我有配置对象,如下所示
Key
因此每个配置对象可以具有不同的属性。 (只有JsonSerializerSettings settings = new JsonSerializerSettings
{
TypeNameHandling = TypeNameHandling.All
};
var configA = new ConfigurationA()
{
Key = "A"
// assign other properties here
}
var strA = JsonConvert.SerializeObject(configA, settings);
StoreInDB(strA);
var configB= new ConfigurationB()
{
Key = "B"
// assign other properties here
}
var strB = JsonConvert.SerializeObject(configB, settings);
StoreInDB(strB);
是公共财产)
然后我序列化配置对象并作为单独的记录存储在DB中
var str= GetConfigurationFromDB("A");
var config = JsonConvert.DeserializeObject<BaseConfiguration>(str);
Now When i try to cast `Configuration` property to respective Configuration class it returns null
if(configA.Key == "A")
{
var configA = config as ConfigurationA;
}
现在我通过传递一些参数
来检索序列化配置<div class="col-12 col-md-7">
<span>Select the fixture type:*</span>
<select id="fixture-type">
<option>Select1</option>
<option>Select2</option>
<option>Select3</option>
</select>
<button class="btn-primary" id="mybtn">+ ADD FEATURE</button>
</div>
<div class="col-12 col-md-5">
<div class="append-list ul">
<!--Append selection box items here-->
</div>
</div>
$('#mybtn').click(function(){
$(".append-list").append('<li>'+ $('#fixture-type').val() +'</li>');
});
什么是序列化配置的方法,所以当我反序列化它时我可以输入强制类型的类型?
我在这里查看了SO post,但这并没有帮助。