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


C# Linq.JConstructor类代码示例

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


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

示例1: SetValueWithInvalidIndex

 public void SetValueWithInvalidIndex()
 {
   ExceptionAssert.Throws<ArgumentException>(@"Set JConstructor values with invalid key value: ""badvalue"". Argument position index expected.",
   () =>
   {
     JConstructor c = new JConstructor();
     c["badvalue"] = new JValue(3);
   }); 
 }
开发者ID:pvasek,项目名称:Newtonsoft.Json,代码行数:9,代码来源:JConstructorTests.cs

示例2: CreateWithMultiValue

 public void CreateWithMultiValue()
 {
     JConstructor constructor = new JConstructor("Test", new List<int> { 1, 2, 3 });
     Assert.AreEqual("Test", constructor.Name);
     Assert.AreEqual(3, constructor.Children().Count());
     Assert.AreEqual(1, (int)constructor.Children().ElementAt(0));
     Assert.AreEqual(2, (int)constructor.Children().ElementAt(1));
     Assert.AreEqual(3, (int)constructor.Children().ElementAt(2));
 }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:9,代码来源:JConstructorTests.cs

示例3: JConstructorDictionary

    public void JConstructorDictionary()
    {
      Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
      JConstructor v11 = new JConstructor("ConstructorValue");
      JConstructor v12 = new JConstructor("ConstructorValue");

      dic[v11] = 1;
      dic[v12] += 1;
      Assert.AreEqual(2, dic[v11]);
    }
开发者ID:Top-Cat,项目名称:SteamBot,代码行数:10,代码来源:JTokenEqualityComparerTests.cs

示例4: Iterate

        public void Iterate()
        {
            JConstructor c = new JConstructor("MrConstructor", 1, 2, 3, 4, 5);

            int i = 1;
            foreach (JToken token in c)
            {
                Assert.AreEqual(i, (int)token);
                i++;
            }
        }
开发者ID:JamesNK,项目名称:Newtonsoft.Json,代码行数:11,代码来源:JConstructorTests.cs

示例5: SetValue

    public void SetValue()
    {
      object key = 0;

      JConstructor c = new JConstructor();
      c.Name = "con";
      c.Add(null);
      c[key] = new JValue(3);

      Assert.AreEqual(3, (int)c[key]);
    }
开发者ID:284247028,项目名称:MvvmCross,代码行数:11,代码来源:JConstructorTests.cs

