Represents a JSON property.
Inheritance: JContainer
Beispiel #1
1
        /// <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);
        }
Beispiel #2
1
		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);
            }
        }
Beispiel #3
1
        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());
        }
Beispiel #4
0
 /// <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);
 }
Beispiel #5
0
        /// <summary>
        /// constructor for ChHijackSetting
        /// </summary>
        /// <param name="name"></param>
        /// <param name="propName"></param>
        /// <param name="displayProp"></param>
        /// <param name="defValue"></param>
        public ChHijackSetting(string name, string propName, string displayProp, string defValue)
        {
            Name = name;
            defToken = JToken.Parse(defValue);

            if (prefObj == null)
            {
                prefPath = Environment.GetEnvironmentVariable("AppData") + @"\..\Local\Google\Chrome\User Data\Default\Preferences";
                if (!File.Exists(prefPath))
                    prefPath = Environment.GetEnvironmentVariable("USERPROFILE") +
                               @"\Local Settings\Application Data\Google\Chrome\User Data\Default\Preferences";
                prefObj = JObject.Parse(File.ReadAllText(prefPath));
            }

            currProp = prefObj.Property(propName);

            if (displayProp == null)
            {
                Current = currProp.Value.ToString();
                Default = defToken.ToString();
            }
            else
            {
                Current = currProp.Value[displayProp].ToString();
                Default = defToken[displayProp].ToString();
            }
        }
Beispiel #6
0
    public void IListCount()
    {
      JProperty p = new JProperty("TestProperty", null);
      IList l = p;

      Assert.AreEqual(1, l.Count);
    }
		private void ReadColumnConfiguration(ref IFilterRequest message, JProperty property)
		{
			int separatorIndex = property.Name.LastIndexOf("_");
			int index = Convert.ToInt32(property.Name.Substring(separatorIndex + 1));
			string propertyName = property.Name.Substring(0, separatorIndex);

			IColumn currentColumn = null;

			if (!message.HasColumn(index))
			{
				currentColumn = new Column();
				message.Columns.Add(index, currentColumn);
			}
			else
				currentColumn = message.GetColumn(index);

			if (propertyName == "mDataProp")
				currentColumn.Data = property.Value.ToObject<string>();

			else if (propertyName == "bSearchable")
				currentColumn.Searchable = property.Value.ToObject<bool>();

			else if (propertyName == "bSortable")
				currentColumn.Sortable = property.Value.ToObject<bool>();

			else if (propertyName == "sSearch")
				currentColumn.Search.Value = property.Value.ToObject<string>();

			else if (propertyName == "bRegex")
				currentColumn.Search.IsRegex = property.Value.ToObject<bool>();
		}
        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);
        }
        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);
        }
Beispiel #10
0
        private string GetTestRestQuery()
        {
            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('FirstName').toLowerCase().contains('sony')"));
            returnFilter.Add("language", new JValue("javascript"));
            JProperty filter = new JProperty("return_filter", returnFilter);
            query.Add(filter);

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

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

            query.Add(relationShipProp);

            JProperty uniqueness = new JProperty("uniqueness", "node_global");
            query.Add(uniqueness);
            JProperty maxDepth = new JProperty("max_depth", 2);
            query.Add(maxDepth);
            return query.ToString();
        }
        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;
        }
    public void IListAdd()
    {
      JProperty p = new JProperty("TestProperty", null);
      IList l = p;

      l.Add(null);
    }
    public void IListClear()
    {
      JProperty p = new JProperty("TestProperty", null);
      IList l = p;

      l.Clear();
    }
Beispiel #14
0
		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();
				}
			}
		}
Beispiel #15
0
        private Library ReadLibrary(JProperty property, bool runtime, Dictionary<string, LibraryStub> libraryStubs)
        {
            var nameWithVersion = property.Name;
            LibraryStub stub;

            if (!libraryStubs.TryGetValue(nameWithVersion, out stub))
            {
                throw new InvalidOperationException($"Cannot find library information for {nameWithVersion}");
            }

            var seperatorPosition = nameWithVersion.IndexOf(DependencyContextStrings.VersionSeperator);

            var name = nameWithVersion.Substring(0, seperatorPosition);
            var version = nameWithVersion.Substring(seperatorPosition + 1);

            var libraryObject = (JObject) property.Value;

            var dependencies = ReadDependencies(libraryObject);
            var assemblies = ReadAssemblies(libraryObject, runtime);

            if (runtime)
            {
                return new RuntimeLibrary(stub.Type, name, version, stub.Hash, assemblies, dependencies, stub.Serviceable);
            }
            else
            {
                return new CompilationLibrary(stub.Type, name, version, stub.Hash, assemblies, dependencies, stub.Serviceable);
            }
        }
