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);
        }
예제 #2
0
        internal static bool TryGetFallbackValue(ChoBaseConfigurationElement configElement, string propName,
                                                 ChoPropertyInfoAttribute memberInfoAttribute, out string configFallbackValue)
        {
            configFallbackValue = null;

            ChoGuard.ArgumentNotNull(configElement, "ConfigElement");
            ChoGuard.ArgumentNotNull(propName, "PropertyName");

            ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement);

            if (propertyInfo != null)
            {
                ChoPropertyInfoMetaData propInfo = propertyInfo[propName];
                if (propInfo == null)
                {
                    if (memberInfoAttribute != null && memberInfoAttribute.IsFallbackValueSpecified)
                    {
                        configFallbackValue = memberInfoAttribute.FallbackValue;
                        return(memberInfoAttribute.IsFallbackValueSpecified);
                    }
                }

                configFallbackValue = propInfo != null && propInfo.FallbackValue != null ? propInfo.FallbackValue.Value : null;
                return(propInfo != null ? propInfo.IsFallbackValueSpecified : false);
            }
            else if (memberInfoAttribute != null && memberInfoAttribute.IsFallbackValueSpecified)
            {
                configFallbackValue = memberInfoAttribute.FallbackValue;
                return(memberInfoAttribute.IsFallbackValueSpecified);
            }

            return(false);
        }
        private static ChoPropertyInfos GetPropertyInfos(ChoBaseConfigurationElement configElement)
        {
            string configElementPath = configElement.ConfigElementPath;

            if (configElementPath.IsNullOrWhiteSpace())
            {
                return(null);
            }

            Dictionary <string, ChoPropertyInfos> propDict = _propDict;

            if (!propDict.ContainsKey(configElementPath))
            {
                lock (_padLock)
                {
                    if (!propDict.ContainsKey(configElementPath))
                    {
                        string  xpath = @"//{0}/propertyInfos".FormatString(configElementPath);
                        XmlNode node  = null;

                        if (_rootNode != null)
                        {
                            node = _rootNode.SelectSingleNode(xpath);
                        }

                        if (node != null)
                        {
                            propDict.Add(configElementPath, ChoPropertyInfos.Default);

                            ChoPropertyInfos propertyInfos = node.ToObject(typeof(ChoPropertyInfos)) as ChoPropertyInfos;
                            propertyInfos.Initialize();
                            propDict[configElementPath] = propertyInfos;
                        }
                        else
                        {
                            propDict[configElementPath] = ConstructPropertyInfos(configElement);
                        }
                    }
                }
            }

            return(propDict[configElementPath]);
        }
        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);
        }
예제 #5
0
        internal static bool IsExpressionProperty(ChoBaseConfigurationElement configElement, string propName,
                                                  ChoPropertyInfoAttribute memberInfoAttribute)
        {
            ChoGuard.ArgumentNotNull(configElement, "ConfigElement");
            ChoGuard.ArgumentNotNull(propName, "PropertyName");

            ChoPropertyInfos propertyInfo = GetPropertyInfos(configElement);

            if (propertyInfo != null)
            {
                ChoPropertyInfoMetaData propInfo = propertyInfo[propName];
                if (propInfo != null)
                {
                    return(propInfo.IsExpression);
                }
            }

            if (memberInfoAttribute != null)
            {
                return(memberInfoAttribute.IsExpression);
            }

            return(false);
        }
        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);
        }