public CatelTypeNodeBuilder(List <TypeDefinition> allTypes, MsCoreReferenceFinder msCoreReferenceFinder) { CatelTypes = new List <CatelType>(); _allClasses = allTypes.Where(x => x.IsClass).ToList(); _msCoreReferenceFinder = msCoreReferenceFinder; }
private static void MarkAsGeneratedCodeInternal(object obj, MsCoreReferenceFinder msCoreReferenceFinder) { var fieldDefinition = obj as FieldDefinition; if (fieldDefinition != null) { fieldDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, fieldDefinition.Module); } var propertyDefinition = obj as PropertyDefinition; if (propertyDefinition != null) { propertyDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, propertyDefinition.Module); } var methodDefinition = obj as MethodDefinition; if (methodDefinition != null) { methodDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, methodDefinition.Module); } var typeDefinition = obj as TypeDefinition; if (typeDefinition != 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 PropertyWeaverBase(CatelType catelType, CatelTypeProperty propertyData, ModuleWeaver moduleWeaver, MsCoreReferenceFinder msCoreReferenceFinder) { _catelType = catelType; _propertyData = propertyData; _moduleWeaver = moduleWeaver; _msCoreReferenceFinder = msCoreReferenceFinder; }
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 CatelType(TypeDefinition typeDefinition, MsCoreReferenceFinder msCoreReferenceFinder) { Mappings = new List <MemberMapping>(); Properties = new List <CatelTypeProperty>(); Ignore = true; TypeDefinition = typeDefinition; Name = typeDefinition.FullName; _msCoreReferenceFinder = msCoreReferenceFinder; DetermineCatelType(); if (Type == CatelTypeType.Unknown) { FodyEnvironment.WriteWarning($"Cannot determine the Catel type used for '{Name}', type will be ignored for weaving"); return; } Version = TypeDefinition.GetCatelVersion(); if (Version == CatelVersion.Unknown) { FodyEnvironment.WriteWarning($"Cannot determine the Catel version used for '{Name}', type will be ignored for weaving"); return; } try { DetermineTypes(); if (!DetermineMethods()) { FodyEnvironment.WriteWarning($"Cannot determine the Catel methods used for '{Name}', type will be ignored for weaving"); return; } DetermineProperties(); DetermineMappings(); Ignore = false; } catch (Exception ex) { FodyEnvironment.WriteWarning($"Failed to get additional information about type '{Name}', type will be ignored for weaving: '{ex.Message}'"); } }
private static void MarkAsGeneratedCodeInternal(object obj, MsCoreReferenceFinder msCoreReferenceFinder) { if (obj is FieldDefinition fieldDefinition) { fieldDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, fieldDefinition.Module); } if (obj is PropertyDefinition propertyDefinition) { propertyDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, propertyDefinition.Module); } if (obj is MethodDefinition methodDefinition) { methodDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, methodDefinition.Module); } if (obj is TypeDefinition typeDefinition) { typeDefinition.CustomAttributes.MarkAsGeneratedCodeInternal(msCoreReferenceFinder, typeDefinition.Module); } }
public static void MarkAsCompilerGenerated(this TypeReference type, MsCoreReferenceFinder msCoreReferenceFinder) { MarkAsGeneratedCodeInternal(type, msCoreReferenceFinder); }
public static void MarkAsCompilerGenerated(this MemberReference member, MsCoreReferenceFinder msCoreReferenceFinder) { MarkAsGeneratedCodeInternal(member, msCoreReferenceFinder); }
private static CustomAttribute CreateDebuggerNonUserCodeAttribute(MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var attributeType = msCoreReferenceFinder.DebuggerNonUserCodeAttribute; if (attributeType == null) { return null; } var attribute = new CustomAttribute(importingModule.Import(attributeType.Resolve().Constructor(false))); return attribute; }
private static CustomAttribute CreateGeneratedCodeAttribute(MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var attributeType = msCoreReferenceFinder.GeneratedCodeAttribute; if (attributeType == null) { return null; } var stringType = (TypeDefinition)msCoreReferenceFinder.GetCoreTypeReference("System.String"); var constructor = attributeType.Resolve().FindConstructor(new[] {stringType, stringType}.ToList()); if (constructor == null) { return null; } var version = typeof(ModuleWeaver).Assembly.GetName().Version.ToString(); var name = typeof(ModuleWeaver).Assembly.GetName().Name; var generatedAttribute = new CustomAttribute(importingModule.Import(constructor)); generatedAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringType, name)); generatedAttribute.ConstructorArguments.Add(new CustomAttributeArgument(stringType, version)); return generatedAttribute; }
private static void MarkAsGeneratedCodeInternal(this Collection<CustomAttribute> customAttributes, MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var generatedCodeAttribute = CreateGeneratedCodeAttribute(msCoreReferenceFinder, importingModule); if (generatedCodeAttribute != null) { customAttributes.Add(generatedCodeAttribute); } var debuggerAttribute = CreateDebuggerNonUserCodeAttribute(msCoreReferenceFinder, importingModule); if (debuggerAttribute != null) { customAttributes.Add(debuggerAttribute); } }
public ObservableObjectPropertyWeaver(CatelType catelType, CatelTypeProperty propertyData, ModuleWeaver moduleWeaver, MsCoreReferenceFinder msCoreReferenceFinder) : base(catelType, propertyData, moduleWeaver, msCoreReferenceFinder) { }
public ModelBasePropertyWeaver(CatelType catelType, CatelTypeProperty propertyData, Configuration configuration, ModuleWeaver moduleWeaver, MsCoreReferenceFinder msCoreReferenceFinder) : base(catelType, propertyData, moduleWeaver, msCoreReferenceFinder) { _configuration = configuration; }
private static void MarkAsGeneratedCodeInternal(this Collection <CustomAttribute> customAttributes, MsCoreReferenceFinder msCoreReferenceFinder, ModuleDefinition importingModule) { var generatedCodeAttribute = CreateGeneratedCodeAttribute(msCoreReferenceFinder, importingModule); if (generatedCodeAttribute != null) { customAttributes.Add(generatedCodeAttribute); } var debuggerAttribute = CreateDebuggerNonUserCodeAttribute(msCoreReferenceFinder, importingModule); if (debuggerAttribute != null) { customAttributes.Add(debuggerAttribute); } }
public 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 // Clear cache because static members will be re-used over multiple builds over multiple systems CacheHelper.ClearAllCaches(); var configuration = new Configuration(Config); InitializeEnvironment(); // 1st step: set up the basics var msCoreReferenceFinder = new MsCoreReferenceFinder(this, ModuleDefinition.AssemblyResolver); msCoreReferenceFinder.Execute(); // Validate if Catel.Core is referenced var isRunningAgainstCatelCore = false; var catelCoreReference = AssemblyResolver.Resolve("Catel.Core"); if (catelCoreReference == null) { if (!ModuleDefinition.Name.StartsWith("Catel.Core")) { LogWarning("No reference to Catel.Core found, this weaver is useless without referencing Catel"); return; } isRunningAgainstCatelCore = true; LogInfo("No reference to Catel.Core found, but continuing because this is running against Catel.Core itself"); } // Note: nested types not supported because we only list actual types (thus not nested) var types = ModuleDefinition.GetTypes().Where(x => x.IsClass && x.BaseType != null).ToList(); var typeNodeBuilder = new CatelTypeNodeBuilder(types); typeNodeBuilder.Execute(); // Remove any code generated types from the list of types to process var codeGenTypeCleaner = new CodeGenTypeCleaner(typeNodeBuilder); codeGenTypeCleaner.Execute(); // 2nd step: Auto property weaving if (!isRunningAgainstCatelCore && configuration.WeaveProperties) { FodyEnvironment.LogInfo("Weaving properties"); var propertyWeaverService = new AutoPropertiesWeaverService(configuration, typeNodeBuilder, msCoreReferenceFinder); propertyWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving properties is disabled"); } // 3rd step: Exposed properties weaving if (!isRunningAgainstCatelCore && configuration.WeaveExposedProperties) { FodyEnvironment.LogInfo("Weaving exposed properties"); var exposedPropertiesWeaverService = new ExposedPropertiesWeaverService(typeNodeBuilder, msCoreReferenceFinder); exposedPropertiesWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving exposed properties is disabled"); } // 4th step: Argument weaving if (!isRunningAgainstCatelCore && configuration.WeaveArguments) { FodyEnvironment.LogInfo("Weaving arguments"); var argumentWeaverService = new ArgumentWeaverService(types, msCoreReferenceFinder); argumentWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving arguments is disabled"); } // 5th step: Logging weaving (we will run this against Catel.Core) if (configuration.WeaveLogging) { FodyEnvironment.LogInfo("Weaving logging"); var loggingWeaver = new LoggingWeaverService(types); loggingWeaver.Execute(); } else { FodyEnvironment.LogInfo("Weaving logging is disabled"); } // 6th step: Xml schema weaving if (!isRunningAgainstCatelCore && configuration.GenerateXmlSchemas) { FodyEnvironment.LogInfo("Weaving xml schemas"); var xmlSchemasWeaverService = new XmlSchemasWeaverService(msCoreReferenceFinder, typeNodeBuilder); xmlSchemasWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving xml schemas is disabled"); } // Last step: clean up var referenceCleaner = new ReferenceCleaner(this); referenceCleaner.Execute(); } catch (Exception ex) { LogError(ex.Message); #if DEBUG if (!Debugger.IsAttached) { Debugger.Launch(); } #endif } }
public CatelPropertyWeaver(CatelType catelType, CatelTypeProperty propertyData, MsCoreReferenceFinder msCoreReferenceFinder) { _catelType = catelType; _propertyData = propertyData; _msCoreReferenceFinder = msCoreReferenceFinder; }
public 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 // Clear cache because static members will be re-used over multiple builds over multiple systems CacheHelper.ClearAllCaches(); var configuration = new Configuration(Config); InitializeEnvironment(); LogInfo($"Catel.Fody v{GetType().Assembly.GetName().Version}"); // 1st step: set up the basics var msCoreReferenceFinder = new MsCoreReferenceFinder(this, ModuleDefinition.AssemblyResolver); msCoreReferenceFinder.Execute(); // Validate if Catel.Core is referenced var isRunningAgainstCatelCore = false; var catelCoreReference = AssemblyResolver.Resolve("Catel.Core"); if (catelCoreReference == null) { if (!ModuleDefinition.Name.StartsWith("Catel.Core")) { LogWarning("No reference to Catel.Core found, this weaver is useless without referencing Catel"); return; } isRunningAgainstCatelCore = true; LogInfo("No reference to Catel.Core found, but continuing because this is running against Catel.Core itself"); } // Note: nested types not supported because we only list actual types (thus not nested) var types = ModuleDefinition.GetTypes().Where(x => x.IsClass && x.BaseType != null).ToList(); var typeNodeBuilder = new CatelTypeNodeBuilder(types); typeNodeBuilder.Execute(); // Remove any code generated types from the list of types to process var codeGenTypeCleaner = new CodeGenTypeCleaner(typeNodeBuilder); codeGenTypeCleaner.Execute(); // 2nd step: Auto property weaving if (!isRunningAgainstCatelCore && configuration.WeaveProperties) { FodyEnvironment.LogInfo("Weaving properties"); var propertyWeaverService = new AutoPropertiesWeaverService(configuration, typeNodeBuilder, msCoreReferenceFinder); propertyWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving properties is disabled"); } // 3rd step: Exposed properties weaving if (!isRunningAgainstCatelCore && configuration.WeaveExposedProperties) { FodyEnvironment.LogInfo("Weaving exposed properties"); var exposedPropertiesWeaverService = new ExposedPropertiesWeaverService(typeNodeBuilder, msCoreReferenceFinder); exposedPropertiesWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving exposed properties is disabled"); } // 4th step: Argument weaving if (!isRunningAgainstCatelCore && configuration.WeaveArguments) { FodyEnvironment.LogInfo("Weaving arguments"); var argumentWeaverService = new ArgumentWeaverService(types, msCoreReferenceFinder); argumentWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving arguments is disabled"); } // 5th step: Logging weaving (we will run this against Catel.Core) if (configuration.WeaveLogging) { FodyEnvironment.LogInfo("Weaving logging"); var loggingWeaver = new LoggingWeaverService(types); loggingWeaver.Execute(); } else { FodyEnvironment.LogInfo("Weaving logging is disabled"); } // 6th step: Xml schema weaving if (!isRunningAgainstCatelCore && configuration.GenerateXmlSchemas) { FodyEnvironment.LogInfo("Weaving xml schemas"); var xmlSchemasWeaverService = new XmlSchemasWeaverService(msCoreReferenceFinder, typeNodeBuilder); xmlSchemasWeaverService.Execute(); } else { FodyEnvironment.LogInfo("Weaving xml schemas is disabled"); } // Last step: clean up var referenceCleaner = new ReferenceCleaner(this); referenceCleaner.Execute(); } catch (Exception ex) { LogError(ex.Message); #if DEBUG if (!Debugger.IsAttached) { Debugger.Launch(); } #endif } }
public override void Execute() { try { //#if DEBUG // if (!Debugger.IsAttached) // { // Debugger.Launch(); // } //#endif // First of all, set the assembly resolver if (AssemblyResolver is null) { AssemblyResolver = ModuleDefinition.AssemblyResolver; } if (TypeSystem is null) { var typeCache = new global::Fody.TypeCache(x => AssemblyResolver.Resolve(x)); typeCache.BuildAssembliesToScan(this); TypeSystem = new global::Fody.TypeSystem(x => typeCache.FindType(x), ModuleDefinition); } // Clear cache because static members will be re-used over multiple builds over multiple systems CacheHelper.ClearAllCaches(); var configuration = new Configuration(Config); InitializeEnvironment(); WriteInfo($"Catel.Fody v{GetType().Assembly.GetName().Version}"); // 1st step: set up the basics var msCoreReferenceFinder = new MsCoreReferenceFinder(this, ModuleDefinition.AssemblyResolver); msCoreReferenceFinder.Execute(); // Validate if Catel.Core is referenced configuration.IsRunningAgainstCatel = false; if (ModuleDefinition.Name.StartsWith("Catel.Core") || ModuleDefinition.Name.StartsWith("Catel.MVVM") || ModuleDefinition.Name.StartsWith("Catel.Serialization.") || ModuleDefinition.Name.StartsWith("Catel.Tests")) { configuration.IsRunningAgainstCatel = true; WriteInfo("Running against Catel itself, most features will be disabled"); } var catelCoreReference = AssemblyResolver.Resolve("Catel.Core"); if (!configuration.IsRunningAgainstCatel && catelCoreReference is null) { WriteWarning("No reference to Catel.Core found, this weaver is useless without referencing Catel"); return; } // Note: nested types not supported because we only list actual types (thus not nested) var types = ModuleDefinition.GetTypes().Where(x => x.IsClass && x.BaseType != null).ToList(); var typeNodeBuilder = new CatelTypeNodeBuilder(types, msCoreReferenceFinder); typeNodeBuilder.Execute(); // Remove any code generated types from the list of types to process var codeGenTypeCleaner = new CodeGenTypeCleaner(typeNodeBuilder); codeGenTypeCleaner.Execute(); // 2nd step: Auto property weaving if (!configuration.IsRunningAgainstCatel && configuration.WeaveProperties) { FodyEnvironment.WriteInfo("Weaving properties"); var propertyWeaverService = new AutoPropertiesWeaverService(configuration, this, typeNodeBuilder, msCoreReferenceFinder); propertyWeaverService.Execute(); } else { FodyEnvironment.WriteInfo("Weaving properties is disabled"); } // 3rd step: Exposed properties weaving if (!configuration.IsRunningAgainstCatel && configuration.WeaveExposedProperties) { FodyEnvironment.WriteInfo("Weaving exposed properties"); var exposedPropertiesWeaverService = new ExposedPropertiesWeaverService(this, configuration, typeNodeBuilder, msCoreReferenceFinder); exposedPropertiesWeaverService.Execute(); } else { FodyEnvironment.WriteInfo("Weaving exposed properties is disabled"); } // 4th step: Argument weaving if (configuration.WeaveArguments) { FodyEnvironment.WriteInfo("Weaving arguments"); var argumentWeaverService = new ArgumentWeaverService(types, msCoreReferenceFinder, configuration); argumentWeaverService.Execute(); } else { FodyEnvironment.WriteInfo("Weaving arguments is disabled"); } // 5th step: Logging weaving (we will run this against Catel.Core) if (configuration.WeaveLogging) { FodyEnvironment.WriteInfo("Weaving logging"); var loggingWeaver = new LoggingWeaverService(types); loggingWeaver.Execute(); } else { FodyEnvironment.WriteInfo("Weaving logging is disabled"); } // 6th step: Xml schema weaving if (!configuration.IsRunningAgainstCatel && configuration.GenerateXmlSchemas) { FodyEnvironment.WriteInfo("Weaving xml schemas"); var xmlSchemasWeaverService = new XmlSchemasWeaverService(this, msCoreReferenceFinder, typeNodeBuilder); xmlSchemasWeaverService.Execute(); } else { FodyEnvironment.WriteInfo("Weaving xml schemas is disabled"); } // Validate that nothing has been left out var validationService = new ValidationService(this); validationService.Validate(); // Last step: clean up var referenceCleaner = new ReferenceCleaner(this); referenceCleaner.Execute(); } catch (Exception ex) { WriteError(ex.Message); #if DEBUG if (!Debugger.IsAttached) { Debugger.Launch(); } #endif } }