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


C# JObject.Properties方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.Properties方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.Properties方法的具体用法?C# JObject.Properties怎么用?C# JObject.Properties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JObject的用法示例。


在下文中一共展示了JObject.Properties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HasRed

 private static bool HasRed(JObject jObject)
 {
     return jObject.Properties()
         .Select(x => x.Value)
         .OfType<JValue>()
         .Any(x => x.Value<string>() == "red");
 }
开发者ID:navoznov,项目名称:AdventOfCode,代码行数:7,代码来源:Program.cs

示例2: GetSum

        long GetSum(JArray arr, string avoid) => arr.Sum((dynamic a) => (long)GetSum(a, avoid)); //don't understand

        long GetSum(JObject o, string avoid = null) //don't understand
        {
            bool shouldAvoid = o.Properties()
                .Select(a => a.Value).OfType<JValue>()
                .Select(v => v.Value).Contains(avoid);
            if (shouldAvoid) return 0;

            return o.Properties().Sum((dynamic a) => (long)GetSum(a.Value, avoid));
        }
开发者ID:funkysi1701,项目名称:AdventSolution,代码行数:11,代码来源:day12.cs

示例3: CompareMaps

        private static void CompareMaps(JObject expected, JObject actual)
        {
            var expectedFileds = expected.Properties().Select(f => f.Name).ToList();
            var actualFields = actual.Properties().Select(f => f.Name).ToList();
            if (!expectedFileds.OrderBy(f => f).SequenceEqual(actualFields.OrderBy(f => f)))
                FailDifferentObjects(expectedFileds, actualFields, expected, actual);

            foreach (var expectedProperty in expected.Properties())
            {
                var actualProperty = actual.Property(expectedProperty.Name);
                CompareTokens(expectedProperty.Value, actualProperty.Value);
            }
        }
开发者ID:vtex,项目名称:specs-owin-pt,代码行数:13,代码来源:JsonComparer.cs

示例4: CreateEvent

    /// <summary>
    /// You could implement this with reflection or some other deserialize algorithm.
    /// For this sample, we explicitly implemented this.
    /// </summary>
    /// <param name="eventJson"></param>
    /// <returns></returns>
    public Event CreateEvent(JObject eventJson)
    {
      var eventName = eventJson.Properties().First().Name;
      var eventBody = eventJson.Properties().First().Value.Value<JObject>();

      switch(eventName)
      {
        case "CQRSMicroservices.Articles.ArticleCreatedEvent":

          return new ArticleCreatedEvent
          {
            ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
            Description = eventBody["Description"].Value<string>(),
            Price = decimal.Parse(eventBody["Price"].Value<string>(), CultureInfo.InvariantCulture)
          };

        case "CQRSMicroservices.Articles.ArticleAvailableEvent":

          return new ArticleAvailableEvent
          {
            ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
          };

        case "CQRSMicroservices.Articles.ArticleUnavailableEvent":
          return new ArticleUnavailableEvent
          {
            ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
          };

        case "CQRSMicroservices.Articles.ArticleSoldEvent":
          return new ArticleSoldEvent
          {
            ArticleId = Guid.Parse(eventBody["ArticleId"].Value<string>()),
            CustomerId = Guid.Parse(eventBody["CustomerId"].Value<string>()),
            Price = decimal.Parse(eventBody["Price"].Value<string>(), CultureInfo.InvariantCulture)
          };

        case "CQRSMicroservices.Customers.CustomerCreatedEvent":
          return new CustomerCreatedEvent
          {
            CustomerId = Guid.Parse(eventBody["CustomerId"].Value<string>()),
            Name = eventBody["Name"].Value<string>()
          };

        default:
          throw new EventNotFoundException(eventName);
      }
    }
开发者ID:AFASResearch,项目名称:CQRS-Playground,代码行数:54,代码来源:Deserializer.cs

