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


C# Linq.JProperty类代码示例

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


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

示例1: CreateCloudStackObject

        /// <summary>
        /// Associate CloudStack object's content with a fully qualified type name.
        /// </summary>
        /// <param name="objType">Fully qualified type name, e.g. "org.apache.cloudstack.storage.to.TemplateObjectTO"</param>
        /// <param name="objValue">Object's data, can be an anonymous object, e.g. </param>
        /// <returns></returns>
        public static JObject CreateCloudStackObject(string objType, object objValue)
        {
            JToken objContent = JToken.FromObject(objValue);
            JProperty objTypeValuePairing = new JProperty(objType, objContent);

            return new JObject(objTypeValuePairing);
        }
开发者ID:OrangeChan,项目名称:cshv3,代码行数:13,代码来源:Utils.cs

示例2: FormatPropertyInJson

        public void FormatPropertyInJson()
        {
            JObject query = new JObject();
            JProperty orderProp = new JProperty("order", "breadth_first");
            query.Add(orderProp);

            JObject returnFilter = new JObject();
            returnFilter.Add("body", new JValue("position.endNode().getProperty('name').toLowerCase().contains('t')"));
            returnFilter.Add("language", new JValue("javascript"));

            query.Add("return_filter", new JValue(returnFilter.ToString()));

            JObject pruneEval = new JObject();
            pruneEval.Add("body", new JValue("position.length() > 10"));
            pruneEval.Add("language", new JValue("javascript"));
            query.Add("prune_evaluator", pruneEval.ToString());

            query.Add("uniqueness", new JValue("node_global"));

            JArray relationships = new JArray();
            JObject relationShip1 = new JObject();
            relationShip1.Add("direction", new JValue("all"));
            relationShip1.Add("type", new JValue("knows"));
            relationships.Add(relationShip1);

            JObject relationShip2 = new JObject();
            relationShip2.Add("direction", new JValue("all"));
            relationShip2.Add("type", new JValue("loves"));
            relationships.Add(relationShip2);

            query.Add("relationships", relationships.ToString());
            //arr.Add(
            Console.WriteLine(query.ToString());
            //Assert.AreEqual(@"""order"" : ""breadth_first""", jobject.ToString());
        }
开发者ID:sonyarouje,项目名称:Neo4jD,代码行数:35,代码来源:DataFormatTest.cs

示例3: ModifyValue

		private void ModifyValue(PatchRequest patchCmd, string propName, JProperty property)
        {
			EnsurePreviousValueMatchCurrentValue(patchCmd, property);
            if (property == null)
                throw new InvalidOperationException("Cannot modify value from  '" + propName + "' because it was not found");

            var nestedCommands = patchCmd.Nested;
            if (nestedCommands == null)
                throw new InvalidOperationException("Cannot understand modified value from  '" + propName +
                                                    "' because could not find nested array of commands");
            
            switch (property.Value.Type)
            {
                case JTokenType.Object:
                    foreach (var cmd in nestedCommands)
                    {
                        var nestedDoc = property.Value.Value<JObject>();
						new JsonPatcher(nestedDoc).Apply(cmd);
                    }
                    break;
                case JTokenType.Array:
					var position = patchCmd.Position;
					if (position == null)
                         throw new InvalidOperationException("Cannot modify value from  '" + propName +
                                                             "' because position element does not exists or not an integer");
                    var value = property.Value.Value<JArray>()[position];
					foreach (var cmd in nestedCommands)
					{
                    	new JsonPatcher(value.Value<JObject>()).Apply(cmd);
                    }
            		break;
                default:
                    throw new InvalidOperationException("Can't understand how to deal with: " + property.Value.Type);
            }
        }
开发者ID:Inferis,项目名称:ravendb,代码行数:35,代码来源:JsonPatcher.cs

示例4: GetValue

        private static void GetValue(IDictionary<string, dynamic> foreignKeys, JProperty prop)
        {
            var array = prop.Value as JArray;
            if (array == null) return;

            foreach (var subObj in array)
            {
                var subObject = subObj as JObject;

                if (subObject != null)
                {
                    var p = subObject.Parent.Parent.Parent;
                    subObject.Add("PartitionKey", ((dynamic)p).RowKey);
                    JToken idToken;
                    if (subObject.TryGetValue("id", out idToken))
                    {
                        subObject.Add("RowKey", idToken.Value<string>());
                        subObject.Remove("id");
                    }
                    else
                    {
                        subObject.Add("RowKey", Guid.NewGuid().ToString()); // TODO UXID!
                    }

                    // "events": [{ "id": "XI1BTWMDXR6X", ... }, { "id": "OK1JAWL7WWQS", ... }]
                    foreignKeys.Add(String.Format("{0}_{1}", prop.Name, subObject.GetValue("RowKey").Value<string>()), ConvertToSimpleObject(subObject));
                }
            }
        }
