static InjectableInfo CreateInjectableInfoForParam( Type parentType, ParameterInfo paramInfo) { List <InjectAttributeBase> 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); InjectAttributeBase 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)); }
static InjectableInfo CreateForMember(MemberInfo memInfo, Type parentType) { List <InjectAttributeBase> 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); InjectAttributeBase 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) { FieldInfo fieldInfo = (FieldInfo)memInfo; setter = ((object injectable, object value) => fieldInfo.SetValue(injectable, value)); memberType = fieldInfo.FieldType; } else { Assert.That(memInfo is PropertyInfo); PropertyInfo 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)); }