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


C# List.GetType方法代码示例

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


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

示例1: Convert_IEnumerableOfString_IsSupported

 public void Convert_IEnumerableOfString_IsSupported()
 {
     var converter = new SimpleDbConverter();
     var theList = new List<string>();
     var forSimpleDb = converter.ConvertToSimpleDb(theList.GetType(), theList);
     Assert.AreEqual(string.Empty, forSimpleDb);
     theList.Add("blue");
     theList.Add("red");
     theList.Add("green");
     forSimpleDb = converter.ConvertToSimpleDb(theList.GetType(), theList);
     Assert.AreEqual("blue,red,green", forSimpleDb);
     var toSimpleDb = converter.ConvertFromSimpleDb(theList.GetType(), forSimpleDb);
     Assert.AreEqual(toSimpleDb, theList);
 }
开发者ID:dotcomputercraft,项目名称:irobyx.SimpleDb,代码行数:14,代码来源:SimpleDbConverterTest.cs

示例2: Can_convert_shippingOptionList_to_string_and_back

        public void Can_convert_shippingOptionList_to_string_and_back()
        {
            var shippingOptionsInput = new List<ShippingOption>();
            shippingOptionsInput.Add(new ShippingOption()
            {
                Name = "a1",
                Description = "a2",
                Rate = 3.57M,
                ShippingRateComputationMethodSystemName = "a4"
            });
            shippingOptionsInput.Add(new ShippingOption()
            {
                Name = "b1",
                Description = "b2",
                Rate = 7.00M,
                ShippingRateComputationMethodSystemName = "b4"
            });

			var converter = CommonHelper.GetTypeConverter(shippingOptionsInput.GetType());
            var result = converter.ConvertTo(shippingOptionsInput, typeof(string)) as string;

            var shippingOptionsOutput = converter.ConvertFrom(result) as List<ShippingOption>;
            shippingOptionsOutput.ShouldNotBeNull();
            shippingOptionsOutput.Count.ShouldEqual(2);
            shippingOptionsOutput[0].Name.ShouldEqual("a1");
            shippingOptionsOutput[0].Description.ShouldEqual("a2");
            shippingOptionsOutput[0].Rate.ShouldEqual(3.57M);
            shippingOptionsOutput[0].ShippingRateComputationMethodSystemName.ShouldEqual("a4");

            shippingOptionsOutput[1].Name.ShouldEqual("b1");
            shippingOptionsOutput[1].Description.ShouldEqual("b2");
            shippingOptionsOutput[1].Rate.ShouldEqual(7.00M);
            shippingOptionsOutput[1].ShippingRateComputationMethodSystemName.ShouldEqual("b4");
        }
开发者ID:JeffersonNascimento,项目名称:SmartStoreNET,代码行数:34,代码来源:ShippingOptionListTypeConverterTests.cs

示例3: CanWrite_ReturnsFalse_IfValueIsAList

        public void CanWrite_ReturnsFalse_IfValueIsAList()
        {
            object value = new ArrayList();
            Assert.IsFalse(writer.CanWrite(value, value.GetType()));

            value = new List<int>();
            Assert.IsFalse(writer.CanWrite(value, value.GetType()));
        }
开发者ID:RobSmyth,项目名称:nserializer,代码行数:8,代码来源:ArrayOfObjectsWriterTests.cs

示例4: Can_convert_string_list_to_string

 public void Can_convert_string_list_to_string()
 {
     var items = new List<string> { "foo", "bar", "day" };
     var converter = TypeDescriptor.GetConverter(items.GetType());
     var result = converter.ConvertTo(items, typeof(string)) as string;
     result.ShouldNotBeNull();
     result.ShouldEqual("foo,bar,day");
 }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:8,代码来源:GenericListTypeConverterTests.cs

示例5: Can_convert_int_list_to_string

        public void Can_convert_int_list_to_string()
        {
            var items = new List<int> { 10, 20, 30, 40, 50 };
            var converter = TypeDescriptor.GetConverter(items.GetType());
            var result = converter.ConvertTo(items, typeof(string)) as string;

            result.ShouldNotBeNull();
            result.ShouldEqual("10,20,30,40,50");
        }
