本文整理匯總了C#中Newtonsoft.Json.Linq.JObject.SafeAdd方法的典型用法代碼示例。如果您正苦於以下問題:C# JObject.SafeAdd方法的具體用法?C# JObject.SafeAdd怎麽用?C# JObject.SafeAdd使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.SafeAdd方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: SafeAddDoesNotAddPropertyWhenValueIsTokenWithNullValue
public void SafeAddDoesNotAddPropertyWhenValueIsTokenWithNullValue()
{
// Arrange
var sut = new JObject();
// Act
sut.SafeAdd("foo", (string)null);
// Assert
Assert.That(sut.Properties().Any(i => i.Name == "foo"), Is.False,
"SafeAdd() should not add property if value is null."
);
}
示例2: SafeAddAddsPropertyWhenItDoesNotExist
public void SafeAddAddsPropertyWhenItDoesNotExist()
{
// Arrange
var sut = new JObject();
// Act
sut.SafeAdd("foo", "bar");
// Assert
Assert.That((string)sut["foo"], Is.EqualTo("bar"),
"SafeAdd() should add property if it doesn't exist."
);
}
示例3: SafeAddDoesNotAddPropertyWhenValueIsNull
public void SafeAddDoesNotAddPropertyWhenValueIsNull()
{
// Arrange
var sut = new JObject();
sut["foo"] = "bar";
// Act
sut.SafeAdd("foo", null);
// Assert
Assert.That((string)sut["foo"], Is.EqualTo("bar"),
"SafeAdd() should not add property if value is null."
);
}
示例4: SafeAddDoesNotAddPropertyWhenItAlreadyExists
public void SafeAddDoesNotAddPropertyWhenItAlreadyExists()
{
// Arrange
var sut = new JObject();
sut["foo"] = "bar";
// Act
sut.SafeAdd("foo", "baz");
// Assert
Assert.That((string)sut["foo"], Is.EqualTo("bar"),
"SafeAdd() should not add property if it already exists."
);
}