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));
                        }
                    }
                }
            }
        }
 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);
         }
     }
 }
 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;
 }
Example #4
0
 public void Inject(object value)
 {
     if (value != null)
     {
         var typeProvider = DescriptionProvider.GetProvider(value.GetType());
         ApplyResolver(value, typeProvider);
     }
 }
        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);
            }
        }
 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);
         }
     }
 }
Example #7
0
        public Injector(IInjector parent)
        {
            if (parent != null)
            {
                Parent = parent;
                DescriptionProvider = parent.DescriptionProvider;
            }
            else
            {
                DescriptionProvider = new DescriptionProvider();
                DescriptionProvider.MapAttribute <InjectAttribute>();
            }

            _resolvers = new Dictionary <Type, IResolver>();

            this.ToValue <IInjector>(this);
            this.ToValue <IInject>(this);
            this.ToValue(this);
        }
 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));
                 }
             }
         }
     }
 }
Example #9
0
 public DescriptionProvider(DescriptionProvider parent = null)
 {
     _parent = parent;
 }