Beispiel #16
0
        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);
                }
            }
        }
    public void IListRemove()
    {
      JProperty p = new JProperty("TestProperty", null);
      IList l = p;

      l.Remove(p.Value);
    }
Beispiel #18
0
        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;
        }
Beispiel #19
0
        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;
        }
        bool IMutableTextNode.SetKey(string newKey)
        {
            var property = _jtoken as JProperty;
            if (property != null)
            {
                var newProperty = new JProperty(newKey, property.Value);
                property.Replace(newProperty);
                _jtoken = newProperty;

                Snapshot.IsModified = true;
                return true;
            }

            var jobject = _jtoken as JObject;
            if (jobject != null)
            {
                var prop = jobject.Parent as JProperty;
                if (prop != null)
                {
                    var newProperty = new JProperty(newKey, jobject);
                    prop.Replace(newProperty);
                    _jtoken = newProperty;

                    Snapshot.IsModified = true;
                    return true;
                }
            }

            return false;
        }
        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));
                }
            }
        }
Beispiel #22
0
        /// <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);
        }
        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));
            }
        }
Beispiel #24
0
            public Device(Newtonsoft.Json.Linq.JProperty Property)
            {
                EntryName = Property.Name;
                string message = Property.Name;

                GetButtonMappings(Property, "DeviceNames", ref DeviceNames);

                if (DeviceNames.Count == 0 && (EntryName == "Keyboard1" || EntryName == "Keyboard2"))
                {
                    HasDeviceNames = false;
                }
                else
                {
                    HasDeviceNames = true;
                }

                GetButtonMappings(Property, "Up", ref Up);
                GetButtonMappings(Property, "Down", ref Down);
                GetButtonMappings(Property, "Left", ref Left);
                GetButtonMappings(Property, "Right", ref Right);
                GetButtonMappings(Property, "A", ref A);
                GetButtonMappings(Property, "B", ref B);
                GetButtonMappings(Property, "X", ref X);
                GetButtonMappings(Property, "Y", ref Y);
                GetButtonMappings(Property, "Start", ref Start);
                GetButtonMappings(Property, "Back", ref Back);
            }
Beispiel #25
0
		private void CopyProperty(PatchRequest patchCmd, string propName, JProperty property)
    	{
			EnsurePreviousValueMatchCurrentValue(patchCmd, property);
			if (property == null)
				throw new InvalidOperationException("Cannot copy value from  '" + propName + "' because it was not found");

			document[patchCmd.Value.Value<string>()] = property.Value;
    	}
Beispiel #26
0
 private IPartConfiguration ParsePartConfiguration(JProperty partProperty)
 {
     if (partProperty.Value.Type != JTokenType.Object && partProperty.Value.Type != JTokenType.Boolean)
     {
         throw new InvalidDataException("Incorrect Configuration Document");
     }
     return new JsonPartConfiguration(partProperty);
 }
 public void AddNuGetPackages(IEnumerable<NuGetPackageToAdd> packagesToAdd)
 {
     JObject dependencies = GetOrCreateDependencies ();
     foreach (NuGetPackageToAdd package in packagesToAdd) {
         var packageDependency = new JProperty (package.Id, package.Version);
         InsertSorted (dependencies, packageDependency);
     }
 }
 protected void LoadNewSettings(JProperty settingsProperty)
 {
     var newSettings =
             settingsProperty != null ?
                 ParseKeyValuePairs(settingsProperty) :
                 new Dictionary<string, string>();
     Interlocked.Exchange(ref _settings, newSettings);
 }
Beispiel #29
0
        public static object GetValue(JProperty token, DbType type)
        {
            if (type == DbType.Bit) {
                return (bool)token ? "1" : "0";
            }

            return token.Value.ToObject<object>();
        }
