本文整理汇总了C#中TypeInfo.ReadType方法的典型用法代码示例。如果您正苦于以下问题:C# TypeInfo.ReadType方法的具体用法?C# TypeInfo.ReadType怎么用?C# TypeInfo.ReadType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TypeInfo
的用法示例。
在下文中一共展示了TypeInfo.ReadType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: It_detects_Obsolete_attributes
public void It_detects_Obsolete_attributes()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
[System.Obsolete(""This class is obsolete!"")]
public class MyClass
{
[System.Obsolete(""This constructor is obsolete!"")]
public MyClass() { }
[System.Obsolete(""This method is obsolete!"")]
public void MyMethod() { }
[System.Obsolete(""This property is obsolete!"")]
public int MyProperty { get; set; }
[System.Obsolete(""This event is obsolete!"")]
public event System.EventHandler MyEvent;
[System.Obsolete(""This field is obsolete!"")]
public int MyField;
}
}"));
Assert.IsTrue(typeInfo.Obsolete);
Assert.AreEqual("This class is obsolete!", typeInfo.ObsoleteMessage);
Assert.IsTrue(typeInfo.Members.Single(m => m.Name == ".ctor").Obsolete);
Assert.AreEqual("This constructor is obsolete!", typeInfo.Members.Single(m => m.Name == ".ctor").ObsoleteMessage);
Assert.IsTrue(typeInfo.Members.Single(m => m.Name == "MyMethod").Obsolete);
Assert.AreEqual("This method is obsolete!", typeInfo.Members.Single(m => m.Name == "MyMethod").ObsoleteMessage);
Assert.IsTrue(typeInfo.Members.Single(m => m.Name == "MyProperty").Obsolete);
Assert.AreEqual("This property is obsolete!", typeInfo.Members.Single(m => m.Name == "MyProperty").ObsoleteMessage);
Assert.IsTrue(typeInfo.Members.Single(m => m.Name == "MyEvent").Obsolete);
Assert.AreEqual("This event is obsolete!", typeInfo.Members.Single(m => m.Name == "MyEvent").ObsoleteMessage);
Assert.IsTrue(typeInfo.Members.Single(m => m.Name == "MyField").Obsolete);
Assert.AreEqual("This field is obsolete!", typeInfo.Members.Single(m => m.Name == "MyField").ObsoleteMessage);
}
示例2: It_detects_the_kind_of_each_member
public void It_detects_the_kind_of_each_member()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass
{
public MyClass() { }
public void MyMethod() { }
public int MyProperty { get; set; }
public event System.EventHandler MyEvent;
public int MyField;
}
}"));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == ".ctor" && m.Kind == MemberKind.Constructor));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyMethod" && m.Kind == MemberKind.Method));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyProperty" && m.Kind == MemberKind.Property));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyEvent" && m.Kind == MemberKind.Event));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyField" && m.Kind == MemberKind.Field));
}
示例3: It_finds_the_default_constructor
public void It_finds_the_default_constructor()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass { }
}"));
Assert.AreEqual(1, typeInfo.Members.Count);
}
示例4: It_doesnt_find_virtual_properties_defined_in_base_types_that_are_overridden
public void It_doesnt_find_virtual_properties_defined_in_base_types_that_are_overridden()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType("MyNamespace.MyDerivedClass",
@"namespace MyNamespace
{
public class MyBaseClass
{
public virtual int MyProperty { get; set; }
}
public class MyDerivedClass : MyBaseClass
{
private MyDerivedClass() { }
public override int MyProperty { get; set; }
}
}"));
Assert.AreEqual(0, typeInfo.Members.Count);
}
示例5: It_finds_public_members
public void It_finds_public_members()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass
{
public MyClass() { }
public void MyMethod() { }
public int MyProperty { get; set; }
public event System.EventHandler MyEvent;
public int MyField;
}
}"));
Assert.AreEqual(5, typeInfo.Members.Count);
}
示例6: It_doesnt_find_virtual_methods_defined_in_System_Object_that_are_overridden
public void It_doesnt_find_virtual_methods_defined_in_System_Object_that_are_overridden()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass
{
private MyClass() { }
public override string ToString() { return null; }
}
}"));
Assert.AreEqual(0, typeInfo.Members.Count);
}
示例7: It_doesnt_find_the_special_value_field_for_enum_types
public void It_doesnt_find_the_special_value_field_for_enum_types()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public enum MyEnum
{
MyField1,
MyField2
}
}"));
Assert.AreEqual(2, typeInfo.Members.Count);
}
示例8: It_doesnt_find_property_get_and_set_methods
public void It_doesnt_find_property_get_and_set_methods()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass
{
private MyClass() { }
public int MyProperty { get { return 0; } set { } }
}
}"));
Assert.AreEqual(1, typeInfo.Members.Count);
}
示例9: It_doesnt_find_event_add_and_remove_methods
public void It_doesnt_find_event_add_and_remove_methods()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass
{
private MyClass() { }
public event System.EventHandler MyEvent { add { } remove { } }
}
}"));
Assert.AreEqual(1, typeInfo.Members.Count);
}
示例10: It_detects_the_type_of_each_member
public void It_detects_the_type_of_each_member()
{
var typeInfo = new TypeInfo();
typeInfo.ReadType(Compiler.GetType(
@"namespace MyNamespace
{
public class MyClass
{
public MyClass() { }
public string MyMethod() { return null; }
public int MyProperty { get; set; }
public event System.EventHandler MyEvent;
public int MyField;
}
}"));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == ".ctor" && m.Type == ""));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyMethod" && m.Type == "System.String"));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyProperty" && m.Type == "System.Int32"));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyEvent" && m.Type == "System.EventHandler"));
Assert.IsTrue(typeInfo.Members.Any(m => m.Name == "MyField" && m.Type == "System.Int32"));
}