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


C# JObject.Remove方法代码示例

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


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

示例1: CreateResource

        static IResource CreateResource(JObject jObj, Type resourceType)
        {
            // remove _links and _embedded so those don't try to deserialize, because we know they will fail
            JToken links;
            if (jObj.TryGetValue(HalLinksName, out links))
                jObj.Remove(HalLinksName);
            JToken embeddeds;
            if (jObj.TryGetValue(HalEmbeddedName, out embeddeds))
                jObj.Remove(HalEmbeddedName);

            // create value properties in base object
            var resource = jObj.ToObject(resourceType) as IResource;
            if (resource == null) return null;

            // links are named properties, where the name is Link.Rel and the value is the rest of Link
            if (links != null)
            {
                foreach (var rel in links.OfType<JProperty>())
                    CreateLinks(rel, resource);
                var self = resource.Links.SingleOrDefault(l => l.Rel == "self");
                if (self != null)
                    resource.Href = self.Href;
            }

            // embedded are named properties, where the name is the Rel, which needs to map to a Resource Type, and the value is the Resource
            // recursive
            if (embeddeds != null)
            {
                foreach (var prop in resourceType.GetProperties().Where(p => Representation.IsEmbeddedResourceType(p.PropertyType)))
                {
                    // expects embedded collection of resources is implemented as an IList on the Representation-derived class
                    if (typeof (IEnumerable<IResource>).IsAssignableFrom(prop.PropertyType))
                    {
                        var lst = prop.GetValue(resource) as IList;
                        if (lst == null)
                        {
                            lst = ConstructResource(prop.PropertyType) as IList ??
                                  Activator.CreateInstance(
                                      typeof (List<>).MakeGenericType(prop.PropertyType.GenericTypeArguments)) as IList;
                            if (lst == null) continue;
                            prop.SetValue(resource, lst);
                        }
                        if (prop.PropertyType.GenericTypeArguments != null &&
                            prop.PropertyType.GenericTypeArguments.Length > 0)
                            CreateEmbedded(embeddeds, prop.PropertyType.GenericTypeArguments[0],
                                newRes => lst.Add(newRes));
                    }
                    else
                    {
                        var prop1 = prop;
                        CreateEmbedded(embeddeds, prop.PropertyType, newRes => prop1.SetValue(resource, newRes));
                    }
                }
            }

            return resource;
        }
开发者ID:iremezoff,项目名称:AspNet.Hal,代码行数:57,代码来源:ResourceConverter.cs

