コード例 #1
0
        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");
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
 public static TypeReference ImportType <T>(this ITypeSystem typeSystem)
 {
     return(typeSystem.ImportType(typeof(T)));
 }
コード例 #4
0
        public SystemReferences(ITypeSystem typeSystem)
        {
#pragma warning disable CS8603 // Possible null reference return.
#pragma warning disable CS8602 // Dereference of a possibly null reference.
            LazyTypeReference        = typeSystem.ImportType <Lazy <T> >();
            LazyConstructorReference = typeSystem.ImportMethod(() => new Lazy <T>(() => default, default(LazyThreadSafetyMode)));