本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.SetModel方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.SetModel方法的具体用法?C# JObject.SetModel怎么用?C# JObject.SetModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.SetModel方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateEntityObject
public static JObject CreateEntityObject(string model, int? id = null)
{
JObject result = new JObject();
result.SetModel(model);
if (id != null)
result.SetId(id ?? 0);
result.Add("fields", new JObject());
return result;
}
示例2: RetreiveObjectFromRow
private JObject RetreiveObjectFromRow(DataRow row, bool diffOnly = false)
{
int? pk = row.Field<int?>(this.Table.Columns[KeyColumn]);
string modelName = row.Field<string>(this.Table.Columns[ModelColumn]);
JObject obj = new JObject();
obj.Add(FieldsField, new JObject());
if (pk != null)
obj.SetId(pk ?? 0);
if (modelName == null)
throw new Exception("Error, model must be set for data field");
obj.SetModel(modelName);
if (this.ModelMappings.ContainsKey(modelName))
{
Dictionary<string, string> tableToModel = this.ModelMappings[modelName].TableToModel;
EntityModel model = DonationModels.GetModel(modelName);
foreach (string col in this.Columns)
{
JObject found = null;
if (obj.GetId() != null)
this.CachedObjectTable.TryGetValue(new Tuple<string, int?>(obj.GetModel(), obj.GetId()), out found);
string fieldName = tableToModel[col];
string value = row[this.TrueColumnName(col)] == null ? null : row[this.TrueColumnName(col)].ToString();
if (!model.GetField(fieldName).ReadOnly && (!diffOnly || found == null || !Util.EqualsEx(found.GetField(fieldName), value)))
obj.SetField(fieldName, value);
}
return obj;
}
else
throw new Exception("Model mapping for " + modelName + " unregistered");
}
示例3: SaveObject
/**
* Calling this with diffOnly=true will, if there is already a cached object, return
* only those fields whose values have changed.
*/
public JObject SaveObject(bool diffOnly = false)
{
JObject obj = new JObject();
obj.Add(FieldsField, new JObject());
if (this.CachedData != null)
{
if (this.CachedData.GetId() != null)
obj.SetId(this.CachedData.GetId() ?? 0);
obj.SetModel(this.CachedData.GetModel());
}
foreach (KeyValuePair<string, FieldBinding> entry in this.Bindings)
{
FieldModel field = this.SearchForm ? this.Model.GetSearchField(entry.Key).FieldType : this.Model.GetField(entry.Key);
string fieldValue = entry.Value.RetreiveField();
if (!field.ReadOnly && (!diffOnly || this.CachedData == null || !Util.EqualsEx(fieldValue, this.CachedData.GetField(entry.Key))))
obj.SetField(entry.Key, fieldValue);
}
Console.WriteLine(obj.ToString());
return obj;
}