• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# JValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: DoubleDeepEquals

    public void DoubleDeepEquals()
    {
      JArray a =
        new JArray(
          double.NaN,
          double.PositiveInfinity,
          double.NegativeInfinity
        );

      JArray a2 = (JArray)a.DeepClone();

      Assert.IsTrue(a.DeepEquals(a2));

      double d = 1 + 0.1 + 0.1 + 0.1;

      JValue v1 = new JValue(d);
      JValue v2 = new JValue(1.3);

      Assert.IsTrue(v1.DeepEquals(v2));
    }
开发者ID:bitpusher,项目名称:Newtonsoft.Json4,代码行数:20,代码来源:JTokenTests.cs


示例17: EqualsWithStringCoercion

        private bool EqualsWithStringCoercion(JValue value, JValue queryValue)
        {
            if (value.Equals(queryValue))
            {
                return true;
            }

            if (queryValue.Type != JTokenType.String)
            {
                return false;
            }

            string queryValueString = (string)queryValue.Value;

            string currentValueString;

            // potential performance issue with converting every value to string?
            switch (value.Type)
            {
                case JTokenType.Date:
                    using (StringWriter writer = StringUtils.CreateStringWriter(64))
                    {
#if !NET20
                        if (value.Value is DateTimeOffset)
                        {
                            DateTimeUtils.WriteDateTimeOffsetString(writer, (DateTimeOffset)value.Value, DateFormatHandling.IsoDateFormat, null, CultureInfo.InvariantCulture);
                        }
                        else
#endif
                        {
                            DateTimeUtils.WriteDateTimeString(writer, (DateTime)value.Value, DateFormatHandling.IsoDateFormat, null, CultureInfo.InvariantCulture);
                        }

                        currentValueString = writer.ToString();
                    }
                    break;
                case JTokenType.Bytes:
                    currentValueString = Convert.ToBase64String((byte[])value.Value);
                    break;
                case JTokenType.Guid:
                case JTokenType.TimeSpan:
                    currentValueString = value.Value.ToString();
                    break;
                case JTokenType.Uri:
                    currentValueString = ((Uri)value.Value).OriginalString;
                    break;
                default:
                    return false;
            }

            return string.Equals(currentValueString, queryValueString, StringComparison.Ordinal);
        }
开发者ID:veblush,项目名称:Newtonsoft.Json,代码行数:52,代码来源:QueryExpression.cs


示例18: JPropertyContains

        public void JPropertyContains()
        {
            JValue v = new JValue(1);
            var p = new JProperty("TestProperty", v);

            Assert.Equal(true, p.Contains(v));
            Assert.Equal(false, p.Contains(new JValue(1)));
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:8,代码来源:JPropertyTests.cs


示例19: JPropertyIndexOf

        public void JPropertyIndexOf()
        {
            JValue v = new JValue(1);
            JProperty p1 = new JProperty("TestProperty", v);

            IList l1 = p1;
            Assert.Equal(0, l1.IndexOf(v));

            IList<JToken> l2 = p1;
            Assert.Equal(0, l2.IndexOf(v));
        }
开发者ID:extesla,项目名称:OpenGamingLibrary,代码行数:11,代码来源:JPropertyTests.cs


示例20: Insert

    public void Insert()
    {
      JValue v1 = new JValue(1);
      JValue v2 = new JValue(2);
      JValue v3 = new JValue(3);
      JValue v4 = new JValue(4);

      JArray j = new JArray();

      j.Add(v1);
      j.Add(v2);
      j.Add(v3);
      j.Insert(1, v4);

      Assert.AreEqual(0, j.IndexOf(v1));
      Assert.AreEqual(1, j.IndexOf(v4));
      Assert.AreEqual(2, j.IndexOf(v2));
      Assert.AreEqual(3, j.IndexOf(v3));
    }
开发者ID:royra,项目名称:ravendb,代码行数:19,代码来源:JArrayTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JadeCore类代码示例发布时间:2022-05-24
下一篇:
C# JTokenType类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap