示例#1
0
        public ProxyTypeDefinition GetTypeDefinition(Type type, Type targetType, ProxyGeneratorOptions options)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            lock (locker)
            {
                ProxyTypeDefinition typeDefinition = typeDefinitions.GetByType(type, targetType, options);
                if (typeDefinition != null)
                {
                    return(typeDefinition);
                }

                if (type.IsInterface)
                {
                    typeDefinition = new InterfaceProxyDefinition(this, type, targetType, options);
                }
                else
                {
                    typeDefinition = new ClassProxyDefinition(this, type, targetType, options);
                }

                SetMixinDefinitions(typeDefinition, options);

                typeDefinitions.Add(typeDefinition);

                return(typeDefinition);
            }
        }
示例#2
0
        public MixinDefinition(ModuleDefinition moduleDefinition, ProxyTypeDefinition proxyTypeDefinition, object mixinInstance)
            : base(moduleDefinition, mixinInstance.GetType(), mixinInstance.GetType())
        {
            if (proxyTypeDefinition is null)
            {
                throw new ArgumentNullException(nameof(proxyTypeDefinition));
            }

            this.proxyTypeDefinition = proxyTypeDefinition;
            this.mixinInstance       = mixinInstance;
        }
示例#3
0
 private void SetMixinDefinitions(ProxyTypeDefinition typeDefinition, ProxyGeneratorOptions options)
 {
     if (options != null)
     {
         int length = options.MixinInstances.Count;
         MixinDefinition[] mixinDefinitions = new MixinDefinition[length];
         for (int i = 0; i < length; i++)
         {
             var mixinInstance = options.MixinInstances[i];
             mixinDefinitions[i] = new MixinDefinition(this, typeDefinition, mixinInstance);
         }
         typeDefinition.MixinDefinitions = mixinDefinitions;
     }
     else
     {
         typeDefinition.MixinDefinitions = new MixinDefinition[0];
     }
 }