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


C# JObject.DeepClone方法代码示例

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


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

示例1: Example

    public void Example()
    {
      JObject o1 = new JObject
        {
          {"String", "A string!"},
          {"Items", new JArray(1, 2)}
        };

      Console.WriteLine(o1.ToString());
      // {
      //   "String": "A string!",
      //   "Items": [
      //     1,
      //     2
      //   ]
      // }

      JObject o2 = (JObject) o1.DeepClone();

      Console.WriteLine(o2.ToString());
      // {
      //   "String": "A string!",
      //   "Items": [
      //     1,
      //     2
      //   ]
      // }

      Console.WriteLine(JToken.DeepEquals(o1, o2));
      // true

      Console.WriteLine(Object.ReferenceEquals(o1, o2));
      // false
    }
开发者ID:che3tah7,项目名称:Newtonsoft.Json,代码行数:34,代码来源:Clone.cs

示例2: Interpolate

		public JObject Interpolate(List<CallbackParameter> paras, JArray args, JObject scope)
		{
			var nscope = scope.DeepClone() as JObject;
			for (var i = 0; i < paras.Count(); i++)
			{
				nscope[paras[i].Name] = args[i];
			}
			return nscope;
		}
开发者ID:danielwerthen,项目名称:Funcis-Sharp,代码行数:9,代码来源:Signal.cs

示例3: InsertAsync

        public async Task<JObject> InsertAsync(JObject instance)
        {
            object id = MobileServiceSerializer.GetId(instance, ignoreCase: false, allowDefault: true);
            if (id == null)
            {
                id = Guid.NewGuid().ToString();
                instance = (JObject)instance.DeepClone();
                instance[MobileServiceSystemColumns.Id] = (string)id;
            }
            else
            {
                EnsureIdIsString(id);
            }

            await this.syncContext.InsertAsync(this.TableName, this.Kind, (string)id, instance);

            return instance;
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:18,代码来源:MobileServiceSyncTable.cs

示例4: IterateAndFuzz

        private static void IterateAndFuzz(string url, JObject obj)
        {
            foreach (var pair in (JObject)obj.DeepClone()) {
                if (pair.Value.Type == JTokenType.String || pair.Value.Type == JTokenType.Integer) {
                    Console.WriteLine("Fuzzing key: " + pair.Key);

                    if (pair.Value.Type == JTokenType.Integer)
                        Console.WriteLine ("Converting int type to string to fuzz");

                    JToken oldVal = pair.Value;
                    obj[pair.Key] = pair.Value.ToString() + "'";

                    if (Fuzz (url, obj.Root))
                        Console.WriteLine ("SQL injection vector: " + pair.Key);
                    else
                        Console.WriteLine (pair.Key + " does not seem vulnerable.");

                    obj[pair.Key] = oldVal;
                }
            }
        }
开发者ID:Nusec,项目名称:gray_hat_csharp_code,代码行数:21,代码来源:Program.cs

示例5: ExtractObjectJson

 private JObject ExtractObjectJson(JObject json)
 {
     var clone = json.DeepClone() as JObject;
     var properties = clone.Properties().ToArray();
     for (int i = 0; i < properties.Length; i++)
     {
         if( IsObjectProperty(properties[i].Name) == false )
             clone.Remove(properties[i].Name);
     }
     return clone;
 }
开发者ID:ytokas,项目名称:appacitive-dotnet-sdk,代码行数:11,代码来源:FindConnectedObjectsResponseConverter.cs

示例6: GetByTopic

        public HttpResponseMessage GetByTopic(string topic)
        {
            var topicPath = string.Empty;

            try
            {
                if (string.IsNullOrWhiteSpace(topic))
                {
                    throw new ArgumentNullException("Please specify a valid topic parameter in the form of /sample/<topic>.");
                }
                topicPath = HostingEnvironment.MapPath("~/" + topic);
                if (!Directory.Exists(topicPath))
                {
                    throw new FileNotFoundException("Could not find a topic named: " + topic);
                }
            }
            catch (ArgumentNullException ex)
            {
                return CreateErrorResponse(ex);
            }
            catch (FileNotFoundException ex)
            {
                return CreateErrorResponse(ex);
            }

            var directories = new DirectoryInfo(topicPath);
            var jArray = new JArray();

            foreach (var langDir in directories.GetDirectories())
            {
                var examples = new JArray();
                var files = langDir.GetFiles();
                var exampleFiles = files.Where(f => f.Extension != ".json");
                var rootObject = new JObject();
                rootObject["mode"] = langDir.Name;
                rootObject["content"] = string.Empty;
                rootObject["id"] = langDir.Name;
                var filePathRoot = "https://v1codesamples.azurewebsites.net/api/sample?path=" + topic + "/" + langDir.Name + "/";

                foreach (var file in exampleFiles)
                {
                    var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file.Name);
                    var properties = files.First(f => f.Name == fileNameWithoutExtension + ".json");
                    using (var reader = new StreamReader(properties.OpenRead()))
                    {
                        var json = reader.ReadToEnd();
                        var exampleRoot = rootObject.DeepClone() as JObject;
                        var mergeWith = JObject.Parse(json);
                        var example = new JObject(exampleRoot.Concat(mergeWith.AsJEnumerable()));
                        example["url"] = filePathRoot + file.Name;
                        // TODO: multiple examples per language support
                        //examples.Add(example);
                        jArray.Add(example);
                    }
                }
                // TODO: support multiple examples
                //jArray.Add(examples);
            }

            var content = jArray.ToString();

            var resp = new HttpResponseMessage(HttpStatusCode.OK);
            resp.Content = new StringContent(content, Encoding.UTF8, "text/plain");
            return resp;

        }
