本文整理汇总了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);
}
示例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");
}
示例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()));
}
示例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");
}
示例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");
}
示例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>>);
}
示例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));
}
示例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]);
}
示例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());
}
示例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");
}
示例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);
}
示例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]);
}
示例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);
}
示例14: ReturnsFalseForNonDerivingClass
public void ReturnsFalseForNonDerivingClass()
{
var genericType = typeof (SavableModelBase<>);
var toCheck = new List<string>();
Assert.IsFalse(TypeHelper.IsSubclassOfRawGeneric(genericType, toCheck.GetType()));
}
示例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));
}