开发者ID:noocyte,项目名称:DynamicAzure,代码行数:29,代码来源:JsonSubObjectsTraverser.cs

示例5: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var val = (IColorEffect) value;
            var nameProp = new JProperty("name", val.Name);

            var jobj = new JObject(nameProp);

            var objWriter = jobj.CreateWriter();
            if (value is FixedColor)
            {
                objWriter.WritePropertyName("color");
                serializer.Serialize(objWriter, ((FixedColor) val).Colors[0]);
            }
            if (value is ImageEffect)
            {
                objWriter.WritePropertyName("imageName");
                objWriter.WriteValue(((ImageEffect)value).ImageName);
                objWriter.WritePropertyName("width");
                objWriter.WriteValue(((ImageEffect)value).Width);
            }
            objWriter.WritePropertyName("colors");
            //serializer.Serialize(objWriter, ((ColorFade)val).Colors.Select(c => new JValue(c)));
            serializer.Serialize(objWriter, val.Colors);
            jobj.WriteTo(writer);
        }
开发者ID:JacquiManzi,项目名称:KineticSpectrum,代码行数:25,代码来源:ColorEffectConverter.cs

示例6: MPFormatToJson

        public static JArray MPFormatToJson(string mpFormat)
        {
            PlatformService.SelectQueryResult mpObject;

            try
            {
                mpObject = JsonConvert.DeserializeObject<PlatformService.SelectQueryResult>(mpFormat);
            }
            catch
            {
                //TO-DO: add proper error handler
                return null;
            }            

            //map the reponse into name/value pairs
            var json = new JArray();
            foreach (var dataItem in mpObject.Data)
            {
                var jObject = new JObject();
                foreach (var mpField in mpObject.Fields)
                {
                    var jProperty = new JProperty(mpField.Name, dataItem[mpField.Index]);
                    jObject.Add(jProperty);
                }
                json.Add(jObject);
            }

            return json;
        }
开发者ID:plachmann,项目名称:crds-angular,代码行数:29,代码来源:MPFormatConversion.cs

示例7: can_update_a_doc_within_transaction_scope

		public void can_update_a_doc_within_transaction_scope()
		{
			using (var documentStore = NewDocumentStore())
			{
				var id1 = Guid.NewGuid();
				JObject dummy = null;

				using (TransactionScope trnx = new TransactionScope())
				{
					using (var session = documentStore.OpenSession())
					{
						dummy = new JObject();
						var property = new JProperty("Name", "This is the object content");
						dummy.Add(property);
						dummy.Add("Id", JToken.FromObject(id1));
						session.Store(dummy);
						session.SaveChanges();

					}
					using (var session = documentStore.OpenSession())
					{
						session.Store(dummy);
						session.SaveChanges();
					}
					trnx.Complete();
				}
			}
		}
开发者ID:philiphoy,项目名称:ravendb,代码行数:28,代码来源:UsingDTCForUpdates.cs

示例8: Parse

        /// <summary>
        /// Parses the messages section of a protocol definition
        /// </summary>
        /// <param name="jmessage">messages JSON object</param>
        /// <param name="names">list of parsed names</param>
        /// <param name="encspace">enclosing namespace</param>
        /// <returns></returns>
        internal static Message Parse(JProperty jmessage, SchemaNames names, string encspace)
        {
            string name = jmessage.Name;
            string doc = JsonHelper.GetOptionalString(jmessage.Value, "doc");
            bool? oneway = JsonHelper.GetOptionalBoolean(jmessage.Value, "one-way");

            PropertyMap props = Schema.GetProperties(jmessage.Value);
            RecordSchema schema = RecordSchema.NewInstance(Schema.Type.Record, jmessage.Value as JObject, props, names, encspace);

            JToken jresponse = jmessage.Value["response"];
            var response = Schema.ParseJson(jresponse, names, encspace);

            JToken jerrors = jmessage.Value["errors"];
            UnionSchema uerrorSchema = null;
            if (null != jerrors)
            {
                Schema errorSchema = Schema.ParseJson(jerrors, names, encspace);
                if (!(errorSchema is UnionSchema))
                    throw new AvroException("");

                uerrorSchema = errorSchema as UnionSchema;
            }

            return new Message(name, doc, schema, response, uerrorSchema, oneway);
        }
开发者ID:drzo,项目名称:opensim4opencog,代码行数:32,代码来源:Message.cs

示例9: 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

示例10: SeedTable

        public void SeedTable(JProperty table)
        {
            Log.Info("Seeding table {0}", table.Name);

            var tableOps = this.sql.GetTableOperations(table.Name);

            var records = table.Value.Value<JArray>();

            foreach (JObject record in records)
            {
                var parameters = record.AsDictionary();

                var count = tableOps.CountOfRecordsWithPrimaryKey(parameters);

                if (count == 0)
                {
                    Log.Debug("Inserting new record");

                    tableOps.InsertRecord(parameters);
                }
                else
                {
                    Log.Debug("Updating existing record");

                    tableOps.UpdateRecord(parameters);
                }
            }
        }
