コード例 #1
0
        static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType)
        {
            var injectAttributes = memInfo.AllAttributes <InjectAttributeBase>().ToList();

            Assert.That(injectAttributes.Count <= 1,
                        "Found multiple 'Inject' attributes on type field '{0}' of type '{1}'.  Field should only container one Inject attribute", memInfo.Name, parentType);

            var injectAttr = injectAttributes.SingleOrDefault();

            object        identifier = null;
            bool          isOptional = false;
            InjectSources sourceType = InjectSources.Any;

            if (injectAttr != null)
            {
                identifier = injectAttr.Id;
                isOptional = injectAttr.Optional;
                sourceType = injectAttr.Source;
            }

            Type memberType = memInfo is FieldInfo
                ? ((FieldInfo)memInfo).FieldType : ((PropertyInfo)memInfo).PropertyType;

            var setter = GetSetter(parentType, memInfo);

            return(new InjectableInfo(
                       isOptional,
                       identifier,
                       memInfo.Name,
                       memberType,
                       parentType,
                       setter,
                       null,
                       sourceType));
        }
コード例 #2
0
        static InjectableInfo CreateInjectableInfoForParam(
            Type parentType, ParameterInfo paramInfo)
        {
            var injectAttributes = paramInfo.AllAttributes <InjectAttributeBase>().ToList();

            Assert.That(injectAttributes.Count <= 1,
                        "Found multiple 'Inject' attributes on type parameter '{0}' of type '{1}'.  Parameter should only have one", paramInfo.Name, parentType);

            var injectAttr = injectAttributes.SingleOrDefault();

            object        identifier = null;
            bool          isOptional = false;
            InjectSources sourceType = InjectSources.Any;

            if (injectAttr != null)
            {
                identifier = injectAttr.Id;
                isOptional = injectAttr.Optional;
                sourceType = injectAttr.Source;
            }

            bool isOptionalWithADefaultValue = (paramInfo.Attributes & ParameterAttributes.HasDefault) == ParameterAttributes.HasDefault;

            return(new InjectableInfo(
                       isOptionalWithADefaultValue || isOptional,
                       identifier,
                       paramInfo.Name,
                       paramInfo.ParameterType,
                       parentType,
                       null,
                       isOptionalWithADefaultValue ? paramInfo.DefaultValue : null,
                       sourceType));
        }
コード例 #3
0
        static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType)
        {
            var injectAttributes = memInfo.AllAttributes <InjectAttributeBase>().ToList();

            Assert.That(injectAttributes.Count <= 1,
                        "Found multiple 'Inject' attributes on type field '{0}' of type '{1}'.  Field should only container one Inject attribute", memInfo.Name, parentType);

            var injectAttr = injectAttributes.SingleOrDefault();

            object        identifier = null;
            bool          isOptional = false;
            InjectSources sourceType = InjectSources.Any;

            if (injectAttr != null)
            {
                identifier = injectAttr.Id;
                isOptional = injectAttr.Optional;
                sourceType = injectAttr.Source;
            }

            Type memberType;
            Action <object, object> setter;

            if (memInfo is FieldInfo)
            {
                var fieldInfo = (FieldInfo)memInfo;
                setter     = ((object injectable, object value) => fieldInfo.SetValue(injectable, value));
                memberType = fieldInfo.FieldType;
            }
            else
            {
                Assert.That(memInfo is PropertyInfo);
                var propInfo = (PropertyInfo)memInfo;
                memberType = propInfo.PropertyType;

#if UNITY_WSA && ENABLE_DOTNET && !UNITY_EDITOR
                setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null));
#else
                if (propInfo.CanWrite)
                {
                    setter = ((object injectable, object value) => propInfo.SetValue(injectable, value, null));
                }
                else
                {
                    setter = GetOnlyPropertySetter(parentType, propInfo.Name);
                }
#endif
            }

            return(new InjectableInfo(
                       isOptional,
                       identifier,
                       memInfo.Name,
                       memberType,
                       parentType,
                       setter,
                       null,
                       sourceType));
        }
コード例 #4
0
ファイル: FactoryFromBinder0.cs プロジェクト: polvila/Splash
        public ConditionCopyNonLazyBinder FromResolveGetter <TObj>(
            object subIdentifier, Func <TObj, TContract> method, InjectSources source)
        {
            FactoryBindInfo.ProviderFunc =
                (container) => new GetterProvider <TObj, TContract>(subIdentifier, method, container, source, false);

            return(this);
        }
コード例 #5
0
 public ResolveProvider(
     Type contractType, DiContainer container, object identifier,
     bool isOptional, InjectSources source)
 {
     _contractType = contractType;
     _identifier   = identifier;
     _container    = container;
     _isOptional   = isOptional;
     _source       = source;
 }
コード例 #6
0
 public GetterProvider(
     object identifier, Func <TObj, TResult> method,
     DiContainer container, InjectSources sourceType, bool matchAll)
 {
     _container  = container;
     _identifier = identifier;
     _method     = method;
     _matchAll   = matchAll;
     _sourceType = sourceType;
 }
コード例 #7
0
ファイル: InjectableInfo.cs プロジェクト: UniDi/UniDi
 public InjectableInfo(
     bool optional, object identifier, string memberName, Type memberType,
     object defaultValue, InjectSources sourceType)
 {
     Optional     = optional;
     MemberType   = memberType;
     MemberName   = memberName;
     Identifier   = identifier;
     DefaultValue = defaultValue;
     SourceType   = sourceType;
 }
