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


C# JValue类代码示例

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


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

示例1: Example

        public void Example()
        {
            #region Usage
            JValue s1 = new JValue("A string");
            JValue s2 = new JValue("A string");
            JValue s3 = new JValue("A STRING");

            Console.WriteLine(JToken.DeepEquals(s1, s2));
            // true

            Console.WriteLine(JToken.DeepEquals(s2, s3));
            // false

            JObject o1 = new JObject
            {
                { "Integer", 12345 },
                { "String", "A string" },
                { "Items", new JArray(1, 2) }
            };

            JObject o2 = new JObject
            {
                { "Integer", 12345 },
                { "String", "A string" },
                { "Items", new JArray(1, 2) }
            };

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

            Console.WriteLine(JToken.DeepEquals(s1, o1["String"]));
            // true
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:34,代码来源:DeepEquals.cs

示例2: SetValueWithInvalidIndex

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

示例3: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            Department department = (Department)value;

            JObject o = new JObject();
            o["DepartmentId"] = new JValue(department.DepartmentId.ToString());
            o["Name"] = new JValue(new string(department.Name.Reverse().ToArray()));

            o.WriteTo(writer);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:10,代码来源:DepartmentConverter.cs

示例4: JValueDictionary

        public void JValueDictionary()
        {
            Dictionary<JToken, int> dic = new Dictionary<JToken, int>(JToken.EqualityComparer);
            JValue v11 = new JValue(1);
            JValue v12 = new JValue(1);

            dic[v11] = 1;
            dic[v12] += 1;
            Assert.AreEqual(2, dic[v11]);
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:10,代码来源:JTokenEqualityComparerTests.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:bitpusher,项目名称:Newtonsoft.Json4,代码行数:11,代码来源:JConstructorTests.cs

示例6: Contains

    public void Contains()
    {
      JValue v = new JValue(1);

      JArray a = new JArray {v};

      Assert.AreEqual(false, a.Contains(new JValue(2)));
      Assert.AreEqual(false, a.Contains(new JValue(1)));
      Assert.AreEqual(false, a.Contains(null));
      Assert.AreEqual(true, a.Contains(v));
    }
开发者ID:royra,项目名称:ravendb,代码行数:11,代码来源:JArrayTests.cs

示例7: ChangeValue

    public void ChangeValue()
    {
      JValue v = new JValue(true);
      Assert.AreEqual(true, v.Value);
      Assert.AreEqual(JTokenType.Boolean, v.Type);

      v.Value = "Pie";
      Assert.AreEqual("Pie", v.Value);
      Assert.AreEqual(JTokenType.String, v.Type);

      v.Value = null;
      Assert.AreEqual(null, v.Value);
      Assert.AreEqual(JTokenType.Null, v.Type);

      v.Value = (int?)null;
      Assert.AreEqual(null, v.Value);
      Assert.AreEqual(JTokenType.Null, v.Type);

      v.Value = "Pie";
      Assert.AreEqual("Pie", v.Value);
      Assert.AreEqual(JTokenType.String, v.Type);

#if !(NETFX_CORE || PORTABLE)
      v.Value = DBNull.Value;
      Assert.AreEqual(DBNull.Value, v.Value);
      Assert.AreEqual(JTokenType.Null, v.Type);
#endif

      byte[] data = new byte[0];
      v.Value = data;

      Assert.AreEqual(data, v.Value);
      Assert.AreEqual(JTokenType.Bytes, v.Type);

      v.Value = StringComparison.OrdinalIgnoreCase;
      Assert.AreEqual(StringComparison.OrdinalIgnoreCase, v.Value);
      Assert.AreEqual(JTokenType.Integer, v.Type);

      v.Value = new Uri("http://json.codeplex.com/");
      Assert.AreEqual(new Uri("http://json.codeplex.com/"), v.Value);
      Assert.AreEqual(JTokenType.Uri, v.Type);

      v.Value = TimeSpan.FromDays(1);
      Assert.AreEqual(TimeSpan.FromDays(1), v.Value);
      Assert.AreEqual(JTokenType.TimeSpan, v.Type);

      Guid g = Guid.NewGuid();
      v.Value = g;
      Assert.AreEqual(g, v.Value);
      Assert.AreEqual(JTokenType.Guid, v.Type);
    }
开发者ID:nberardi,项目名称:ravendb,代码行数:51,代码来源:JValueTests.cs

示例8: GenericCollectionRemove

    public void GenericCollectionRemove()
    {
      JValue v = new JValue(1);
      JObject o = new JObject();
      o.Add("PropertyNameValue", v);
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue1", new JValue(1))));
      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(2))));
      Assert.AreEqual(false, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", new JValue(1))));
      Assert.AreEqual(true, ((ICollection<KeyValuePair<string, JToken>>)o).Remove(new KeyValuePair<string, JToken>("PropertyNameValue", v)));

      Assert.AreEqual(0, o.Children().Count());
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:14,代码来源:JObjectTests.cs

示例9: Manual

    public void Manual()
    {
      JArray array = new JArray();
      JValue text = new JValue("Manual text");
      JValue date = new JValue(new DateTime(2000, 5, 23));

      array.Add(text);
      array.Add(date);

      string json = array.ToString();
      // [
      //   "Manual text",
      //   "\/Date(958996800000+1200)\/"
      // ]
    }
开发者ID:925coder,项目名称:ravendb,代码行数:15,代码来源:LinqToJsonTest.cs

示例10: Example

        public void Example()
        {
            #region Usage
            JValue v1 = new JValue("1");
            int i = (int)v1;

            Console.WriteLine(i);
            // 1

            JValue v2 = new JValue(true);
            bool b = (bool)v2;

            Console.WriteLine(b);
            // true

            JValue v3 = new JValue("19.95");
            decimal d = (decimal)v3;

            Console.WriteLine(d);
            // 19.95

            JValue v4 = new JValue(new DateTime(2013, 1, 21));
            string s = (string)v4;

            Console.WriteLine(s);
            // 01/21/2013 00:00:00

            JValue v5 = new JValue("http://www.bing.com");
            Uri u = (Uri)v5;

            Console.WriteLine(u);
            // http://www.bing.com/

            JValue v6 = JValue.CreateNull();
            u = (Uri)v6;

            Console.WriteLine((u != null) ? u.ToString() : "{null}");
            // {null}

            DateTime? dt = (DateTime?)v6;

            Console.WriteLine((dt != null) ? dt.ToString() : "{null}");
            // {null}
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:45,代码来源:JValueCast.cs

示例11: Example

        public void Example()
        {
            #region Usage
            JValue s = new JValue("A string value");

            Console.WriteLine(s.Value.GetType().Name);
            // String
            Console.WriteLine(s.Value);
            // A string value

            JValue u = new JValue(new Uri("http://www.google.com/"));

            Console.WriteLine(u.Value.GetType().Name);
            // Uri
            Console.WriteLine(u.Value);
            // http://www.google.com/
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:18,代码来源:JValueValue.cs

示例12: Example

        public void Example()
        {
            #region Usage
            JValue v1 = new JValue(true);

            bool b = v1.ToObject<bool>();

            Console.WriteLine(b);
            // true

            int i = v1.ToObject<int>();

            Console.WriteLine(i);
            // 1

            string s = v1.ToObject<string>();

            Console.WriteLine(s);
            // "True"
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:21,代码来源:ToObjectGeneric.cs

示例13: Example

        public void Example()
        {
            #region Usage
            JValue v1 = new JValue(true);

            bool b = (bool)v1.ToObject(typeof(bool));

            Console.WriteLine(b);
            // true

            int i = (int)v1.ToObject(typeof(int));

            Console.WriteLine(i);
            // 1

            string s = (string)v1.ToObject(typeof(string));

            Console.WriteLine(s);
            // "True"
            #endregion
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:21,代码来源:ToObjectType.cs

示例14: DictionaryItemShouldSet

    public void DictionaryItemShouldSet()
    {
      JObject o = new JObject();
      o["PropertyNameValue"] = new JValue(1);
      Assert.AreEqual(1, o.Children().Count());

      JToken t;
      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(1), t));

      o["PropertyNameValue"] = new JValue(2);
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue(2), t));

      o["PropertyNameValue"] = null;
      Assert.AreEqual(1, o.Children().Count());

      Assert.AreEqual(true, o.TryGetValue("PropertyNameValue", out t));
      Assert.AreEqual(true, JToken.DeepEquals(new JValue((object)null), t));
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:22,代码来源:JObjectTests.cs

示例15: ToObjectWithDefaultSettings

        public void ToObjectWithDefaultSettings()
        {
            try
            {
                JsonConvert.DefaultSettings = () =>
                {
                    return new JsonSerializerSettings
                    {
                        Converters = { new MetroStringConverter() }
                    };
                };

                JValue v = new JValue(":::STRING:::");
                string s = v.ToObject<string>();

                Assert.Equal("string", s);
            }
            finally
            {
                JsonConvert.DefaultSettings = null;
            }
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:22,代码来源:JValueTests.cs


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