示例5: AddLookupData

        public static JObject AddLookupData(string environment, JObject o)
        {
            var props = o.Properties().ToList();
            foreach (var p in props)
            {
                foreach (var k in LookupIdIndex.Keys)
                {
                    if (p.Name == k && p.Value != null && p.Value.ToString() != string.Empty)
                    {
                        Table lookupTable = LookupIdIndex[k];

                        JObject lookupItem = Get(environment, lookupTable.Name, p.Value.ToString());

                        if (lookupItem != null)
                        {
                            if (lookupTable.LookupDescriptor != null)
                            {
                                o[lookupTable.Name] = lookupItem[lookupTable.LookupDescriptor];
                            }
                            else
                            {
                                o[lookupTable.Name] = lookupItem;
                            }

                            o.Remove(p.Name);
                        }
                    }
                }
            }

            return o;
        }
开发者ID:NGPVAN,项目名称:dnorml,代码行数:32,代码来源:Cache.cs

示例6: ParseFieldsData

    public static List<IField> ParseFieldsData(JObject fieldsData, CancellationToken cancelToken)
    {
      if (fieldsData == null)
      {
        throw new ArgumentNullException();
      }

      var fields = new List<IField>();

      IList<string> propertyNames = fieldsData.Properties().Select(p => p.Name).ToList();


      foreach (string fieldId in propertyNames)
      {
        cancelToken.ThrowIfCancellationRequested();

        JObject fieldData = (JObject)fieldsData.GetValue(fieldId);
        var name = (string)fieldData.GetValue("Name");
        var type = (string)fieldData.GetValue("Type");
        var value = (string)fieldData.GetValue("Value");

        ScField newField = new ScField(fieldId, name, type, value);
        fields.Add(newField);
      }

      return fields;
    }
开发者ID:amatkivskiy,项目名称:sitecore-xamarin-pcl-sdk,代码行数:27,代码来源:ScFieldsParser.cs

示例7: ApplyChanges

        /// <summary>
        /// Patches an existing source <see cref="JObject"/> with (potentially 
        /// partial) changes from another <see cref="JObject"/>.
        /// </summary>
        public static void ApplyChanges(this JObject source, JObject changes)
        {
            // Metadata properties are never applied.
            foreach (var changedProp in changes.Properties().Where(prop => !prop.Name.StartsWith("$"))) {
                var sourceProp = source.Property (changedProp.Name);

                // If source property doesn't exist, add the new one directly.
                if (sourceProp == null) {
                    source.Add (changedProp);
                    continue;
                }

                // If the type changed, or if it's not a JObject, just overwrite
                // the entire existing property.
                if (sourceProp.Value.Type != changedProp.Value.Type ||
                    sourceProp.Value.Type != JTokenType.Object) {
                    sourceProp.Value = changedProp.Value;
                    continue;
                }

                var sourceObj = (JObject)sourceProp.Value;
                var changeObj = (JObject)changedProp.Value;

                // Recurse.
                ApplyChanges (sourceObj, changeObj);
            }
        }
开发者ID:ReedCopsey,项目名称:DynamicForms,代码行数:31,代码来源:JsonExtensions.cs

示例8: DefineTable

        /// <summary>
        /// Defines the local table on the store.
        /// </summary>
        /// <param name="tableName">Name of the local table.</param>
        /// <param name="item">An object that represents the structure of the table.</param>
        public override void DefineTable(string tableName, JObject item)
        {
            if (tableName == null)
            {
                throw new ArgumentNullException("tableName");
            }
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }

            if (this.Initialized)
            {
                throw new InvalidOperationException("Cannot define a table after the store has been initialized.");
            }

            // add id if it is not defined
            JToken ignored;
            if (!item.TryGetValue(MobileServiceSystemColumns.Id, StringComparison.OrdinalIgnoreCase, out ignored))
            {
                item[MobileServiceSystemColumns.Id] = String.Empty;
            }

            var tableDefinition = (from property in item.Properties()
                                   let storeType = SqlHelpers.GetStoreType(property.Value.Type, allowNull: false)
                                   select new ColumnDefinition(property.Name, property.Value.Type, storeType))
                                  .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase);

            var sysProperties = GetSystemProperties(item);

            this.tableMap.Add(tableName, new TableDefinition(tableDefinition, sysProperties));
        }
开发者ID:brettsam,项目名称:azure-mobile-apps-net-client,代码行数:37,代码来源:MobileServiceSQLiteStore.cs