开发者ID:versionone,项目名称:CommunitySite.CodeSamples,代码行数:66,代码来源:SampleController.cs

示例7: MakePackageDetailsContent

        static JObject MakePackageDetailsContent(JObject package, IDictionary<int, JObject> packageDependencies, IDictionary<int, JObject> packageFrameworks, IDictionary<int, IList<int>> dependenciesByPackage, IDictionary<int, IList<int>> frameworksByPackage)
        {
            int packageKey = package.Value<int>("Key");

            package = (JObject)package.DeepClone();
            package.Remove("Key");
            package.Remove("PackageRegistrationKey");
            package.Remove("UserKey");

            JToken depenedencies = MakeDependencies(packageDependencies, dependenciesByPackage, packageKey);
            if (depenedencies != null)
            {
                package.Add("dependencies", depenedencies);
            }

            IList<int> frameworkKeys;
            if (frameworksByPackage.TryGetValue(packageKey, out frameworkKeys))
            {
                JArray frameworks = new JArray();
                foreach (int frameworkKey in frameworkKeys)
                {
                    JObject framework = (JObject)packageFrameworks[frameworkKey].DeepClone();
                    framework.Remove("Key");
                    framework.Remove("Package_Key");
                    frameworks.Add(framework);
                }
                package.Add("frameworks", frameworks);
            }

            return package;
        }
开发者ID:johnataylor,项目名称:render,代码行数:31,代码来源:Program.cs

示例8: MakeOwnerContent

        static JObject MakeOwnerContent(JObject user, IDictionary<int, JObject> packageRegistrations, IList<int> registrationsByOwner)
        {
            JObject owner = (JObject)user.DeepClone();

            owner.Remove("Key");

            owner.Add("@context", MakeOwnerContextUri());

            JArray registrations = new JArray();
            foreach (int packageRegistrationKey in registrationsByOwner)
            {
                JObject packageRegistration = packageRegistrations[packageRegistrationKey];

                JObject registration = new JObject();
                registration.Add("Id", packageRegistration["Id"]);
                registration.Add("Uri", MakePackageRegistrationUri(packageRegistration));
                registrations.Add(registration);
            }

            owner.Add("Packages", registrations);

            return owner;
        }
开发者ID:johnataylor,项目名称:render,代码行数:23,代码来源:Program.cs

