本文整理汇总了C#中NbtCompound.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# NbtCompound.Clear方法的具体用法?C# NbtCompound.Clear怎么用?C# NbtCompound.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NbtCompound
的用法示例。
在下文中一共展示了NbtCompound.Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddingAndRemoving
public void AddingAndRemoving()
{
NbtCompound test = new NbtCompound();
NbtInt foo = new NbtInt( "Foo" );
test.Add( foo );
// adding duplicate object
Assert.Throws<ArgumentException>( () => test.Add( foo ) );
// adding duplicate name
Assert.Throws<ArgumentException>( () => test.Add( new NbtByte( "Foo" ) ) );
// adding unnamed tag
Assert.Throws<ArgumentException>( () => test.Add( new NbtInt() ) );
// adding null
Assert.Throws<ArgumentNullException>( () => test.Add( null ) );
// contains existing name
Assert.IsTrue( test.Contains( "Foo" ) );
// contains existing object
Assert.IsTrue( test.Contains( foo ) );
// contains non-existent name
Assert.IsFalse( test.Contains( "Bar" ) );
// contains existing name / different object
Assert.IsFalse( test.Contains( new NbtInt( "Foo" ) ) );
// removing non-existent name
Assert.IsFalse( test.Remove( "Bar" ) );
// removing existing name
Assert.IsTrue( test.Remove( "Foo" ) );
// removing non-existent name
Assert.IsFalse( test.Remove( "Foo" ) );
// re-adding object
test.Add( foo );
// removing existing object
Assert.IsTrue( test.Remove( foo ) );
// clearing an empty NbtCompound
Assert.AreEqual( test.Count, 0 );
test.Clear();
// re-adding after clearing
test.Add( foo );
Assert.AreEqual( test.Count, 1 );
// clearing a non-empty NbtCompound
test.Clear();
Assert.AreEqual( test.Count, 0 );
}
示例2: AddingAndRemoving
public void AddingAndRemoving()
{
var foo = new NbtInt("Foo");
var test = new NbtCompound
{
foo
};
// adding duplicate object
Assert.Throws<ArgumentException>(() => test.Add(foo));
// adding duplicate name
Assert.Throws<ArgumentException>(() => test.Add(new NbtByte("Foo")));
// adding unnamed tag
Assert.Throws<ArgumentException>(() => test.Add(new NbtInt()));
// adding null
Assert.Throws<ArgumentNullException>(() => test.Add(null));
// adding tag to self
Assert.Throws<ArgumentException>(() => test.Add(test));
// contains existing name/object
Assert.True(test.Contains("Foo"));
Assert.True(test.Contains(foo));
Assert.Throws<ArgumentNullException>(() => test.Contains((string) null));
Assert.Throws<ArgumentNullException>(() => test.Contains((NbtTag) null));
// contains non-existent name
Assert.False(test.Contains("Bar"));
// contains existing name / different object
Assert.False(test.Contains(new NbtInt("Foo")));
// removing non-existent name
Assert.Throws<ArgumentNullException>(() => test.Remove((string) null));
Assert.False(test.Remove("Bar"));
// removing existing name
Assert.True(test.Remove("Foo"));
// removing non-existent name
Assert.False(test.Remove("Foo"));
// re-adding object
test.Add(foo);
// removing existing object
Assert.Throws<ArgumentNullException>(() => test.Remove((NbtTag) null));
Assert.True(test.Remove(foo));
Assert.False(test.Remove(foo));
// clearing an empty NbtCompound
Assert.Equal(0, test.Count);
test.Clear();
// re-adding after clearing
test.Add(foo);
Assert.Equal(1, test.Count);
// clearing a non-empty NbtCompound
test.Clear();
Assert.Equal(0, test.Count);
}