internal static bool TryConfigDefaultValue(ChoBaseConfigurationElement configElement, string propName, ChoPropertyInfoAttribute memberInfoAttribute, out object configDefaultValue) { configDefaultValue = null; ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement); if (propertyInfo != null) { ChoPropertyInfo propInfo = propertyInfo[propName]; if (propInfo == null) { return(false); } configDefaultValue = propInfo != null ? propInfo.DefaultValue : null; return(propInfo != null ? propInfo.IsDefaultValueSpecified : false); } else if (memberInfoAttribute != null && memberInfoAttribute.IsDefaultValueSpecified) { configDefaultValue = memberInfoAttribute.DefaultValue; return(memberInfoAttribute.IsDefaultValueSpecified); } return(false); }
internal static Type GetSourceType(ChoBaseConfigurationElement configElement, string propName, ChoPropertyInfoAttribute memberInfoAttribute) { ChoGuard.ArgumentNotNull(configElement, "ConfigElement"); ChoGuard.ArgumentNotNull(propName, "PropertyName"); ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement); if (propertyInfo != null) { ChoPropertyInfo propInfo = propertyInfo[propName]; if (propInfo != null && propInfo.SourceType != null) { return(propInfo.SourceType); } } if (memberInfoAttribute != null && memberInfoAttribute.SourceType != null) { return(memberInfoAttribute.SourceType); } return(null); }
private static ChoPropertyInfos ConstructPropertyInfos(ChoBaseConfigurationElement configElement) { if (configElement != null && configElement.ConfigbObjectType != null) { Dictionary <string, ChoPropertyInfos> propDict = _propDict; string configElementPath = configElement.ConfigElementPath; if (configElementPath.IsNullOrWhiteSpace()) { return(ChoPropertyInfos.Default); } if (!propDict.ContainsKey(configElementPath)) { lock (_padLock) { if (!propDict.ContainsKey(configElementPath)) { MemberInfo[] memberInfos = ChoTypeMembersCache.GetAllMemberInfos(configElement.ConfigbObjectType); if (memberInfos != null && memberInfos.Length > 0) { //Set member values List <ChoPropertyInfo> propertyInfoList = new List <ChoPropertyInfo>(); ChoPropertyInfoAttribute memberInfoAttribute = null; foreach (MemberInfo memberInfo in memberInfos) { if (memberInfo.GetCustomAttribute <ChoIgnorePropertyAttribute>() != null) { continue; } memberInfoAttribute = (ChoPropertyInfoAttribute)ChoType.GetMemberAttribute(memberInfo, typeof(ChoPropertyInfoAttribute)); ChoPropertyInfo propInfo = new ChoPropertyInfo(); propInfo.Name = ChoType.GetMemberName(memberInfo); if (memberInfoAttribute != null) { propInfo.DefaultValue = memberInfoAttribute.DefaultValue; propInfo.FallbackValue = memberInfoAttribute.FallbackValue; propInfo.SourceType = memberInfoAttribute.SourceType; propInfo.IsDefaultValueSpecified = memberInfoAttribute.IsDefaultValueSpecified; propInfo.IsFallbackValueSpecified = memberInfoAttribute.IsFallbackValueSpecified; } propertyInfoList.Add(propInfo); } if (propertyInfoList.Count > 0) { ChoPropertyInfos propertyInfos = new ChoPropertyInfos(); propertyInfos.PropertyInfoArr = propertyInfoList.ToArray(); return(propertyInfos); } } } } } } return(ChoPropertyInfos.Default); }