コード例 #8
0
 public InjectableInfo(
     bool optional, string identifier, string memberName,
     Type memberType, Type objectType, Action <object, object> setter, object defaultValue, InjectSources sourceType)
 {
     Optional     = optional;
     Setter       = setter;
     ObjectType   = objectType;
     MemberType   = memberType;
     MemberName   = memberName;
     Identifier   = identifier;
     DefaultValue = defaultValue;
     SourceType   = sourceType;
 }
コード例 #9
0
ファイル: InjectableInfo.cs プロジェクト: Soren025/Zenject
 public InjectableInfo(
     bool optional, object identifier, string memberName,
     Type memberType, Type objectType, Action<object, object> setter, object defaultValue, InjectSources sourceType)
 {
     Optional = optional;
     Setter = setter;
     ObjectType = objectType;
     MemberType = memberType;
     MemberName = memberName;
     Identifier = identifier;
     DefaultValue = defaultValue;
     SourceType = sourceType;
 }
コード例 #10
0
 void SetDefaults()
 {
     _objectType           = null;
     _parentContext        = null;
     _objectInstance       = null;
     _memberName           = "";
     _bindingId.Identifier = null;
     _bindingId.Type       = null;
     _optional             = false;
     _sourceType           = InjectSources.Any;
     _fallBackValue        = null;
     _container            = null;
 }
コード例 #11
0
ファイル: FromBinder.cs プロジェクト: Apeksi1990/module2
        protected ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveGetterBase <TObj, TResult>(
            object identifier, Func <TObj, TResult> method, InjectSources source, bool matchMultiple)
        {
            BindingUtil.AssertIsDerivedFromTypes(typeof(TResult), AllParentTypes);

            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;
            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new GetterProvider <TObj, TResult>(identifier, method, container, source, matchMultiple));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
コード例 #12
0
        ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveInternal(object subIdentifier, bool matchAll,
                                                                         InjectSources source)
        {
            BindInfo.RequireExplicitScope = false;
            // Don't know how it's created so can't assume here that it violates AsSingle
            BindInfo.MarkAsCreationBinding = false;

            SubFinalizer = new ScopableBindingFinalizer(
                BindInfo,
                (container, type) => new ResolveProvider(
                    type, container, subIdentifier, false, source, matchAll));

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
コード例 #13
0
ファイル: InjectContext.cs プロジェクト: Aszan/Zenject
 public InjectContext(
     DiContainer container, Type memberType, string identifier, bool optional,
     Type objectType, object objectInstance, string memberName,
     InjectContext parentContext, string concreteIdentifier,
     object fallBackValue, InjectSources sourceType)
 {
     ObjectType = objectType;
     ObjectInstance = objectInstance;
     Identifier = identifier;
     ConcreteIdentifier = concreteIdentifier;
     MemberName = memberName;
     MemberType = memberType;
     Optional = optional;
     FallBackValue = fallBackValue;
     Container = container;
     BindingId = new BindingId(memberType, identifier);
     ParentContext = parentContext;
     SourceType = sourceType;
 }
コード例 #14
0
ファイル: InjectContext.cs プロジェクト: halzate93/dungeon
 public InjectContext(
     DiContainer container, Type memberType, string identifier, bool optional,
     Type objectType, object objectInstance, string memberName,
     InjectContext parentContext, string concreteIdentifier,
     object fallBackValue, InjectSources sourceType)
 {
     ObjectType         = objectType;
     ObjectInstance     = objectInstance;
     Identifier         = identifier;
     ConcreteIdentifier = concreteIdentifier;
     MemberName         = memberName;
     MemberType         = memberType;
     Optional           = optional;
     FallBackValue      = fallBackValue;
     Container          = container;
     BindingId          = new BindingId(memberType, identifier);
     ParentContext      = parentContext;
     SourceType         = sourceType;
 }
コード例 #15
0
 public InjectOptionalAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
     IsOptional = true;
 }
コード例 #16
0
ファイル: InjectAttributeBase.cs プロジェクト: Aszan/Zenject
 public InjectOptionalAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
     IsOptional = true;
 }
コード例 #17
0
ファイル: InjectAttributeBase.cs プロジェクト: Aszan/Zenject
 public InjectOptionalAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
     IsOptional = true;
 }
コード例 #18
0
ファイル: FromBinder.cs プロジェクト: Apeksi1990/module2
 public ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveAll(object subIdentifier, InjectSources source)
 {
     return(FromResolveInternal(subIdentifier, true, source));
 }
コード例 #19
0
 public ScopeConditionCopyNonLazyBinder FromResolve(object subIdentifier, InjectSources source)
 {
     return(FromResolveInternal(subIdentifier, false, source));
 }
コード例 #20
0
ファイル: InjectAttributeBase.cs プロジェクト: Aszan/Zenject
 public InjectAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
 }
コード例 #21
0
 public InjectAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
 }
コード例 #22
0
 public InjectOptionalAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
     IsOptional = true;
 }
コード例 #23
0
 public InjectAttribute(string identifier, InjectSources sourceType)
 {
     Identifier = identifier;
     SourceType = sourceType;
 }
コード例 #24
0
 public ScopeConcreteIdArgConditionCopyNonLazyBinder FromResolveAllGetter <TObj>(object identifier, Func <TObj, TContract> method, InjectSources source)
 {
     return(FromResolveGetterBase <TObj, TContract>(identifier, method, source, true));
 }
コード例 #25
0
ファイル: InjectAttributeBase.cs プロジェクト: Aszan/Zenject
 public InjectAttribute(InjectSources sourceType)
 {
     SourceType = sourceType;
 }