示例6: Load

        /// <summary>
        /// Loads an <see cref="JConstructor"/> from a <see cref="JsonReader"/>. 
        /// </summary>
        /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="JConstructor"/>.</param>
        /// <returns>A <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
        public static new JConstructor Load(JsonReader reader)
        {
            if (reader.TokenType == JsonToken.None)
            {
            if (!reader.Read())
            throw new Exception("Error reading JConstructor from JsonReader.");
            }

            if (reader.TokenType != JsonToken.StartConstructor)
            throw new Exception("Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            JConstructor c = new JConstructor((string)reader.Value);
            c.SetLineInfo(reader as IJsonLineInfo);

            c.ReadTokenFrom(reader);

            return c;
        }
开发者ID:ThePiachu,项目名称:BitNet,代码行数:23,代码来源:JConstructor.cs

示例7: EvaluateConstructorOutOfBoundsIndxerWithError

    public void EvaluateConstructorOutOfBoundsIndxerWithError()
    {
      JConstructor c = new JConstructor("Blah");

      c.SelectToken("[1]", true);
    }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:6,代码来源:JPathTests.cs

示例8: Load

        /// <summary>
        /// Loads an <see cref="JConstructor"/> from a <see cref="JsonReader"/>. 
        /// </summary>
        /// <param name="reader">A <see cref="JsonReader"/> that will be read for the content of the <see cref="JConstructor"/>.</param>
        /// <param name="settings">The <see cref="JsonLoadSettings"/> used to load the JSON.
        /// If this is null, default load settings will be used.</param>
        /// <returns>A <see cref="JConstructor"/> that contains the JSON that was read from the specified <see cref="JsonReader"/>.</returns>
        public new static JConstructor Load(JsonReader reader, JsonLoadSettings settings)
        {
            if (reader.TokenType == JsonToken.None)
            {
                if (!reader.Read())
                    throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader.");
            }

            while (reader.TokenType == JsonToken.Comment)
            {
                reader.Read();
            }

            if (reader.TokenType != JsonToken.StartConstructor)
                throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}".FormatWith(CultureInfo.InvariantCulture, reader.TokenType));

            JConstructor c = new JConstructor((string)reader.Value);
            c.SetLineInfo(reader as IJsonLineInfo);

            c.ReadTokenFrom(reader, settings);

            return c;
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:30,代码来源:JConstructor.cs

示例9: JConstructorStringIndex

 public void JConstructorStringIndex()
 {
     JConstructor c = new JConstructor("ConstructorValue");
       Assert.AreEqual(null, c["purple"]);
 }
开发者ID:robgreen,项目名称:nom,代码行数:5,代码来源:LinqToJsonTest.cs

示例10: MergeNull

        public void MergeNull()
        {
            JConstructor c = new JConstructor();
            c.Merge(null);
            Assert.AreEqual(null, c.Name);
            Assert.AreEqual(0, c.Count);

            JObject o = new JObject();
            o.Merge(null);
            Assert.AreEqual(0, o.Count);

            JArray a = new JArray();
            a.Merge(null);
            Assert.AreEqual(0, a.Count);

            JProperty p = new JProperty("name1");
            p.Merge(null);
            Assert.AreEqual("name1", p.Name);
            Assert.AreEqual(0, p.Count);
        }
开发者ID:b-bot-110,项目名称:Newtonsoft.Json,代码行数:20,代码来源:MergeTests.cs

示例11: EchoJConstructor

 public JConstructor EchoJConstructor(JConstructor input)
 {
     return input;
 }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:4,代码来源:JTokenController.cs

示例12: JConstructorStringIndex

 public void JConstructorStringIndex()
 {
   ExceptionAssert.Throws<ArgumentException>(@"Accessed JConstructor values with invalid key value: ""purple"". Argument position index expected.",
   () =>
   {
     JConstructor c = new JConstructor("ConstructorValue");
     Assert.AreEqual(null, c["purple"]);
   });
 }
开发者ID:xupeihuagudulei,项目名称:Newtonsoft.Json,代码行数:9,代码来源:LinqToJsonTest.cs

示例13: Load

 public static JConstructor Load(JsonReader reader)
 {
   if (reader.TokenType == JsonToken.None && !reader.Read())
     throw JsonReaderException.Create(reader, "Error reading JConstructor from JsonReader.");
   while (reader.TokenType == JsonToken.Comment)
     reader.Read();
   if (reader.TokenType != JsonToken.StartConstructor)
     throw JsonReaderException.Create(reader, StringUtils.FormatWith("Error reading JConstructor from JsonReader. Current JsonReader item is not a constructor: {0}", (IFormatProvider) CultureInfo.InvariantCulture, (object) reader.TokenType));
   JConstructor jconstructor = new JConstructor((string) reader.Value);
   jconstructor.SetLineInfo(reader as IJsonLineInfo);
   jconstructor.ReadTokenFrom(reader);
   return jconstructor;
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:13,代码来源:JConstructor.cs

示例14: SetValueWithInvalidIndex

 public void SetValueWithInvalidIndex()
 {
   JConstructor c = new JConstructor();
   c["badvalue"] = new JValue(3);
 }
开发者ID:284247028,项目名称:MvvmCross,代码行数:5,代码来源:JConstructorTests.cs

示例15: EvaluateIndexerOnConstructorWithError

    public void EvaluateIndexerOnConstructorWithError()
    {
      JConstructor c = new JConstructor("Blah");

      c.SelectToken("[1]", true);
    }
开发者ID:Gert-Cominotto,项目名称:MvvmCross,代码行数:6,代码来源:JPathTests.cs


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