當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。