protected override ValueModel Create(Type objectType, JObject jObject) { if (jObject == null) { throw new ArgumentNullException("jObject"); } var valueType = jObject["ValueType"].Value <string>(); ValueModel valueModel = new ValueModel(); switch (valueType) { case ValueModelType.INT: valueModel = new IntValueModel(); break; case ValueModelType.SQL: valueModel = new SQLValueModel(); break; case ValueModelType.STRING: valueModel = new StringValueModel(); break; case ValueModelType.DATE: valueModel = new DateValueModel(); break; case ValueModelType.BOOL: valueModel = new BoolValueModel(); break; default: throw new ModelException("Can not parse value type"); } return(valueModel); }
public void Test_Setting_String_Value_To_Other_Types() { var obj = new StringValueModel() { }; var members = ExtFastMember.GetMemberWrappers <StringValueModel>(true); foreach (var member in members) { if (member.Name == "DateTimeOffset") { member.SetMemberValue(obj, "2017-05-30"); Assert.AreEqual(member.GetValue(obj), DateTimeOffset.Parse("2017-05-30")); } if (member.Name == "Guid") { member.SetMemberValue(obj, "a19ed8e6-c455-4164-afac-d4043095a4ee"); Assert.AreEqual(member.GetValue(obj), Guid.Parse("a19ed8e6-c455-4164-afac-d4043095a4ee")); } if (member.Name == "TimeSpan") { member.SetMemberValue(obj, "01:00:00"); Assert.AreEqual(member.GetValue(obj), TimeSpan.Parse("01:00:00")); } } }