Пример #1
0
        protected virtual void ParseProperties(Type type, MemberKind kind, DescriptionProvider provider)
        {
            if ((kind & MemberKind.Property) == MemberKind.Property)
            {
                var properties =
                    type.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public |
                                       BindingFlags.GetProperty | BindingFlags.SetProperty | BindingFlags.DeclaredOnly);

                var length = properties.Length;
                for (int i = 0; i < length; i++)
                {
                    var property   = properties[i];
                    var attributes = property.GetCustomAttributes(true);
                    var attrLen    = attributes.Length;
                    for (int j = 0; j < attrLen; j++)
                    {
                        var  attribute = attributes[j] as Attribute;
                        Type attributeType;
                        if (attribute != null && provider.IsMappedAttribute(attributeType = attribute.GetType()))
                        {
                            AddDescription(attributeType, new PropertyDescription(property, attribute));
                        }
                    }
                }
            }
        }
Пример #2
0
 protected virtual void ParseConstructors(Type type, MemberKind kind, DescriptionProvider provider)
 {
     if ((kind & MemberKind.Constructor) == MemberKind.Constructor)
     {
         ConstructorInfo[] constructors        = type.GetConstructors();
         ConstructorInfo   constructorToInject = null;
         int maxParameters = -1;
         foreach (ConstructorInfo constructor in constructors)
         {
             object[] attributes = constructor.GetCustomAttributes(true);
             var      attrLen    = attributes.Length;
             for (int i = 0; i < attrLen; i++)
             {
                 var  attribute = attributes[i] as Attribute;
                 Type attributeType;
                 if (attribute != null && provider.IsMappedAttribute(attributeType = attribute.GetType()))
                 {
                     AddDescription(attributeType, new ConstructorDescription(constructor, attribute));
                 }
             }
             if (constructor.GetParameters().Length > maxParameters)
             {
                 constructorToInject = constructor;
                 maxParameters       = constructor.GetParameters().Length;
             }
         }
         if (constructorToInject != null)
         {
             DefaultConstructor = new ConstructorDescription(constructorToInject, null);
         }
     }
 }
Пример #3
0
 public TypeProvider(DescriptionProvider provider, Type type, Type baseType = null, int memberCapacity = 4)
 {
     _index          = Interlocked.Increment(ref _instanceCount);
     _provider       = provider;
     _type           = type;
     _memberCapacity = memberCapacity;
     _baseType       = baseType;
 }
Пример #4
0
        protected virtual void ParseParentProvider(Type type, MemberKind kind, DescriptionProvider provider)
        {
            var baseType = type.BaseType;

            if (baseType != null && baseType != ObjectType && (BaseType == null || BaseType != baseType))
            {
                _parent = provider.GetProvider(baseType, kind);
            }
        }
Пример #5
0
 protected virtual void ParseTypeAttributes(Type type, MemberKind kind, DescriptionProvider provider)
 {
     foreach (var customAttribute in type.GetCustomAttributes(true))
     {
         if (provider.IsMappedAttribute(customAttribute.GetType()))
         {
             (_typeAttributes ?? (_typeAttributes = new List <Attribute>())).Add((Attribute)customAttribute);
         }
     }
 }
Пример #6
0
 protected virtual void ParseMethods(Type type, MemberKind kind, DescriptionProvider provider)
 {
     if ((kind & MemberKind.Method) == MemberKind.Method)
     {
         var methods = type.GetMethods(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
         var length  = methods.Length;
         for (int i = 0; i < length; i++)
         {
             var method     = methods[i];
             var attributes = method.GetCustomAttributes(true);
             var attrLen    = attributes.Length;
             for (int j = 0; j < attrLen; j++)
             {
                 var  attribute = attributes[j] as Attribute;
                 Type attributeType;
                 if (attribute != null && provider.IsMappedAttribute(attributeType = attribute.GetType()))
                 {
                     AddDescription(attributeType, new MethodDescription(method, attribute));
                 }
             }
         }
     }
 }
Пример #7
0
        public Injector(IInjector parent, DescriptionProvider provider)
        {
            _provider = new Dictionary <Type, IProvider>(128);

            Parent = parent;
            if (parent != null && provider == null)
            {
                DescriptionProvider = parent.DescriptionProvider;
            }
            else
            {
                DescriptionProvider = provider ?? new DescriptionProvider();
            }
            DescriptionProvider.MapAttribute <InjectAttribute>();
            DescriptionProvider.MapAttribute <PostConstructorAttribute>();
            DescriptionProvider.MapAttribute <PostInjectAttribute>();
            if (GetProvider(typeof(DescriptionProvider), true) == null)
            {
                Map <DescriptionProvider>().ToValue(DescriptionProvider);
            }
            Map <IInjector>().ToValue(this);
            Map <Injector>().ToValue(this);
            Map <IInject>().ToValue(this);
        }
Пример #8
0
 public Injector(DescriptionProvider provider) : this(null, provider)
 {
 }
Пример #9
0
 public DescriptionProvider(DescriptionProvider parent = null)
 {
     _parent = parent;
 }