本文整理汇总了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
}
示例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;
}
示例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;
}
示例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;
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例11: NetkanOverride
public NetkanOverride(JObject metadata)
{
this.metadata = (JObject) metadata.DeepClone();
version = new Version(metadata["version"].ToString());
}
示例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();
}
示例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);
}
示例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;
}