private static void MarkAsGeneratedCodeInternal(object obj, MsCoreReferenceFinder msCoreReferenceFinder) { var fieldDefinition = obj as FieldDefinition; if (fieldDefinition is not null) { fieldDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, fieldDefinition.Module); } var propertyDefinition = obj as PropertyDefinition; if (propertyDefinition is not null) { propertyDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, propertyDefinition.Module); } var methodDefinition = obj as MethodDefinition; if (methodDefinition is not null) { methodDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, methodDefinition.Module); } var typeDefinition = obj as TypeDefinition; if (typeDefinition is not null) { typeDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, typeDefinition.Module); } }
private static CustomAttribute CreateGeneratedCodeAttribute(MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var attributeType = msCoreReferenceFinder.GeneratedCodeAttribute; if (attributeType is null) { return(null); } var stringType = (TypeDefinition)msCoreReferenceFinder.GetCoreTypeReference("System.String"); var constructor = attributeType.Resolve().FindConstructor(new[] { stringType, stringType }.ToList()); if (constructor is null) { return(null); } var version = typeof(ModuleWeaver).Assembly.GetName().Version.ToString(); var name = typeof(ModuleWeaver).Assembly.GetName().Name; var generatedAttribute = new CustomAttribute(importingModule.ImportReference(constructor)); generatedAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringType, name)); generatedAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringType, version)); return(generatedAttribute); }
public void Execute() { try { InitializeEnvironment(); // Read config var configuration = new Configuration(Config); // Set up the basics var msCoreReferenceFinder = new MsCoreReferenceFinder(this, ModuleDefinition.AssemblyResolver); msCoreReferenceFinder.Execute(); // Create method that imports the types var loadTypesWeaver = new LoadTypesWeaver(ModuleDefinition, msCoreReferenceFinder, configuration, this); var loadTypesMethod = loadTypesWeaver.Execute(); // Call method on assembly init var moduleLoaderImporter = new ModuleLoaderImporter(); moduleLoaderImporter.ImportModuleLoader(ModuleDefinition, loadTypesMethod, msCoreReferenceFinder); } catch (Exception ex) { LogError(ex.Message); #if DEBUG Debugger.Launch(); #endif } }
public override void Execute() { try { #if DEBUG if (!Debugger.IsAttached) { Debugger.Launch(); //FodyEnvironment.LogDebug = CreateLoggingCallback(LogDebug); //FodyEnvironment.LogInfo = CreateLoggingCallback(LogInfo); //FodyEnvironment.LogWarning = CreateLoggingCallback(LogWarning); //FodyEnvironment.LogError = CreateLoggingCallback(LogError); } #endif // First of all, set the assembly resolver if (AssemblyResolver == null) { AssemblyResolver = ModuleDefinition.AssemblyResolver; } // Clear cache because static members will be re-used over multiple builds over multiple systems CacheHelper.ClearAllCaches(); InitializeEnvironment(); // Read config var configuration = new Configuration(Config); LogInfo($"LoadAssembliesOnStartup.Fody v{GetType().Assembly.GetName().Version}"); // Set up the basics var msCoreReferenceFinder = new MsCoreReferenceFinder(this, ModuleDefinition.AssemblyResolver); msCoreReferenceFinder.Execute(); // Create method that imports the types var loadTypesWeaver = new LoadTypesWeaver(ModuleDefinition, msCoreReferenceFinder, configuration, this); var loadTypesMethod = loadTypesWeaver.Execute(); // Call method on assembly init var moduleLoaderImporter = new ModuleLoaderImporter(); moduleLoaderImporter.ImportModuleLoader(ModuleDefinition, loadTypesMethod, msCoreReferenceFinder); } catch (Exception ex) { LogError(ex.Message); #if DEBUG Debugger.Launch(); #endif } }
private static CustomAttribute CreateDebuggerNonUserCodeAttribute(MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var attributeType = msCoreReferenceFinder.DebuggerNonUserCodeAttribute; if (attributeType is null) { return(null); } var attribute = new CustomAttribute(importingModule.ImportReference(attributeType.Resolve().Constructor(false))); return(attribute); }
public static void MarkAsCompilerGenerated(this MemberReference member, MsCoreReferenceFinder msCoreReferenceFinder) { MarkAsGeneratedCodeInternal(member, msCoreReferenceFinder); }
public static void MarkAsCompilerGenerated(this TypeReference type, MsCoreReferenceFinder msCoreReferenceFinder) { MarkAsGeneratedCodeInternal(type, msCoreReferenceFinder); }
private static void MarkAsGeneratedCodeInternal(this Collection <CustomAttribute> customAttributes, MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var generatedCodeAttribute = CreateGeneratedCodeAttribute(msCoreReferenceFinder, importingModule); if (generatedCodeAttribute is not null) { customAttributes.Add(generatedCodeAttribute); } var debuggerAttribute = CreateDebuggerNonUserCodeAttribute(msCoreReferenceFinder, importingModule); if (debuggerAttribute is not null) { customAttributes.Add(debuggerAttribute); } }