示例9: RegisterAsync

        /// <summary>
        /// Register an Installation with particular registrationId and templates
        /// </summary>
        /// <param name="registrationId">The registrationId to register</param>
        /// <param name="templates">JSON with one more templates to register</param>
        /// <returns>Task that completes when registration is complete</returns>
        public Task RegisterAsync(string registrationId, JObject templates)
        {
            if (string.IsNullOrWhiteSpace(registrationId))
            {
                throw new ArgumentNullException("registrationId");
            }

            JObject installation = new JObject();
            installation[PushInstallationProperties.PUSHCHANNEL] = registrationId;
            installation[PushInstallationProperties.PLATFORM] = Platform.Instance.PushUtility.GetPlatform();
            if (templates != null)
            {
                JObject templatesWithStringBody = templates;
                foreach (JProperty template in templates.Properties())
                {
                    //Notification hub requires template body to be a string.Convert to string from JObject
                    var templateBody = template.Value["body"];
                    if (templateBody != null && templateBody.GetType() == typeof(JObject))
                    {
                        templatesWithStringBody[template.Name]["body"] = templateBody.ToString();
                    }
                }
                installation[PushInstallationProperties.TEMPLATES] = templatesWithStringBody;
            }
            return this.PushHttpClient.CreateOrUpdateInstallationAsync(installation);
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:32,代码来源:Push.cs

示例10: Fields

 public Fields(JObject json)
 {
     fields = new Dictionary<string, string>();
     IList<string> keys = json.Properties().Select(p => p.Name).ToList();
     foreach (string key in keys)
         fields[key] = json[key].ToString();
 }
开发者ID:schmidt4brains,项目名称:TimberWinR,代码行数:7,代码来源:GrokFilter.cs

示例11: SetProperties

 public void SetProperties(JObject properties)
 {
     foreach (var property in properties.Properties())
     {
         this[property.Name] = property.Value;
     }
 }
开发者ID:itravail,项目名称:PlatformClient.NET,代码行数:7,代码来源:Entity.cs

示例12: FromJson

        /// <summary>
        /// 从 JSON 数据中加载
        /// </summary>
        /// <param name="data">JSON 数据</param>
        /// <returns></returns>
        public static Item[] FromJson( JObject data )
        {
            if ( data == null )
            return new Item[0];

              return data.Properties().Select( p => CreateItem( p ) ).Where( item => item != null ).ToArray();
        }
开发者ID:Ivony,项目名称:HelloWorld,代码行数:12,代码来源:ItemListJsonConverter.cs

示例13: FindChildByText

        private JProperty FindChildByText(string child, JObject obj)
        {
            var p=   obj.Properties().Where(prop => prop.Contains(child)).ToList();

            JProperty newChildJObject = new JProperty("text",child);
            return newChildJObject;
        }
开发者ID:chitrang89,项目名称:StringToTree,代码行数:7,代码来源:Helper.cs

示例14: UpdateBridgeLightsWithJObject

        public static void UpdateBridgeLightsWithJObject(Bridge bridge, JObject json)
        {
            try
            {
                // Get light keys
                IList<string> lightKeys = json.Properties().Select(p => p.Name).ToList();

                bridge.LightList.Clear();
                bridge.LightCache.Clear();

                foreach(var lightId in lightKeys)
                {
                    Light light = new Light();
                    light.LightId = lightId;
                    bridge.LightList.Add(light);
                    bridge.LightCache[lightId] = light;

                    JObject lightJson = (JObject)json[lightId];
                    LightFactory.UpdateLightWithJObject(light, lightJson);
                }
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
开发者ID:chandrachivukula,项目名称:hue,代码行数:26,代码来源:BridgeFactory.cs

示例15: Example

        public void Example()
        {
            #region Usage
            JObject o = new JObject
            {
                { "name1", "value1" },
                { "name2", "value2" }
            };

            foreach (JProperty property in o.Properties())
            {
                Console.WriteLine(property.Name + " - " + property.Value);
            }
            // name1 - value1
            // name2 - value2

            foreach (KeyValuePair<string, JToken> property in o)
            {
                Console.WriteLine(property.Key + " - " + property.Value);
            }
            // name1 - value1
            // name2 - value2
            #endregion

            Assert.AreEqual(2, o.Count);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:26,代码来源:JObjectProperties.cs


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