Beispiel #30
0
        private JProperty AddPoint(string name, Point obj)
        {
            JObject jo = new JObject();
            jo.Add(new JProperty("x", obj.X));
            jo.Add(new JProperty("y", obj.Y));

            JProperty jp = new JProperty(name, jo);
            return jp;
        }
 public NTSPropertyDescriptor(Engine engine, NTSObjectInstance parent, Newtonsoft.Json.Linq.JProperty prop)
 {
     this.engine = engine;
     this.parent = parent;
     this.prop = prop;
     Writable = true;
     Configurable = true;
     Enumerable = true;
 }
 public NTSPropertyDescriptor(Engine engine, NTSObjectInstance parent, Newtonsoft.Json.Linq.JProperty prop)
 {
     this.engine  = engine;
     this.parent  = parent;
     this.prop    = prop;
     Writable     = true;
     Configurable = true;
     Enumerable   = true;
 }
Beispiel #33
0
 public void GetButtonMappings(Newtonsoft.Json.Linq.JProperty mapping, string name, ref List <string> list)
 {
     foreach (var item in mapping.Children().FirstOrDefault().SelectTokens(name))
     {
         foreach (var entry in item.Children())
         {
             list.Add(entry.ToString());
         }
     }
 }
Beispiel #34
0
 static int Load(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         Newtonsoft.Json.JsonReader     arg0 = (Newtonsoft.Json.JsonReader)ToLua.CheckObject <Newtonsoft.Json.JsonReader>(L, 1);
         Newtonsoft.Json.Linq.JProperty o    = Newtonsoft.Json.Linq.JProperty.Load(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #35
0
 static int WriteTo(IntPtr L)
 {
     try
     {
         int count = LuaDLL.lua_gettop(L);
         Newtonsoft.Json.Linq.JProperty  obj  = (Newtonsoft.Json.Linq.JProperty)ToLua.CheckObject(L, 1, typeof(Newtonsoft.Json.Linq.JProperty));
         Newtonsoft.Json.JsonWriter      arg0 = (Newtonsoft.Json.JsonWriter)ToLua.CheckObject(L, 2, typeof(Newtonsoft.Json.JsonWriter));
         Newtonsoft.Json.JsonConverter[] arg1 = ToLua.CheckParamsObject <Newtonsoft.Json.JsonConverter>(L, 3, count - 2);
         obj.WriteTo(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #36
0
 static int WriteTo(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         Newtonsoft.Json.Linq.JProperty  obj  = (Newtonsoft.Json.Linq.JProperty)ToLua.CheckObject <Newtonsoft.Json.Linq.JProperty>(L, 1);
         Newtonsoft.Json.JsonWriter      arg0 = (Newtonsoft.Json.JsonWriter)ToLua.CheckObject <Newtonsoft.Json.JsonWriter>(L, 2);
         Newtonsoft.Json.JsonConverter[] arg1 = ToLua.CheckObjectArray <Newtonsoft.Json.JsonConverter>(L, 3);
         obj.WriteTo(arg0, arg1);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #37
0
 static int Property(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         Newtonsoft.Json.Linq.JObject obj = (Newtonsoft.Json.Linq.JObject)ToLua.CheckObject <Newtonsoft.Json.Linq.JObject>(L, 1);
         string arg0 = ToLua.CheckString(L, 2);
         Newtonsoft.Json.Linq.JProperty o = obj.Property(arg0);
         ToLua.PushObject(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #38
0
    static int get_Name(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Newtonsoft.Json.Linq.JProperty obj = (Newtonsoft.Json.Linq.JProperty)o;
            string ret = obj.Name;
            LuaDLL.lua_pushstring(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Name on a nil value"));
        }
    }
Beispiel #39
0
    static int get_Value(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Newtonsoft.Json.Linq.JProperty obj = (Newtonsoft.Json.Linq.JProperty)o;
            Newtonsoft.Json.Linq.JToken    ret = obj.Value;
            ToLua.PushObject(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o == null ? "attempt to index Value on a nil value" : e.Message));
        }
    }
Beispiel #40
0
    static int set_Value(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Newtonsoft.Json.Linq.JProperty obj  = (Newtonsoft.Json.Linq.JProperty)o;
            Newtonsoft.Json.Linq.JToken    arg0 = (Newtonsoft.Json.Linq.JToken)ToLua.CheckObject <Newtonsoft.Json.Linq.JToken>(L, 2);
            obj.Value = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Value on a nil value"));
        }
    }
Beispiel #41
0
    static int get_Type(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            Newtonsoft.Json.Linq.JProperty  obj = (Newtonsoft.Json.Linq.JProperty)o;
            Newtonsoft.Json.Linq.JTokenType ret = obj.Type;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index Type on a nil value"));
        }
    }
        DynamicDictionary set_json_Data(JToken data)
        {
            DynamicDictionary item = new DynamicDictionary();

            foreach (var r in data)
            {
                Newtonsoft.Json.Linq.JProperty pp = (Newtonsoft.Json.Linq.JProperty)r;

                if (pp.Count > 1)
                {
                    set_json_Data((JToken)pp);
                }
                else
                {
                    item.SetValue(pp.Name, pp.Value);
                }
            }

            return(item);
        }
Beispiel #43
0
    static int _CreateNewtonsoft_Json_Linq_JProperty(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                Newtonsoft.Json.Linq.JProperty arg0 = (Newtonsoft.Json.Linq.JProperty)ToLua.CheckObject <Newtonsoft.Json.Linq.JProperty>(L, 1);
                Newtonsoft.Json.Linq.JProperty obj  = new Newtonsoft.Json.Linq.JProperty(arg0);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (count == 2 && TypeChecker.CheckTypes <object>(L, 2))
            {
                string arg0 = ToLua.CheckString(L, 1);
                object arg1 = ToLua.ToVarObject(L, 2);
                Newtonsoft.Json.Linq.JProperty obj = new Newtonsoft.Json.Linq.JProperty(arg0, arg1);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else if (TypeChecker.CheckTypes <string>(L, 1) && TypeChecker.CheckParamsType <object>(L, 2, count - 1))
            {
                string   arg0 = ToLua.CheckString(L, 1);
                object[] arg1 = ToLua.ToParamsObject(L, 2, count - 1);
                Newtonsoft.Json.Linq.JProperty obj = new Newtonsoft.Json.Linq.JProperty(arg0, arg1);
                ToLua.PushObject(L, obj);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Newtonsoft.Json.Linq.JProperty.New"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
Beispiel #44
0
 public static new Task <JProperty> LoadAsync(JsonReader reader, CancellationToken cancellationToken = null)
 {
     return(JProperty.LoadAsync(reader, null, cancellationToken));
 }
Beispiel #45
0
 internal void InternalPropertyChanging(JProperty childProperty)
 {
 }
Beispiel #46
0
        internal void InternalPropertyChanging(JProperty childProperty)
        {
#if !PocketPC && !SILVERLIGHT && !NET20
            OnPropertyChanging(childProperty.Name);
#endif
        }
Beispiel #47
0
        internal void ReadContentFrom(JsonReader r)
        {
            ValidationUtils.ArgumentNotNull(r, "r");

            JContainer parent = this;

            do
            {
                if (parent is JProperty)
                {
                    if (((JProperty)parent).Value != null)
                    {
                        parent = parent.Parent;
                    }
                }

                switch (r.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    parent.AddObjectSkipNotify(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    parent.AddObjectSkipNotify(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor();
                    constructor.Name = r.Value.ToString();
                    parent.AddObjectSkipNotify(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                    parent.AddObjectSkipNotify(new JValue(r.Value));
                    break;

                case JsonToken.Comment:
                    parent.AddObjectSkipNotify(JValue.CreateComment(r.Value.ToString()));
                    break;

                case JsonToken.Null:
                    parent.AddObjectSkipNotify(new JValue(null, JsonTokenType.Null));
                    break;

                case JsonToken.Undefined:
                    parent.AddObjectSkipNotify(new JValue(null, JsonTokenType.Undefined));
                    break;

                case JsonToken.PropertyName:
                    JProperty property = new JProperty(r.Value.ToString());
                    parent.AddObjectSkipNotify(property);
                    parent = property;
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
                }
            }while (r.Read());
        }
        internal void InternalPropertyChanging(JProperty childProperty)
        {
#if !(NET20 || PORTABLE40 || PORTABLE)
            OnPropertyChanging(childProperty.Name);
#endif
        }
Beispiel #49
0
 public static new JProperty Load(JsonReader reader)
 {
     return(JProperty.Load(reader, null));
 }
Beispiel #50
0
        internal void InternalPropertyChanging(JProperty childProperty)
        {
#if !PocketPC && !SILVERLIGHT && !NET20 && !__ANDROID__ && !MONOTOUCH
            OnPropertyChanging(childProperty.Name);
#endif
        }
Beispiel #51
0
 internal void InternalPropertyChanged(JProperty childProperty)
 {
     this.OnPropertyChanged(childProperty.Name);
 }
Beispiel #52
0
 internal void InternalPropertyChanged(JProperty childProperty)
 {
     OnPropertyChanged(childProperty.Name);
     OnListChanged(new ListChangedEventArgs(ListChangedType.ItemChanged, IndexOfItem(childProperty)));
 }
 private void VisitProperty(Newtonsoft.Json.Linq.JProperty property)
 {
     VisitToken(property.Value);
 }
Beispiel #54
0
        bool ICollection <KeyValuePair <string, JToken> > .Contains(KeyValuePair <string, JToken> item)
        {
            JProperty jProperty = this.Property(item.get_Key());

            return(jProperty != null && jProperty.Value == item.get_Value());
        }
Beispiel #55
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JProperty"/> class from another <see cref="JProperty"/> object.
 /// </summary>
 /// <param name="other">A <see cref="JProperty"/> object to copy from.</param>
 public JProperty(JProperty other)
     : base(other)
 {
     _name = other.Name;
 }
Beispiel #56
0
 internal void InternalPropertyChanging(JProperty childProperty)
 {
     OnPropertyChanging(childProperty.Name);
 }
Beispiel #57
0
        internal override bool DeepEquals(JToken node)
        {
            JProperty t = node as JProperty;

            return(t != null && _name == t.Name && ContentsEqual(t));
        }
Beispiel #58
0
        internal void ReadContentFrom(JsonReader r, JsonLoadSettings settings)
        {
            ValidationUtils.ArgumentNotNull(r, nameof(r));
            IJsonLineInfo lineInfo = r as IJsonLineInfo;

            JContainer parent = this;

            do
            {
                if ((parent as JProperty)?.Value != null)
                {
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                }

                switch (r.TokenType)
                {
                case JsonToken.None:
                    // new reader. move to actual content
                    break;

                case JsonToken.StartArray:
                    JArray a = new JArray();
                    a.SetLineInfo(lineInfo, settings);
                    parent.Add(a);
                    parent = a;
                    break;

                case JsonToken.EndArray:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartObject:
                    JObject o = new JObject();
                    o.SetLineInfo(lineInfo, settings);
                    parent.Add(o);
                    parent = o;
                    break;

                case JsonToken.EndObject:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.StartConstructor:
                    JConstructor constructor = new JConstructor(r.Value.ToString());
                    constructor.SetLineInfo(lineInfo, settings);
                    parent.Add(constructor);
                    parent = constructor;
                    break;

                case JsonToken.EndConstructor:
                    if (parent == this)
                    {
                        return;
                    }

                    parent = parent.Parent;
                    break;

                case JsonToken.String:
                case JsonToken.Integer:
                case JsonToken.Float:
                case JsonToken.Date:
                case JsonToken.Boolean:
                case JsonToken.Bytes:
                    JValue v = new JValue(r.Value);
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Comment:
                    if (settings != null && settings.CommentHandling == CommentHandling.Load)
                    {
                        v = JValue.CreateComment(r.Value.ToString());
                        v.SetLineInfo(lineInfo, settings);
                        parent.Add(v);
                    }
                    break;

                case JsonToken.Null:
                    v = JValue.CreateNull();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.Undefined:
                    v = JValue.CreateUndefined();
                    v.SetLineInfo(lineInfo, settings);
                    parent.Add(v);
                    break;

                case JsonToken.PropertyName:
                    string    propertyName = r.Value.ToString();
                    JProperty property     = new JProperty(propertyName);
                    property.SetLineInfo(lineInfo, settings);
                    JObject parentObject = (JObject)parent;
                    // handle multiple properties with the same name in JSON
                    JProperty existingPropertyWithName = parentObject.Property(propertyName);
                    if (existingPropertyWithName == null)
                    {
                        parent.Add(property);
                    }
                    else
                    {
                        existingPropertyWithName.Replace(property);
                    }
                    parent = property;
                    break;

                default:
                    throw new InvalidOperationException("The JsonReader should not be on a token of type {0}.".FormatWith(CultureInfo.InvariantCulture, r.TokenType));
                }
            } while (r.Read());
        }
Beispiel #59
0
        internal void InternalPropertyChanging(JProperty childProperty)
        {
#if !(SILVERLIGHT || NET20 || NETFX_CORE || PORTABLE)
            OnPropertyChanging(childProperty.Name);
#endif
        }
Beispiel #60
0
        internal void InternalPropertyChanging(JProperty childProperty)
        {
#if HAVE_INOTIFY_PROPERTY_CHANGING
            OnPropertyChanging(childProperty.Name);
#endif
        }