示例2: Remove

    public void Remove()
    {
      JObject o = new JObject();
      o.Add("PropertyNameValue", new JValue(1));
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(false, o.Remove("sdf"));
      Assert.AreEqual(false, o.Remove(null));
      Assert.AreEqual(true, o.Remove("PropertyNameValue"));

      Assert.AreEqual(0, o.Children().Count());
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:12,代码来源:JObjectTests.cs

示例3: Post

        public JObject Post(int userId, JObject json)
        {
            var user = DataContext.User.Get(userId);
            if (user == null)
                ThrowHttpResponse(HttpStatusCode.NotFound, "User not found!");

            var jsonClient = json["client"] as JObject;
            if (jsonClient == null)
                ThrowHttpResponse(HttpStatusCode.BadRequest, "The 'client' field is required!");
            json.Remove("client");

            var oauthGrant = Mapper.Map(json);
            oauthGrant.UserID = user.ID;
            oauthGrant.Client = MapClient(jsonClient);
            if (string.IsNullOrEmpty(oauthGrant.RedirectUri))
                ThrowHttpResponse(HttpStatusCode.BadRequest, "Missing required field: redirectUri");

            OAuth2Controller.RenewGrant(oauthGrant);
            Validate(oauthGrant);

            DataContext.AccessKey.Save(oauthGrant.AccessKey);
            DataContext.OAuthGrant.Save(oauthGrant);

            if (oauthGrant.Type == (int)OAuthGrantType.Code)
                oauthGrant.AccessKey = null; // do not disclose key in authorization code scenario

            return Mapper.Map(oauthGrant, oneWayOnly: true);
        }
开发者ID:bestpetrovich,项目名称:devicehive-.net,代码行数:28,代码来源:OAuthGrantController.cs

示例4: OnPut

        public override void OnPut(string key, JObject document, JObject metadata, TransactionInformation transactionInformation)
        {
			if (VersioningContext.IsInVersioningContext)
				return;
			if (key.StartsWith("Raven/", StringComparison.InvariantCultureIgnoreCase))
				return;

			if (excludeByEntityName.Contains(metadata.Value<string>("Raven-Entity-Name")))
				return;

			if (metadata.Value<string>(RavenDocumentRevisionStatus) == "Historical")
				return;

			using(VersioningContext.Enter())
			{
				var copyMetadata = new JObject(metadata);
				copyMetadata[RavenDocumentRevisionStatus] = JToken.FromObject("Historical");
				copyMetadata.Remove(RavenDocumentRevision);
				var parentRevision = metadata.Value<string>(RavenDocumentRevision);
				if(parentRevision!=null)
				{
					copyMetadata[RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
					metadata[RavenDocumentParentRevision] = key + "/revisions/" + parentRevision;
				}

				PutResult newDoc = Database.Put(key + "/revisions/", null, document, copyMetadata,
											 transactionInformation);
				int revision = int.Parse(newDoc.Key.Split('/').Last());

				RemoveOldRevisions(key, revision, transactionInformation);

				metadata[RavenDocumentRevisionStatus] = JToken.FromObject("Current");
				metadata[RavenDocumentRevision] = JToken.FromObject(revision);
			}
        }
开发者ID:ajaishankar,项目名称:ravendb,代码行数:35,代码来源:VersioningPutTrigger.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: PostFormat

        /// <summary>
        /// Removes the standard non configurable properties.
        /// </summary>
        public JObject PostFormat(JObject json, object value, Type type)
        {
            if (json == null)
                throw new ArgumentNullException(nameof(json));
            if (value == null)
                throw new ArgumentNullException(nameof(value));
            if (type == null)
                throw new ArgumentNullException(nameof(type));

            if (value is IIdentifier)
                json.Remove("id");

            if (value is IModified)
                json.Remove(new[] { "created_on", "modified_on" });

            return json;
        }
开发者ID:isbtech,项目名称:CloudFlare.NET,代码行数:20,代码来源:StandardNonconfigurablePropertyFormatter.cs

示例7: setAutoComplite

 private void setAutoComplite()
 {
     JObject joContextKey = new JObject();
     joContextKey["SearchCode"] = "1";
     this.AutoComplit(ref joContextKey, "~/Tools/LandUse.asmx/GetCompletionList", this.txtFirst);
     joContextKey.Remove("SearchCode");
     joContextKey["SearchParams"] = new JRaw("function () {return UpdateContext();}");
     this.AutoComplit(ref joContextKey, "~/Tools/LandUse.asmx/GetCompletionList2", this.txtSecond);
 }
开发者ID:ranyaof,项目名称:gismaster,代码行数:9,代码来源:Default2.aspx.cs

示例8: MigrateContent

        bool MigrateContent(JObject x)
        {
            if (x["Content"] is JObject)
            {
                // already converted
                return false;
            }

            var content = new Content();
            content.Title = x.Value<string>("Title");
            content.Body = x.Value<string>("Content");
            content.Format = (ContentFormat)x.Value<int>("Format");
            x.Remove("Title");
            x.Remove("Content");
            x.Remove("Format");
            x["Content"] = Session.Serializer.WriteFragment(content);
            return true;
        }
开发者ID:nicknystrom,项目名称:AscendRewards,代码行数:18,代码来源:MigrateFrom0000.cs

示例9: RemoveCreatesNewJObjectWithPropertiesRemoved

        public void RemoveCreatesNewJObjectWithPropertiesRemoved()
        {
            JObject obj = new JObject() { { "prop1", "value1" }, { "prop2", "value2" } };
            JObject obj2 = obj.Remove(prop => prop.Name.Equals("prop1"));

            Assert.AreNotSame(obj, obj2);
            Assert.IsTrue(((IDictionary<string,JToken>)obj2).ContainsKey("prop2"));
            Assert.IsFalse(((IDictionary<string,JToken>)obj2).ContainsKey("prop1"));
        }
开发者ID:jlaanstra,项目名称:azure-mobile-services,代码行数:9,代码来源:JObjectExtensionsTest.cs

示例10: FotoliaGetSearchResult

 public FotoliaGetSearchResult(JObject searchResultData)
 {
     Items = new List<FotoliaSearchResultItem>();
     TotalCount = searchResultData["nb_results"].ToObject<int>();
     searchResultData.Remove("nb_results");
     foreach (var item in searchResultData)
     {
         Items.Add(new FotoliaSearchResultItem(item));
     }
 }
开发者ID:vmaron,项目名称:FotoliaSharp,代码行数:10,代码来源:FotoliaGetSearchResult.cs

示例11: Strip

        private static void Strip(JObject metadata)
        {
            var propertiesToRemove = new List<string>();

            foreach (var property in metadata.Properties())
            {
                if (property.Name.StartsWith("x_netkan"))
                {
                    propertiesToRemove.Add(property.Name);
                }
                else switch (property.Value.Type)
                {
                    case JTokenType.Object:
                        Strip((JObject)property.Value);
                        break;
                    case JTokenType.Array:
                        foreach (var element in ((JArray)property.Value).Where(i => i.Type == JTokenType.Object))
                        {
                            Strip((JObject)element);
                        }
                        break;
                }
            }

            foreach (var property in propertiesToRemove)
            {
                metadata.Remove(property);
            }

            if (metadata["$kref"] != null)
            {
                metadata.Remove("$kref");
            }

            if (metadata["$vref"] != null)
            {
                metadata.Remove("$vref");
            }
        }
开发者ID:CliftonMarien,项目名称:CKAN,代码行数:39,代码来源:StripNetkanMetadataTransformer.cs

示例12: ParseSearchResult

        /// <summary>
        /// This method parses the search result because device's local DB can only handle strings shorter than 4000 characters.
        /// </summary>
        private void ParseSearchResult(JObject resultObj)
        {
            int removableItemIndex = 0;

            while (resultObj.ToString(Newtonsoft.Json.Formatting.None).Length > searchResultMaxLength)
            {
                resultObj.Remove(searchResultRemovableItems[removableItemIndex]);
                if (removableItemIndex < searchResultRemovableItems.Length)
                    removableItemIndex++;
                else
                    break;
            }
        }
开发者ID:WinToosa,项目名称:mobilelogger,代码行数:16,代码来源:SearchDataHandler.cs

示例13: MergeTemplateStart

 private void MergeTemplateStart(JObject iTarget, JObject iTemplate, string iKnxReplace) {
     //evaluate template
     JProperty lTemplate = iTarget.Property("$template");
     //string lOldKnxReplace = "";
     if (lTemplate != null) {
         //JProperty lKnx = (lTemplate.Value as JObject).Property("knx");
         //if (lKnx != null) {
         //    lOldKnxReplace = gKnxReplace;
         //    gKnxReplace = lKnx.Value.ToString();
         //}
         JObject lTemplateObject = iTemplate.Properties().Last().Value as JObject;
         iTarget.Remove("$template");
         MergeTemplate(iTarget, lTemplateObject, iKnxReplace);
         //if (lKnx != null && lOldKnxReplace != "-/-/-") gKnxReplace = lOldKnxReplace;
     }
 }
开发者ID:ivan73,项目名称:json,代码行数:16,代码来源:MergeTemplate.cs

示例14: MoveExtraExceptionProperties

        private void MoveExtraExceptionProperties(JObject doc, JObject extendedData = null) {
            if (doc == null)
                return;

            if (extendedData == null)
                extendedData = doc["Data"] as JObject;

            string json = extendedData != null && extendedData["__ExceptionInfo"] != null ? extendedData["__ExceptionInfo"].ToString() : null;
            if (String.IsNullOrEmpty(json))
                return;

            try {
                var extraProperties = JObject.Parse(json);
                foreach (var property in extraProperties.Properties())
                    doc.Add(property.Name, property.Value);
            } catch (Exception) {}

            extendedData.Remove("__ExceptionInfo");
        }
开发者ID:BookSwapSteve,项目名称:Exceptionless,代码行数:19,代码来源:V2_EventUpgrade.cs

示例15: Sort

        private static void Sort(JObject jObject)
        {
            var props = jObject.Properties().ToList();

            foreach (var prop in props)
            {
                jObject.Remove(prop.Name);
            }

            foreach (var prop in props.OrderBy(p => p.Name))
            {
                jObject.Add(prop);

                if (prop.Value is JObject)
                {
                    Sort((JObject) prop.Value);
                }
            }
        }
开发者ID:borealwinter,项目名称:simpl,代码行数:19,代码来源:JsonHelper.cs


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