public static void DisposeWatcher(ChoBaseConfigurationElement configElement)
        {
            if (configElement == null)
            {
                return;
            }

            ConfigurationChangeWatcher.SetConfigurationChangedEventHandler("{0}_PCMetaData_WatcherHandler".FormatString(configElement.ConfigElementPath), NullConfigurationChangedEventHandler);
        }
Пример #2
0
        internal static Dictionary <string, object> ToPersistableDictionaryCollection(ChoBaseConfigurationElement configElement, Type itemType)
        {
            ChoGuard.ArgumentNotNull(configElement, "ConfigElement");

            object target = configElement.ConfigObject;

            ChoGuard.ArgumentNotNull(target, "Target");

            Dictionary <string, object> dict = new Dictionary <string, object>();

            //Dictionary<string, MemberInfo> configMemberInfos = ChoType.GetMembersDictionary(target.GetType(), typeof(ChoConfigurationPropertyAttribute));
            //MemberInfo[] memberInfos = ChoType.GetMembers(target.GetType(), typeof(ChoConfigurationPropertyAttribute));
            MemberInfo[] memberInfos = ChoTypeMembersCache.GetAllMemberInfos(target.GetType());
            if (memberInfos == null || memberInfos.Length == 0)
            {
                return(dict);
            }

            ChoPropertyInfoAttribute memberInfoAttribute = null;
            string name = null;

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

                object memberValue = ChoType.GetMemberValue(target, memberInfo.Name);
                memberInfoAttribute = (ChoPropertyInfoAttribute)ChoType.GetMemberAttribute(memberInfo, typeof(ChoPropertyInfoAttribute));
                name = ChoType.GetMemberName(memberInfo, memberInfoAttribute);

                if (target is ChoConfigurableObject && ((ChoConfigurableObject)target).RaiseBeforeConfigurationObjectMemberPersist(memberInfo.Name, name, ref memberValue))
                {
                    dict.Add(name, memberValue);
                }
                else
                {
                    if (memberInfoAttribute != null && !memberInfoAttribute.Persistable)
                    {
                        continue;
                    }

                    memberValue = ChoType.GetMemberValue(target, memberInfo.Name);
                    Type memberType = ChoConfigurationMetaDataManager.GetSourceType(configElement, name, memberInfoAttribute);

                    if (memberType == null)
                    {
                        if (itemType == typeof(Object))
                        {
                            memberType = ChoType.GetMemberType(memberInfo);
                        }
                        else
                        {
                            memberType = itemType;
                        }
                    }
                    dict.Add(name, ChoConvert.ConvertTo(target, memberValue, memberType,
                                                        ChoTypeDescriptor.GetTypeConverters(memberInfo), ChoTypeDescriptor.GetTypeConverterParams(memberInfo), null));
                }
            }
            return(dict);
        }
Пример #3
0
 internal static Dictionary <string, object> ToPersistableDictionaryCollection(ChoBaseConfigurationElement configElement)
 {
     return(ToPersistableDictionaryCollection(configElement, typeof(string)));
 }