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


C# JArray.First方法代码示例

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


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

示例1: TryParsePullRequestInfo

        internal static bool TryParsePullRequestInfo(JArray actions, out PullRequestInfo info)
        {
            var container = actions.First(x => x["parameters"] != null);

            string sha1 = null;
            string pullLink = null;
            int? pullId = null;
            string pullAuthorEmail = null;
            string commitAuthorEmail = null;
            var parameters = (JArray)container["parameters"];
            foreach (var pair in parameters)
            {
                switch (pair.Value<string>("name"))
                {
                    case "ghprbActualCommit":
                        sha1 = pair.Value<string>("value");
                        break;
                    case "ghprbPullId":
                        pullId = pair.Value<int>("value");
                        break;
                    case "ghprbPullAuthorEmail":
                        pullAuthorEmail = pair.Value<string>("value");
                        break;
                    case "ghprbActualCommitAuthorEmail":
                        commitAuthorEmail = pair.Value<string>("value");
                        break;
                    case "ghprbPullLink":
                        pullLink = pair.Value<string>("value");
                        break;
                    default:
                        break;
                }
            }

            // It's possible for the pull email to be blank if the Github settings for the user
            // account hides their public email address.  In that case fall back to the commit
            // author.  It's generally the same value and serves as a nice backup identifier.
            if (string.IsNullOrEmpty(pullAuthorEmail))
            {
                pullAuthorEmail = commitAuthorEmail;
            }

            if (sha1 == null || pullLink == null || pullId == null || pullAuthorEmail == null)
            {
                info = null;
                return false;
            }

            info = new PullRequestInfo(
                authorEmail: pullAuthorEmail,
                id: pullId.Value,
                pullUrl: pullLink,
                sha1: sha1);
            return true;
        }
开发者ID:dpoeschl,项目名称:jenkins,代码行数:55,代码来源:JsonUtil.cs

示例2: RetrievingCustomerAddressesByZipCode

        public void RetrievingCustomerAddressesByZipCode(JArray addresses)
        {
            const int CustomerId = 346760;
            const string ZipCode = "802";

            "Given existing addresses".
                 f(() =>
                 {
                     MockAddressesStore.Setup(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))).Returns((int customerId, AddressesFilter addressFilter) =>
                     {
                         var filteredAddresses = from n in this.FakeAddresses
                                                 where n.Value<string>("ZipCode").Contains(addressFilter.Zip) &&
                                                       n.Value<int>("OwnerId") == CustomerId
                                                 select n;

                         return Task.FromResult<dynamic>(filteredAddresses);
                     });
                 });
            "When a GET 'addresses for a customer by zip code' request is sent".
                f(() =>
                {
                    Response = Client.GetAsync(new Uri(string.Format(_customerAddressesFormat, CustomerId) + "/?Zip=" + ZipCode)).Result;
                });
            "Then the request is received by the API Controller".
                f(() => MockAddressesStore.Verify(i => i.GetCustomerAddresses(It.Is<int>(customerId => customerId == CustomerId), It.Is<AddressesFilter>(addressFilter => addressFilter.Zip.Contains(ZipCode)))));
            "Then a response is received by the HTTP client".
                f(() =>
                {
                    Response.Content.ShouldNotBeNull();
                });
            "Then content should be returned".
                f(() =>
                {
                    addresses = Response.Content.ReadAsAsync<JArray>().Result;
                    addresses.ShouldNotBeNull();
                });
            "Then a '200 OK' status is returned".
                f(() => Response.StatusCode.ShouldEqual(HttpStatusCode.OK));
            "Then addresses are returned".
                f(() => addresses.Count().ShouldEqual(2));
            "Then the address references the queried customer".
                f(() => addresses.First().Value<int>("OwnerId").ShouldEqual(CustomerId));
            "Then each address references the queried zip code".
                f(() => addresses.ToList().ForEach(address => address.Value<string>("ZipCode").ShouldContain(ZipCode)));
        }
开发者ID:TheFastCat,项目名称:XunitHangRepro,代码行数:45,代码来源:RetrievingCustomerAddresses.cs

示例3: CalculateIndices

        static void CalculateIndices(JObject item, JArray interfaces, Dictionary<string, int> indices)
        {
            var key = (string)item["key"];
            if (indices.ContainsKey((string)item["key"]))
                return;

            var parent = (string)item["type"];
            if (!indices.ContainsKey(parent))
                CalculateIndices(interfaces.First(i => (string)i["key"] == parent) as JObject, interfaces, indices);

            int offset = indices[parent];
            int count = 0;

            foreach (var method in item["methods"])
            {
                int index = (int)method["index"];
                method["index"] = index + offset;
                count++;
            }

            indices.Add(key, count + offset);
        }
开发者ID:dkushner,项目名称:SlimDX,代码行数:22,代码来源:ModelXml.cs

示例4: ParseSecurityRequirements

        private static SecurityRequirement[] ParseSecurityRequirements(JArray securitySchemes)
        {
            if (securitySchemes == null)
            {
                return null;
            }

            var result = new List<SecurityRequirement>();
            foreach (JObject securityObject in securitySchemes)
            {
                var security = ((securitySchemes.First() as JObject).First as JProperty);
                var item = new SecurityRequirement
                {
                    Name = security.Name,
                    Values = (security.Value as JArray).Values<string>().ToArray()
                };

                result.Add(item);
            }

            return result.ToArray();
        }
开发者ID:rmaclean,项目名称:nSwagger,代码行数:22,代码来源:Parser.cs


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