コード例 #1
0
        static Dictionary <SysCategory, string> GetLogWebApplicationsNameFromFile()
        {
            List <KVEdm> kVEdms = Log2NetConfig.GetSectionVal("userSystemNames");

            if (kVEdms.Count > 0)
            {
                Dictionary <SysCategory, string> dic = kVEdms.ToDictionary(k => StringEnum.GetEnumValue <SysCategory>(k.Key), v => v.Value);
                return(dic);
            }
            else
            {
                var enumDic = StringEnum.GetDicFromEnumType(new SysCategory());
                return(enumDic.ToDictionary(k => (SysCategory)k.Value, v => v.Key));
            }
        }
コード例 #2
0
        public override object ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
        {
            int pos = 0;

            string[] objectIdParts = new string[2];

            while (reader.Read())
            {
                if (pos < 1)
                {
                    if (reader.TokenType == JsonToken.String)
                    {
                        objectIdParts[pos] = reader.Value.ToString();
                        pos++;
                    }
                }
                // read until the end of the JsonReader
            }

            return(new Language((LanguageCode)StringEnum.GetEnumValue(objectIdParts[0], typeof(LanguageCode))));//TODO: add: , objectIdParts[1], objectIdParts[2]);
        }
コード例 #3
0
ファイル: CustomPropertyGrid.cs プロジェクト: wshanshan/DDD
 private void UpdateValue(PropertyDescriptor thisProperty, XPathNavigator current, String value, Object onObject)
 {
     if (!(thisProperty.Converter is ArrayConverter))
     {
         // set value
         if (value.Length > 0)
         {
             if (thisProperty.Converter is EnumConverter) // enums are a special case
             {
                 StringEnum stringEnum = new StringEnum(thisProperty.PropertyType);
                 Boolean pass = stringEnum.IsStringDefined(value);
                 if (!pass) // normal case, no string value
                 {
                     thisProperty.SetValue(onObject,
                         thisProperty.Converter.ConvertFromString(value));
                 }
                 else // string value, reverse to the enum value
                 {
                     thisProperty.SetValue(onObject, thisProperty.Converter.ConvertFromString(stringEnum.GetEnumValue(value))); 
                 }
             }
             else // everyone else
             {
                 thisProperty.SetValue(onObject,
                     thisProperty.Converter.ConvertFromString(value));
             }
         }
         else
         {
             if (thisProperty.PropertyType == typeof(String)) // replace with empty string
             {
                 thisProperty.SetValue(onObject,
                     thisProperty.Converter.ConvertFromString(String.Empty));
             }
         }
     }
     else
     {
         if (thisProperty.Converter is ArrayConverter)
         {
             // select collection children
             XPathNodeIterator collectionChildren = current.Select("Parameter");
             int index = 0;
             Type elementType = thisProperty.PropertyType.GetElementType();
             Array newValue = Array.CreateInstance(elementType, collectionChildren.Count);
             foreach (XPathNavigator collectionChild in collectionChildren)
             {
                 String xmlValue = collectionChild.GetAttribute(ConfigFileConstants.Value, "");
                 Object result = Convert.ChangeType(xmlValue, elementType);
                 newValue.SetValue(result, index);
                 index++;
             }
             thisProperty.SetValue(onObject, newValue);
         }
     }
 }