当前位置: 首页>>代码示例>>C#>>正文


C# JObject.SetModel方法代码示例

本文整理汇总了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;
 }
开发者ID:CyberBotX,项目名称:sda-donation-tracker,代码行数:9,代码来源:JObjectEntityHelpers.cs

示例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");
        }
开发者ID:CyberBotX,项目名称:sda-donation-tracker,代码行数:40,代码来源:TableBinding.cs

示例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;
        }
开发者ID:CyberBotX,项目名称:sda-donation-tracker,代码行数:30,代码来源:FormBinding.cs


注:本文中的Newtonsoft.Json.Linq.JObject.SetModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。