示例9: NewCommand

        public void NewCommand(JObject newCommand)
        {
            JObject command = (JObject)newCommand.DeepClone();

            String json = command.ToString();
            String deviceId = command.GetValue("deviceId").ToString();

            using (IModel channel = connection.CreateModel())
            {
                channel.ExchangeDeclare("ex" + deviceId, ExchangeType.Direct);
                channel.QueueDeclare(deviceId, false, false, false, null);
                channel.QueueBind(deviceId, "ex" + deviceId, "", null);

                IBasicProperties props = channel.CreateBasicProperties();
                props.DeliveryMode = 2;

                Byte[] body = Encoding.UTF8.GetBytes(json);
                channel.BasicPublish("ex" + deviceId, "", props, body);
            }
        }
开发者ID:zheltoukhovyury,项目名称:GitDSR,代码行数:20,代码来源:Context.cs

示例10: IsDefinitionContentSubsetEquivalent

        /// <summary>
        /// Validates that definition1 is a content equivalent subset of definition2
        /// </summary>
        private static bool IsDefinitionContentSubsetEquivalent(JObject definition1, JObject definition2)
        {
            JObject clonedDefinition1 = (JObject)definition1.DeepClone();
            JObject clonedDefinition2 = (JObject)definition2.DeepClone();

            RemoveIdentifiableInformation(clonedDefinition1, clonedDefinition2);

            // Compare only the child tokens present in the first definition to the corresponding contents of the second definition
            // The second definition may contain additional tokens which we don't care about.
            foreach(var childToken in clonedDefinition1.Children())
            {
                if(!JToken.DeepEquals(childToken.First, clonedDefinition2[childToken.Path]))
                {
                    return false;
                }
            }
            return true;
        }
开发者ID:roncain,项目名称:buildtools,代码行数:21,代码来源:VstsBuildClient.cs

示例11: NetkanOverride

 public NetkanOverride(JObject metadata)
 {
     this.metadata = (JObject) metadata.DeepClone();
     version = new Version(metadata["version"].ToString());
 }
开发者ID:dexen,项目名称:CKAN,代码行数:5,代码来源:NetkanOverride.cs

示例12: Initialize

        /// <summary>
        /// 初始化游戏规则数据
        /// </summary>
        /// <param name="data">游戏规则数据</param>
        protected virtual void Initialize( GameRulesBase rules, JObject data )
        {
            if ( data == null )
            throw new ArgumentNullException( "data" );

              Guid = (Guid) data.GuidValue( "ID" );
              Data = (JObject) data.DeepClone();
        }
开发者ID:Ivony,项目名称:HelloWorld,代码行数:12,代码来源:GameRuleItem.cs

示例13: SENDLOCATION

		async static void SENDLOCATION(JObject postData){
			var postitionData = (JObject) postData.DeepClone ();
			var position = await CrossGeolocator.Current.GetPositionAsync ();

			postitionData ["latit"] = position.Latitude;
			postitionData ["longit"] = position.Longitude;

			RestCall.POST (URLs.LOCATION, postitionData);

		}
开发者ID:r0345,项目名称:EIMA,代码行数:10,代码来源:DataNetworkCalls.cs

示例14: RemoveSystemProperties

        /// <summary>
        /// Removes all system properties (name start with '__') from the instance
        /// if the instance is determined to have a string id and therefore be for table that
        /// supports system properties.
        /// </summary>
        /// <param name="instance">The instance to remove the system properties from.</param>
        /// <param name="version">Set to the value of the version system property before it is removed.</param>
        /// <returns>
        /// The instance with the system properties removed.
        /// </returns>
        protected static JObject RemoveSystemProperties(JObject instance, out string version)
        {
            version = null;

            bool haveCloned = false;
            foreach (JProperty property in instance.Properties())
            {
                if (property.Name.StartsWith(MobileServiceSerializer.SystemPropertyPrefix))
                {
                    // We don't want to alter the original jtoken passed in by the caller
                    // so if we find a system property to remove, we have to clone first
                    if (!haveCloned)
                    {
                        instance = instance.DeepClone() as JObject;
                        haveCloned = true;
                    }

                    if (String.Equals(property.Name, MobileServiceSerializer.VersionSystemPropertyString, StringComparison.OrdinalIgnoreCase))
                    {
                        version = (string)instance[property.Name];
                    }

                    instance.Remove(property.Name);
                }
            }

            return instance;
        }
开发者ID:jcookems,项目名称:azure-mobile-services,代码行数:38,代码来源:MobileServiceTable.cs


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