private static void ProcessAssemblyTypes( AssemblyDefinition assembly, MonoCecilUtility utility, ModificationOptions options) { List<TypeDefinition> typesToRemove = new List<TypeDefinition>(); foreach (TypeDefinition currentType in assembly.MainModule.Types) { bool isServiceContract = utility.HasAttribute<ServiceContractAttribute>(currentType); bool isDataContract = utility.HasAttribute<DataContractAttribute>(currentType); if (isServiceContract) { currentType.Name = currentType.Name.Replace("Wcf", string.Empty); ChangeNamespace(currentType, options.ServiceContractsNamespace); } else if (isDataContract) { ChangeNamespace(currentType, options.ModelsNamespace); } else if (currentType.Name == "<Module>") { Log($"Leaving special type {currentType.FullName}"); } else { typesToRemove.Add(currentType); Log($"Removed {currentType.FullName}"); } } foreach (TypeDefinition typeToRemove in typesToRemove) { assembly.MainModule.Types.Remove(typeToRemove); } }
private static void ModifyAssemblyName( AssemblyDefinition assembly, ModificationOptions options) { string currentName = assembly.Name.Name; assembly.Name.Name = options.TargetAssemblyName; Log($"Changed assembly name from {currentName} to {options.TargetAssemblyName}"); }
private static void ModifyAssemblyTitleAttribute( AssemblyDefinition assembly, MonoCecilUtility utility, ModificationOptions options) { CustomAttribute assemblyTitle = utility.GetFirstAttribute<AssemblyTitleAttribute>(assembly); // assembly title attribute has just 1 argument CustomAttributeArgument currentConstructurArgument = assemblyTitle.ConstructorArguments[0]; assemblyTitle.ConstructorArguments[0] = new CustomAttributeArgument( currentConstructurArgument.Type, options.TargetAssemblyName); Log($"Changed assembly title attribute from {currentConstructurArgument.Value} to {options.TargetAssemblyName}"); }
public ModificationOptions ParseCommandLine(params string[] commandLineArgs) { if (commandLineArgs == null || commandLineArgs.Length == 0) return new ModificationOptions(); var options = new ModificationOptions(); Parser.Default.ParseArgumentsStrict(commandLineArgs, options, () => { string message = $"Failed to parse command line arguments '{Environment.NewLine}'. Usage: {options.GetUsage()}"; throw new InvalidOperationException(message); }); return options; }