Update Template
This commit is contained in:
parent
3da3e10f9f
commit
9ab953b005
@ -29,16 +29,16 @@ internal class SearchParams
|
|||||||
public bool? HasAttribute { get; set; } = null;
|
public bool? HasAttribute { get; set; } = null;
|
||||||
public bool? IsDerived { get; set; } = null;
|
public bool? IsDerived { get; set; } = null;
|
||||||
public bool? HasGenericParameters { get; set; } = null;
|
public bool? HasGenericParameters { get; set; } = null;
|
||||||
public List<string> MethodNamesToMatch { get; set; } = [];
|
public List<string> MatchMethods { get; set; }
|
||||||
public List<string> MethodNamesToIgnore { get; set; } = [];
|
public List<string> IgnoreMethods { get; set; }
|
||||||
|
|
||||||
public List<string> FieldNamesToMatch { get; set; } = [];
|
public List<string> MatchFields { get; set; }
|
||||||
public List<string> FieldNamesToIgnore { get; set; } = [];
|
public List<string> IgnoreFields { get; set; }
|
||||||
public List<string> PropertyNamesToMatch { get; set; } = [];
|
public List<string> MatchProperties { get; set; }
|
||||||
public List<string> PropertyNamesToIgnore { get; set; } = [];
|
public List<string> IgnorePropterties { get; set; }
|
||||||
|
|
||||||
public List<string> NestedTypesToMatch { get; set; } = [];
|
public List<string> MatchNestedTypes { get; set; }
|
||||||
public List<string> NestedTypesToIgnore { get; set; } = [];
|
public List<string> IgnoreNestedTypes { get; set; }
|
||||||
|
|
||||||
public SearchParams()
|
public SearchParams()
|
||||||
{
|
{
|
||||||
|
@ -204,6 +204,8 @@ internal class Remapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
highestScore.RemapModel.OriginalTypeName = highestScore.Definition.Name;
|
||||||
|
|
||||||
// Rename type and all associated type members
|
// Rename type and all associated type members
|
||||||
Renamer.RenameAll(highestScore);
|
Renamer.RenameAll(highestScore);
|
||||||
|
|
||||||
@ -220,9 +222,11 @@ internal class Remapper
|
|||||||
var remappedPath = Path.Combine(strippedPath, filename);
|
var remappedPath = Path.Combine(strippedPath, filename);
|
||||||
|
|
||||||
DataProvider.AssemblyDefinition.Write(remappedPath);
|
DataProvider.AssemblyDefinition.Write(remappedPath);
|
||||||
|
DataProvider.UpdateMapping();
|
||||||
|
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
Logger.Log($"Complete: Assembly written to `{remappedPath}`", ConsoleColor.Green);
|
Logger.Log($"Complete: Assembly written to `{remappedPath}`", ConsoleColor.Green);
|
||||||
|
Logger.Log("Original type names updated on mapping file.", ConsoleColor.Green);
|
||||||
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
Logger.Log("-----------------------------------------------", ConsoleColor.Green);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -174,14 +174,14 @@ internal static class SearchExtentions
|
|||||||
public static EMatchResult MatchMethods(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchMethods(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
// We're not searching for methods and this type contains methods
|
// We're not searching for methods and this type contains methods
|
||||||
if (parms.MethodNamesToMatch.Count == 0 && parms.MethodNamesToIgnore.Count == 0)
|
if (parms.MatchMethods.Count == 0 && parms.IgnoreMethods.Count == 0)
|
||||||
{
|
{
|
||||||
return type.HasMethods
|
return type.HasMethods
|
||||||
? EMatchResult.NoMatch
|
? EMatchResult.NoMatch
|
||||||
: EMatchResult.Match;
|
: EMatchResult.Match;
|
||||||
}
|
}
|
||||||
|
|
||||||
var skippAll = parms.MethodNamesToIgnore.Contains("*");
|
var skippAll = parms.IgnoreMethods.Contains("*");
|
||||||
|
|
||||||
// The type has methods and we dont want any
|
// The type has methods and we dont want any
|
||||||
if (type.HasMethods is true && skippAll is true)
|
if (type.HasMethods is true && skippAll is true)
|
||||||
@ -206,13 +206,13 @@ internal static class SearchExtentions
|
|||||||
foreach (var method in type.Methods)
|
foreach (var method in type.Methods)
|
||||||
{
|
{
|
||||||
// Type contains a method we dont want
|
// Type contains a method we dont want
|
||||||
if (parms.MethodNamesToIgnore.Contains(method.Name))
|
if (parms.IgnoreMethods.Contains(method.Name))
|
||||||
{
|
{
|
||||||
score.FailureReason = EFailureReason.HasMethods;
|
score.FailureReason = EFailureReason.HasMethods;
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var name in parms.MethodNamesToMatch)
|
foreach (var name in parms.MatchMethods)
|
||||||
{
|
{
|
||||||
// Method name match
|
// Method name match
|
||||||
if (method.Name == name)
|
if (method.Name == name)
|
||||||
@ -228,13 +228,13 @@ internal static class SearchExtentions
|
|||||||
|
|
||||||
public static EMatchResult MatchFields(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchFields(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.FieldNamesToMatch.Count == 0 && parms.FieldNamesToIgnore.Count == 0)
|
if (parms.MatchFields.Count == 0 && parms.IgnoreFields.Count == 0)
|
||||||
{
|
{
|
||||||
return EMatchResult.Disabled;
|
return EMatchResult.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all fields that exist on types
|
// `*` is the wildcard to ignore all fields that exist on types
|
||||||
if (!type.HasFields && parms.FieldNamesToIgnore.Contains("*"))
|
if (!type.HasFields && parms.IgnoreFields.Contains("*"))
|
||||||
{
|
{
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
}
|
}
|
||||||
@ -243,14 +243,14 @@ internal static class SearchExtentions
|
|||||||
|
|
||||||
foreach (var field in type.Fields)
|
foreach (var field in type.Fields)
|
||||||
{
|
{
|
||||||
if (parms.FieldNamesToIgnore.Contains(field.Name))
|
if (parms.IgnoreFields.Contains(field.Name))
|
||||||
{
|
{
|
||||||
// Type contains blacklisted field
|
// Type contains blacklisted field
|
||||||
score.FailureReason = EFailureReason.HasFields;
|
score.FailureReason = EFailureReason.HasFields;
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parms.FieldNamesToMatch.Contains(field.Name))
|
if (parms.MatchFields.Contains(field.Name))
|
||||||
{
|
{
|
||||||
matchCount++;
|
matchCount++;
|
||||||
score.Score++;
|
score.Score++;
|
||||||
@ -262,13 +262,13 @@ internal static class SearchExtentions
|
|||||||
|
|
||||||
public static EMatchResult MatchProperties(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchProperties(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.PropertyNamesToMatch.Count == 0 && parms.PropertyNamesToIgnore.Count == 0)
|
if (parms.MatchProperties.Count == 0 && parms.IgnorePropterties.Count == 0)
|
||||||
{
|
{
|
||||||
return EMatchResult.Disabled;
|
return EMatchResult.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all fields that exist on types
|
// `*` is the wildcard to ignore all fields that exist on types
|
||||||
if (!type.HasProperties && parms.PropertyNamesToIgnore.Contains("*"))
|
if (!type.HasProperties && parms.IgnorePropterties.Contains("*"))
|
||||||
{
|
{
|
||||||
score.Score++;
|
score.Score++;
|
||||||
return EMatchResult.Match;
|
return EMatchResult.Match;
|
||||||
@ -278,14 +278,14 @@ internal static class SearchExtentions
|
|||||||
|
|
||||||
foreach (var property in type.Properties)
|
foreach (var property in type.Properties)
|
||||||
{
|
{
|
||||||
if (parms.PropertyNamesToIgnore.Contains(property.Name))
|
if (parms.IgnorePropterties.Contains(property.Name))
|
||||||
{
|
{
|
||||||
// Type contains blacklisted property
|
// Type contains blacklisted property
|
||||||
score.FailureReason = EFailureReason.HasProperties;
|
score.FailureReason = EFailureReason.HasProperties;
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parms.PropertyNamesToMatch.Contains(property.Name))
|
if (parms.MatchProperties.Contains(property.Name))
|
||||||
{
|
{
|
||||||
matchCount++;
|
matchCount++;
|
||||||
score.Score++;
|
score.Score++;
|
||||||
@ -297,13 +297,13 @@ internal static class SearchExtentions
|
|||||||
|
|
||||||
public static EMatchResult MatchNestedTypes(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
public static EMatchResult MatchNestedTypes(this TypeDefinition type, SearchParams parms, ScoringModel score)
|
||||||
{
|
{
|
||||||
if (parms.NestedTypesToMatch.Count == 0 && parms.NestedTypesToIgnore.Count == 0)
|
if (parms.MatchNestedTypes.Count == 0 && parms.IgnoreNestedTypes.Count == 0)
|
||||||
{
|
{
|
||||||
return EMatchResult.Disabled;
|
return EMatchResult.Disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `*` is the wildcard to ignore all fields that exist on types
|
// `*` is the wildcard to ignore all fields that exist on types
|
||||||
if (type.HasNestedTypes && parms.NestedTypesToIgnore.Contains("*"))
|
if (type.HasNestedTypes && parms.IgnoreNestedTypes.Contains("*"))
|
||||||
{
|
{
|
||||||
score.FailureReason = EFailureReason.HasNestedTypes;
|
score.FailureReason = EFailureReason.HasNestedTypes;
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
@ -313,14 +313,14 @@ internal static class SearchExtentions
|
|||||||
|
|
||||||
foreach (var nestedType in type.NestedTypes)
|
foreach (var nestedType in type.NestedTypes)
|
||||||
{
|
{
|
||||||
if (parms.NestedTypesToIgnore.Contains(nestedType.Name))
|
if (parms.IgnoreNestedTypes.Contains(nestedType.Name))
|
||||||
{
|
{
|
||||||
// Type contains blacklisted nested type
|
// Type contains blacklisted nested type
|
||||||
score.FailureReason = EFailureReason.HasNestedTypes;
|
score.FailureReason = EFailureReason.HasNestedTypes;
|
||||||
return EMatchResult.NoMatch;
|
return EMatchResult.NoMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parms.NestedTypesToMatch.Contains(nestedType.Name))
|
if (parms.MatchNestedTypes.Contains(nestedType.Name))
|
||||||
{
|
{
|
||||||
matchCount++;
|
matchCount++;
|
||||||
score.Score++;
|
score.Score++;
|
||||||
|
@ -55,6 +55,24 @@ internal static class DataProvider
|
|||||||
Remaps = JsonConvert.DeserializeObject<HashSet<RemapModel>>(jsonText);
|
Remaps = JsonConvert.DeserializeObject<HashSet<RemapModel>>(jsonText);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void UpdateMapping()
|
||||||
|
{
|
||||||
|
if (!File.Exists(AppSettings.MappingPath))
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException($"path `{AppSettings.MappingPath}` does not exist...");
|
||||||
|
}
|
||||||
|
|
||||||
|
JsonSerializerSettings settings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
NullValueHandling = NullValueHandling.Ignore,
|
||||||
|
Formatting = Formatting.Indented
|
||||||
|
};
|
||||||
|
|
||||||
|
var jsonText = JsonConvert.SerializeObject(Remaps, settings);
|
||||||
|
|
||||||
|
File.WriteAllText(AppSettings.MappingPath, jsonText);
|
||||||
|
}
|
||||||
|
|
||||||
public static void LoadAssemblyDefinition()
|
public static void LoadAssemblyDefinition()
|
||||||
{
|
{
|
||||||
DefaultAssemblyResolver resolver = new();
|
DefaultAssemblyResolver resolver = new();
|
||||||
|
@ -5,41 +5,37 @@
|
|||||||
"NewTypeName": "TEMPLATE", // This is the name we want to change it to
|
"NewTypeName": "TEMPLATE", // This is the name we want to change it to
|
||||||
"OriginalTypeName": "", // This is the name of the object in the assembly, Can be used to store what type you're changing as its not read unless "UseDirectRename" is true, it is also written to after remapping
|
"OriginalTypeName": "", // This is the name of the object in the assembly, Can be used to store what type you're changing as its not read unless "UseDirectRename" is true, it is also written to after remapping
|
||||||
"UseForceRename": false, // If this is true, directly remap using the name in the assembly from the above property
|
"UseForceRename": false, // If this is true, directly remap using the name in the assembly from the above property
|
||||||
"SearchParams": {
|
"SearchParams": { // null means disabled
|
||||||
"IsPublic": true, // Is the Type public?
|
"IsPublic": null, // Is the Type public? (bool)
|
||||||
"IsAbstract": false, // Is the Type Abstract?
|
"IsAbstract": null, // Is the Type Abstract? (bool)
|
||||||
"IsInterface": false, // Is the Type an Interface?
|
"IsInterface": null, // Is the Type an Interface? (bool)
|
||||||
"IsEnum": false, // Is the Type an Enum?
|
"IsEnum": null, // Is the Type an Enum? (bool)
|
||||||
"IsNested": false, // Is the Type Nested?
|
"IsNested": null, // Is the Type Nested? (bool)
|
||||||
"ParentName": "", // The Name of the parent type if it is nested, can be left empty
|
"ParentName": "", // The Name of the parent type if it is nested, can be left empty (string)
|
||||||
"IsSealed": false, // Is the Type Sealed?
|
"IsSealed": null, // Is the Type Sealed? (bool)
|
||||||
"HasAttribute": false, // Does the Type have an attribute?
|
"HasAttribute": null, // Does the Type have an attribute? (bool)
|
||||||
"IsDerived": true, // Does the Type inherit from another Type?
|
"IsDerived": null, // Does the Type inherit from another Type? (bool)
|
||||||
"HasGenericParameters": false, // Does the type have generic parameters?
|
"HasGenericParameters": null, // Does the type have generic parameters? (bool)
|
||||||
"MethodNamesToMatch": [ // This is a list of methods we want to match
|
|
||||||
"Foo"
|
// Note:
|
||||||
|
// - You can can filter the ignore list with a wild card '*' to match all types that have none of that search parameter
|
||||||
|
// - These are all lists of strings
|
||||||
|
|
||||||
|
"MatchMethods": [ // This is a list of methods we want to match
|
||||||
],
|
],
|
||||||
"MethodNamesToIgnore": [ // This is a list of methods we want to ignore
|
"IgnoreMethods": [ // This is a list of methods we want to ignore
|
||||||
"Foo",
|
|
||||||
"*" // Ignore all Types that have methods, this wildcard can be used on any ignore list
|
|
||||||
],
|
],
|
||||||
"FieldNamesToMatch": [ // This is a list of fields we want to match
|
"MatchFields": [ // This is a list of fields we want to match
|
||||||
"_fooBar"
|
|
||||||
],
|
],
|
||||||
"FieldNamesToIgnore": [ // This is a list of fields we want to ignore
|
"IgnoreFields": [ // This is a list of fields we want to ignore
|
||||||
"Foo"
|
|
||||||
],
|
],
|
||||||
"PropertyNamesToMatch": [ // This is a list of properties we want to match
|
"MatchProperties": [ // This is a list of properties we want to match
|
||||||
"FooBar"
|
|
||||||
],
|
],
|
||||||
"PropertyNamesToIgnore": [ // This is a list of properties we want to ignore
|
"IgnorePropterties": [ // This is a list of properties we want to ignore
|
||||||
"Foo"
|
|
||||||
],
|
],
|
||||||
"NestedTypesToMatch": [ // This is a list of nested types we want to match
|
"MatchNestedTypes": [ // This is a list of nested types we want to match
|
||||||
"FooBarFoo"
|
|
||||||
],
|
],
|
||||||
"NestedTypesToIgnore": [ // This is a list of nested types we want to match ignore
|
"IgnoreNestedTypes": [ // This is a list of nested types we want to match ignore
|
||||||
"FooBarFoo"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user