开发者ID:haithemChkel,项目名称:nopCommerce_33,代码行数:9,代码来源:GenericListTypeConverterTests.cs

示例6: DoCheck

        public void DoCheck()
        {
            var loGenericItem = new List<List<String>>();
            var loTypeAnatomy = loGenericItem.GetType().GetTypeAnatomy();

            Assert.IsNotNull(loTypeAnatomy);

            var loGenericItemFromAnatomy = loTypeAnatomy.CreateInstance();

            Assert.IsTrue(loGenericItemFromAnatomy is List<List<String>>);
        }
开发者ID:vasilenkos,项目名称:DSE,代码行数:11,代码来源:TypeAnatomy.cs

示例7: NonPrimitiveInstanceTest

        public void NonPrimitiveInstanceTest()
        {
            List<String> testList = new List<String>();
            Type listType = testList.GetType();

            var creationData = new ObjectCreationData(listType.GetConstructor(Type.EmptyTypes));

            var objInstance = new ObjectInstance(testList, creationData);
            Assert.That(objInstance.Instance, Is.SameAs(testList));
            Assert.That(objInstance.InstanceNeedsConstructor, Is.True);
            Assert.That(objInstance.CreationData, Is.SameAs(creationData));
        }
开发者ID:eneiand,项目名称:Baseline,代码行数:12,代码来源:ObjectInstanceTests.cs

示例8: ShouldAssignArrayOfListsToNative

 public void ShouldAssignArrayOfListsToNative()
 {
     var intArray = new int[1][];
     intArray[0] = new int[1] { 2 };
     List<int>[] listArray = new List<int> [1] { new List<int> { 1 } };
     SinTDArray innerArray = new SinTDArray();
     innerArray.elementType = SinTDInstance.GetSinTDType("i32");
     SinTDArray outerArray = new SinTDArray();
     outerArray.elementType = innerArray;
     List<int>[] test = (List<int>[])outerArray.AssignValuesToNativeType(intArray, listArray.GetType());
     Assert.IsAssignableFrom<List<int>>(test[0]);
     Assert.AreEqual(2, test[0][0]);
 }
开发者ID:tospie,项目名称:SINFONI,代码行数:13,代码来源:TestTypeInstances.cs

示例9: SholdKnowIfATypeIsAListOfResources

        public void SholdKnowIfATypeIsAListOfResources()
        {
            var list = new List<IBehaveAsResource>();
            var array = new[] {new SomeResource()};

            var notAResourceList = new List<int>();
            var notAResourceArray = new[] {1, 2};

            Assert.IsTrue(list.GetType().IsAListOfResources());
            Assert.IsTrue(array.GetType().IsAListOfResources());

            Assert.IsFalse(notAResourceList.GetType().IsAListOfResources());
            Assert.IsFalse(notAResourceArray.GetType().IsAListOfResources());
        }
开发者ID:seixasfelipe,项目名称:restfulie.net,代码行数:14,代码来源:TypeExtensionsTests.cs

示例10: ComplexCollection

        public static void ComplexCollection()
        {
            var items = new List<object>();
            items.Add(5);
            items.Add("hello");
            items.Add(new { number = 3 });
            items.Add(new Dictionary<string, object>() { { "file", "hello.jpg" } });
            var serialized = Json.Serialize(items);

            var deserializedItems = Json.Deserialize(serialized, items.GetType()) as List<object>;
            Assert.AreEqual(deserializedItems.Count, 4);
            Assert.AreEqual(deserializedItems[0], 5);
            Assert.AreEqual(deserializedItems[1], "hello");
            Assert.AreEqual(((IDictionary)deserializedItems[2])["number"], 3);
            Assert.AreEqual(((IDictionary)deserializedItems[3])["file"], "hello.jpg");
        }
开发者ID:scorredoira,项目名称:Sfx.Json,代码行数:16,代码来源:JsonTests.cs