开发者ID:sorvis,项目名称:DataSeeder,代码行数:28,代码来源:SeedCommand.cs

示例11: ToJson

        public override JObject ToJson()
        {
            if (this.Projection != null)
            {
                return this.Projection;
            }

            var doc = new JObject();
            if (this.DataAsJson != null)
            {
                doc = new JObject(this.DataAsJson); // clone the document
            }

            var metadata = new JObject();
            if (this.Metadata != null)
            {
                metadata = new JObject(this.Metadata); // clone the metadata
            }

            metadata["Last-Modified"] = JToken.FromObject(this.LastModified.ToString("r"));
            var etagProp = metadata.Property("@etag");
            if (etagProp == null)
            {
                etagProp = new JProperty("@etag");
                metadata.Add(etagProp);
            }

            etagProp.Value = new JValue(this.Etag.ToString());
            doc.Add("@metadata", metadata);
            metadata["Non-Authoritive-Information"] = JToken.FromObject(this.NonAuthoritiveInformation);
            return doc;
        }
开发者ID:andrewdavey,项目名称:ravendb,代码行数:32,代码来源:JsonDocument.cs

示例12: GetUpdateAttribute

        private static Tuple<string, YamlNode> GetUpdateAttribute(JProperty prop)
        {
            var propValueType = prop.Value.Type;
            var value = string.Empty;

            if (propValueType == JTokenType.Object || propValueType == JTokenType.Array)
            {
                if (propValueType == JTokenType.Array)
                {
                    var nodes = new YamlSequenceNode();
                    foreach(var item in prop.Value as JArray)
                    {
                        var asset = new Asset(item as dynamic);
                        var yamlNode = GetNodes(asset);
                        nodes.Add(yamlNode);
                    }
                    return new Tuple<string, YamlNode>(prop.Name, nodes);
                }

                return new Tuple<string, YamlNode>(prop.Name, new YamlScalarNode(string.Empty));
            }
            else
            {
                value = (prop.Value as JValue).Value.ToString();
                return new Tuple<string, YamlNode>(prop.Name, new YamlScalarNode(value));
            }
        }
开发者ID:JogoShugh,项目名称:VersionOneRestSharpClient,代码行数:27,代码来源:QueryYamlPayloadBuilder.cs

示例13: AddAtPath

 /// <summary>
 /// Add a new property to the JObject at a given property path
 /// </summary>
 /// <param name="jo">the source object</param>
 /// <param name="path">the property path</param>
 /// <param name="property">the property to add at the path</param>
 public static void AddAtPath(this JObject jo, string path, JProperty property)
 {
     JObject leafParent = jo;
     if (path.Contains("."))
     {
         string[] leafParents = path.UpToLast(".").Split('.');
         foreach (string propName in leafParents)
         {
             JToken child = leafParent[propName];
             if (child is JValue)
             {
                 leafParent.Remove(propName);
                 child = null;
             }
             if (child == null)
             {
                 child = new JObject();
                 leafParent.Add(propName, child);
             }
             leafParent = child as JObject;
         }
     }
     string leafProperty = path.Contains(".") ? path.LastAfter(".") : path;
     leafParent.Add(leafProperty, property.Value);
 }
开发者ID:jamesej,项目名称:lynicon,代码行数:31,代码来源:JsonX.cs

示例14: JsonXPathNavigator

        public JsonXPathNavigator(JsonReader reader)
        {
            reader.DateParseHandling = DateParseHandling.None;
            reader.FloatParseHandling = FloatParseHandling.Decimal;

            try
            {
                var docChild = (JObject)JObject.Load(reader);

                // Add symbolic 'root' child, so initially, we are at a virtual "root" element, just like in the DOM model
                var root = new JProperty(ROOT_PROP_NAME, docChild);
                _state.Push(new NavigatorState(root));
            }
            catch (Exception e)
            {
                throw new FormatException("Cannot parse json: " + e.Message);
            }

            _nameTable.Add(FHIR_NS);
            _nameTable.Add(XHTML_NS);
            _nameTable.Add(XML_NS);
            _nameTable.Add(String.Empty);
            _nameTable.Add(FHIR_PREFIX);
            _nameTable.Add(XML_PREFIX);
            _nameTable.Add(XHTML_PREFIX);
            _nameTable.Add(SPEC_CHILD_VALUE);
        }
开发者ID:wdebeau1,项目名称:fhir-net-api,代码行数:27,代码来源:JsonXPathNavigator.cs

示例15: IListCount

    public void IListCount()
    {
      JProperty p = new JProperty("TestProperty", null);
      IList l = p;

      Assert.AreEqual(1, l.Count);
    }
开发者ID:WimVergouwe,项目名称:ravendb,代码行数:7,代码来源:JPropertyTests.cs


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