Esempio n. 1
0
        internal static bool TryGetDefaultValue(ChoBaseConfigurationElement configElement, string propName,
                                                ChoPropertyInfoAttribute memberInfoAttribute, out string configDefaultValue)
        {
            configDefaultValue = 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.IsDefaultValueSpecified)
                    {
                        configDefaultValue = memberInfoAttribute.DefaultValue;
                        return(memberInfoAttribute.IsDefaultValueSpecified);
                    }
                }

                configDefaultValue = propInfo != null && propInfo.DefaultValue != null ? propInfo.DefaultValue.Value : null;
                return(propInfo != null ? propInfo.IsDefaultValueSpecified : false);
            }
            else if (memberInfoAttribute != null && memberInfoAttribute.IsDefaultValueSpecified)
            {
                configDefaultValue = memberInfoAttribute.DefaultValue;
                return(memberInfoAttribute.IsDefaultValueSpecified);
            }

            return(false);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        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)
            {
                ChoPropertyInfoMetaData propInfo = propertyInfo[propName];
                if (propInfo != null && propInfo.SourceType != null)
                {
                    return(propInfo.SourceType);
                }
            }

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

            return(null);
        }
Esempio n. 4
0
        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 <ChoPropertyInfoMetaData> propertyInfoList    = new List <ChoPropertyInfoMetaData>();
                                ChoPropertyInfoAttribute       memberInfoAttribute = null;

                                foreach (MemberInfo memberInfo in memberInfos)
                                {
                                    if (memberInfo.GetCustomAttribute <ChoIgnorePropertyAttribute>() != null)
                                    {
                                        continue;
                                    }

                                    memberInfoAttribute = (ChoPropertyInfoAttribute)ChoType.GetMemberAttribute(memberInfo, typeof(ChoPropertyInfoAttribute));
                                    ChoPropertyInfoMetaData propInfo = new ChoPropertyInfoMetaData();

                                    propInfo.Name = ChoType.GetMemberName(memberInfo);

                                    object defaultValue = memberInfo.GetDefaultValue();
                                    if (defaultValue != null)
                                    {
                                        propInfo.DefaultValue = new ChoCDATA(defaultValue.ToString());
                                    }

                                    if (memberInfoAttribute != null)
                                    {
                                        propInfo.FallbackValue            = new ChoCDATA(memberInfoAttribute.FallbackValue);
                                        propInfo.SourceType               = memberInfoAttribute.SourceType;
                                        propInfo.IsExpression             = memberInfoAttribute.IsExpression;
                                        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);
        }