示例11: Cast

        public void Cast()
        {
            object source = new List<M1> {new M1 {Name = "o"}};
            object target = new List<M2>();

            var targetArgumentType = target.GetType().GetGenericArguments()[0];

            var list = Activator.CreateInstance(typeof(List<>).MakeGenericType(targetArgumentType));
            var add = list.GetType().GetMethod("Add");

            foreach (var o in source as IEnumerable)
            {
                var t = Activator.CreateInstance(targetArgumentType);
                add.Invoke(list, new[] { t.InjectFrom(o) });
            }

            target = list;

            Assert.AreEqual("o", (target as List<M2>).First().Name);
        }
开发者ID:jpomez,项目名称:ValueInjecter,代码行数:20,代码来源:BelitreTest.cs

示例12: TestGenericArguments

        public void TestGenericArguments()
        {
            IList<string> strlist = new List<string>();

            Type type = strlist.GetType();
            Assert.IsTrue(type.IsGenericType);

            Assert.AreEqual(typeof(string),type.GetGenericArguments()[0]);
        }
开发者ID:stasi009,项目名称:TestDrivenLearn,代码行数:9,代码来源:ReflectionTest.cs

示例13: SerializeDeserailize_listOfSerializableGetSetPropertiesOfPrimitiveType_theSame

        public void SerializeDeserailize_listOfSerializableGetSetPropertiesOfPrimitiveType_theSame()
        {
            GetSetProperties o = new GetSetProperties { dat = "fff"};
            var l = new List<GetSetProperties>();
            l.Add(o);
            l.Add(o);
            var ser = new XmlSerializer(l.GetType());
            var nss = new XmlSerializerNamespaces();
            nss.Add(String.Empty, String.Empty);
            var m = new MemoryStream();

            ser.Serialize(m,l, nss);
            m.Position = 0;
            var de = (List<GetSetProperties>)ser.Deserialize(m);

            Assert.AreEqual(o.dat, de[0].dat);
            Assert.AreEqual(o.dat, de[1].dat);
        }
开发者ID:OpenSharp,项目名称:mono,代码行数:18,代码来源:XmlSerializerTests.cs

示例14: ReturnsFalseForNonDerivingClass

            public void ReturnsFalseForNonDerivingClass()
            {
                var genericType = typeof (SavableModelBase<>);
                var toCheck = new List<string>();

                Assert.IsFalse(TypeHelper.IsSubclassOfRawGeneric(genericType, toCheck.GetType()));
            }
开发者ID:justdude,项目名称:DbExport,代码行数:7,代码来源:TypeHelperFacts.cs

示例15: PolymorphicSerializationThroughListWhichMayContainYaxlibNamespaceTest

        public void PolymorphicSerializationThroughListWhichMayContainYaxlibNamespaceTest()
        {
            var lst = new List<object> { 1, 2, 3 };
            var ser = new YAXSerializer(typeof(object));
            string xmlResult = ser.Serialize(lst);

            const string expectedResult =
            @"<Object xmlns:yaxlib=""http://www.sinairv.com/yaxlib/"" yaxlib:realtype=""System.Collections.Generic.List`1[[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"">
              <Int32 yaxlib:realtype=""System.Int32"">1</Int32>
              <Int32 yaxlib:realtype=""System.Int32"">2</Int32>
              <Int32 yaxlib:realtype=""System.Int32"">3</Int32>
            </Object>";

            Assert.That(xmlResult.StripTypeAssemblyVersion(), Is.EqualTo(expectedResult.StripTypeAssemblyVersion()));
            var desObj = ser.Deserialize(xmlResult);
            Assert.That(desObj.GetType(), Is.EqualTo(lst.GetType()));
            var desLst = desObj as List<object>;
            Assert.That(lst, Has.Count.EqualTo(desLst.Count));
            Assert.That(lst, Is.EquivalentTo(desLst));
        }
开发者ID:sschocke,项目名称:BrainSimulator,代码行数:20,代码来源:SerializationTest.cs


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