Пример #1
0
 // 												{0}  {1:D2}  | #{text}   |   @{C065F955-1FAD-40df-B2FC-285D62F14E0A}
 public static ConfigItemVersion ToConfigItemVersion(object value)
 {
     if (value == null) throw new ConfigException("Cannot convert null");
     int type;
     ConfigItemVersion ver = null;
     string name = value.GetType().FullName;
     switch (name)
     {
         case "System.String":
             type = StringWithArgs.IsMatch((string)value)
                 ? ConfigValueType.StringWithArgs
                 : ConfigValueType.StringLiteral;
             ver = new CfgText { VersionValue = value, ValueType = type };
             break;
         case "System.Boolean":
             ver = new CfgBool { VersionValue = value };
             break;
         case "System.Drawing.Color":
             ver = new CfgColor { VersionValue = value };
             break;
         case "System.Decimal":
             ver = new CfgNumber{ VersionValue = value, ValueType = ConfigValueType.Decimal };
             break;
         case "System.Double":
         case "System.Float":
             ver = new CfgNumber{ VersionValue = value, ValueType = ConfigValueType.Real };
             break;
         case "System.Uri":
             //TODO ConfigurationService: CfgURI to be implemented
             break;
         case "Imarda.Lib.Measurement":
             ver = new CfgMeasurement { VersionValue = value, ValueType = ConfigValueType.Measurement };
             break;
         default:
             if (name.StartsWith("System.Xml.Xml"))
             {
                 ver = new CfgXml { VersionValue = value };
             }
             else if (name.StartsWith("System.Int") || name.StartsWith("System.UInt"))
             {
                 ver = new CfgNumber { VersionValue = value };
             }
             break;
     }
     return ver;
 }
Пример #2
0
 private static ConfigItemVersion Create(int type)
 {
     ConfigItemVersion result;
     switch (type)
     {
         case ConfigValueType.StringLiteral:
         case ConfigValueType.StringWithArgs:
             result = new CfgText(type);
             break;
         case ConfigValueType.Bool:
             result = new CfgBool();
             break;
         case ConfigValueType.Integer:
         case ConfigValueType.Decimal:
         case ConfigValueType.Real:
             result = new CfgNumber(type);
             break;
         case ConfigValueType.Color:
             result = new CfgColor();
             break;
         case ConfigValueType.Parameters:
             result = new CfgParams();
             break;
         case ConfigValueType.Xml:
             result = new CfgXml();
             break;
         case ConfigValueType.Measurement:
             result = new CfgMeasurement();
             break;
         //case ConfigValueType.Uri:
         //case ConfigValueType.Font:
         //case ConfigValueType.RichText:
         default:
             throw new ConfigException(type + ": data type is not yet supported");
     }
     return result;
 }