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


C# NbtCompound.Contains方法代码示例

本文整理汇总了C#中NbtCompound.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# NbtCompound.Contains方法的具体用法?C# NbtCompound.Contains怎么用?C# NbtCompound.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NbtCompound的用法示例。


在下文中一共展示了NbtCompound.Contains方法的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 );
        }
开发者ID:pdelvo,项目名称:LibNbt2012,代码行数:59,代码来源:CompoundTests.cs

示例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);
        }
开发者ID:KenVanGilbergen,项目名称:ken.Minecraft,代码行数:65,代码来源:NbtCompoundTests.cs


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