Skip to content

Commit

Permalink
Merge pull request #2 from OsOmE1/Dev
Browse files Browse the repository at this point in the history
Added StaticFieldSequence
  • Loading branch information
OsOmE1 authored Jan 6, 2021
2 parents a582f33 + 35587f1 commit f59ce84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Util/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,19 @@ public static bool FieldSequenceEqual(this TypeInfo typeInfo, List<string> field

return true;
}
public static bool StaticFieldSequenceEqual(this TypeInfo typeInfo, List<string> fieldSequence)
{
var typeNames = typeInfo.GetStaticFields().Select(f => new { f.FieldType.CSharpName, f.FieldType.CSharpBaseName }).ToList();
if (fieldSequence.Count != typeNames.Count) return false;

for (int i = 0; i < fieldSequence.Count; i++)
{
if (fieldSequence[i] == "*") continue;
if (typeNames[i].CSharpName != fieldSequence[i] && typeNames[i].CSharpBaseName != fieldSequence[i]) return false;
}

return true;
}
public static IList<FieldInfo> GetStaticFields(this TypeInfo typeInfo)
{
return typeInfo.DeclaredFields.Where(f => !f.IsLiteral && f.IsStatic).ToList();
Expand Down
6 changes: 5 additions & 1 deletion Util/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ public static IList<TypeInfo> GetTypeWithNumStaticFields(int count)
return GetTypes().Where(t => t.GetStaticFields().Count == count).ToList();
}

public static TypeInfo FindTypeWithSequence(List<string> sequence)
public static TypeInfo FindTypeWithFieldSequence(List<string> sequence)
{
CheckInit(); return _types.Where(t => t.FieldSequenceEqual(sequence)).FirstOrDefault();
}

public static TypeInfo FindTypeWithStaticFieldSequence(List<string> sequence)
{
CheckInit(); return _types.Where(t => t.StaticFieldSequenceEqual(sequence)).FirstOrDefault();
}
internal static IList<TypeInfo> GetTypes()
{
CheckInit(); return _types;
Expand Down

0 comments on commit f59ce84

Please sign in to comment.