/// <exclude /> public DefaultValue Clone() { switch (_valueType) { case DefaultValueType.Boolean: return(DefaultValue.Boolean((bool)_value)); case DefaultValueType.DateTime: return(DefaultValue.DateTime((DateTime)_value)); case DefaultValueType.DateTimeNow: return(DefaultValue.Now); case DefaultValueType.Decimal: return(DefaultValue.Decimal((decimal)_value)); case DefaultValueType.Guid: return(DefaultValue.Guid((Guid)_value)); case DefaultValueType.Integer: return(DefaultValue.Integer((int)_value)); case DefaultValueType.NewGuid: return(DefaultValue.NewGuid); case DefaultValueType.String: return(DefaultValue.String((string)_value)); case DefaultValueType.RandomString: return(new DefaultValue(_randomStringSettings)); default: throw new NotImplementedException(); } }
/// <exclude /> public static DefaultValue Deserialize(string serializedData) { Verify.ArgumentNotNullOrEmpty(serializedData, "serializedData"); using (TimerProfilerFacade.CreateTimerProfiler()) { Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedData); Verify.That(dic.ContainsKey("ValueType"), "Wrong serialized format"); string valueTypeString = StringConversionServices.DeserializeValue <string>(dic["ValueType"]); var valueType = (DefaultValueType)Enum.Parse(typeof(DefaultValueType), valueTypeString); bool hasValue = dic.ContainsKey("Value"); switch (valueType) { case DefaultValueType.Boolean: Verify.That(hasValue, "Wrong serialized format"); bool boolValue = StringConversionServices.DeserializeValueBool(dic["Value"]); return(DefaultValue.Boolean(boolValue)); case DefaultValueType.DateTime: Verify.That(hasValue, "Wrong serialized format"); DateTime dateTimeValue = StringConversionServices.DeserializeValueDateTime(dic["Value"]); return(DefaultValue.DateTime(dateTimeValue)); case DefaultValueType.DateTimeNow: return(DefaultValue.Now); case DefaultValueType.Decimal: Verify.That(hasValue, "Wrong serialized format"); decimal decimalValue = StringConversionServices.DeserializeValueDecimal(dic["Value"]); return(DefaultValue.Decimal(decimalValue)); case DefaultValueType.Guid: Verify.That(hasValue, "Wrong serialized format"); Guid guidValue = StringConversionServices.DeserializeValueGuid(dic["Value"]); return(DefaultValue.Guid(guidValue)); case DefaultValueType.Integer: Verify.That(hasValue, "Wrong serialized format"); int intValue = StringConversionServices.DeserializeValueInt(dic["Value"]); return(DefaultValue.Integer(intValue)); case DefaultValueType.NewGuid: return(DefaultValue.NewGuid); case DefaultValueType.String: string stringValue = null; if (hasValue) { stringValue = StringConversionServices.DeserializeValueString(dic["Value"]); } return(DefaultValue.String(stringValue)); case DefaultValueType.RandomString: var settings = RandomStringSettings.Deserialize(dic); return(new DefaultValue(settings)); default: throw new NotImplementedException("DefaultValueType = " + valueType); } } }