Skip to content

Commit

Permalink
Merge pull request #7
Browse files Browse the repository at this point in the history
feature/refactoring
  • Loading branch information
uurha committed Apr 21, 2024
1 parent 69b9cc2 commit 0f13442
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Runtime/Comparers/IsSubClassComparer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;

namespace Better.Commons.Runtime.Comparers
{
public class IsSubClassComparer : BaseComparer<IsSubClassComparer, Type>, IEqualityComparer<Type>
{
public bool Equals(Type x, Type y)
{
if (ReferenceEquals(x, y)) return true;
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
var isAssignableFrom = y.IsSubclassOf(x);
return isAssignableFrom || x == y;
}

public int GetHashCode(Type obj)
{
return 0;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Comparers/IsSubClassComparer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Runtime/Extensions/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static IEnumerable<Type> GetAllInheritedTypes(this Type self)

public static IEnumerable<Type> GetAllInheritedTypes(this Type self, params Type[] excludes)
{
return self.GetAllInheritedTypes().Except(excludes);
return self.GetAllInheritedTypes().Except(excludes, IsSubClassComparer.Instance);
}

public static IEnumerable<Type> GetAllInheritedTypesWithoutUnityObject(this Type self)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.tdw.better.commons",
"displayName": "Better Commons",
"version": "0.0.3",
"version": "0.0.4",
"unity": "2021.3",
"description": " ",
"dependencies": {
Expand Down

0 comments on commit 0f13442

Please sign in to comment.