private WeakEventHandlerWeaver(ModuleDefinition moduleDefinition, ITypeSystem typeSystem, ILogger logger, TypeReference makeWeakAttributeReference) { _moduleDefinition = moduleDefinition; _typeSystem = typeSystem; _logger = logger; var makeWeakAttribute = makeWeakAttributeReference.Resolve(); var helperTypes = makeWeakAttribute.Module.Types; _codeImporter = new CodeImporter(moduleDefinition) { NamespaceDecorator = value => "<>" + value }; _weakAdapterType = _codeImporter.Import(helperTypes.Single(t => t.Name == "WeakEventHandlerFodyWeakEventAdapter`4")); _eventTargetInterface = _codeImporter.Import(helperTypes.Single(t => t.Name == "IWeakEventHandlerFodyWeakEventTarget")); _weakAdapterConstructor = _weakAdapterType.GetConstructors().Single(ctor => ctor.Parameters.Count == 4); _generatedCodeAttribute = _weakAdapterType.CustomAttributes.Single(attr => attr.AttributeType.Name == nameof(GeneratedCodeAttribute)); var weakAdapterMethods = _weakAdapterType.GetMethods().ToList(); _weakAdapterSubscribeMethod = weakAdapterMethods.Single(method => method.Name == "Subscribe"); _weakAdapterUnsubscribeMethod = weakAdapterMethods.Single(method => method.Name == "Unsubscribe"); _weakAdapterReleaseMethod = weakAdapterMethods.Single(method => method.Name == "Release"); _action2Type = typeSystem.ImportType <Action <object, EventArgs> >(); _action2Constructor = typeSystem.ImportMethod <Action <object, EventArgs>, object, IntPtr>(".ctor"); _action3Type = typeSystem.ImportType <Action <Type, object, EventArgs> >(); _action3Constructor = typeSystem.ImportMethod <Action <Type, object, EventArgs>, object, IntPtr>(".ctor"); }
public SystemReferences([NotNull] ITypeSystem typeSystem) { #pragma warning disable CS1720 // Expression will always cause a System.NullReferenceException because the type's default value is null GetFieldFromHandle = typeSystem.ImportMethod(() => FieldInfo.GetFieldFromHandle(default(RuntimeFieldHandle))); PropertyInfoType = typeSystem.ImportType <PropertyInfo>(); GetTypeFromHandle = typeSystem.ImportMethod(() => Type.GetTypeFromHandle(default(RuntimeTypeHandle))); GetPropertyInfo = typeSystem.TryImportMethod(() => default(Type).GetProperty(default(string), default(BindingFlags))); }
public static MethodReference ImportMethod(this ITypeSystem typeSystem, Expression <Action> expression) { GetMethodInfo(expression, out var declaringType, out var methodName, out var argumentTypes); return(typeSystem.ImportMethod(declaringType, methodName, argumentTypes)); }
public static MethodReference ImportMethod <T, TP1, TP2, TP3>(this ITypeSystem typeSystem, string name) { return(typeSystem.ImportMethod <T>(name, typeof(TP1), typeof(TP2), typeof(TP3))); }
public static MethodReference ImportMethod <T>(this ITypeSystem typeSystem, string name, params Type[] argumentTypes) { return(typeSystem.ImportMethod(typeof(T), name, argumentTypes)); }