本文整理汇总了C#中ModuleDefinition.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleDefinition.GetType方法的具体用法?C# ModuleDefinition.GetType怎么用?C# ModuleDefinition.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModuleDefinition
的用法示例。
在下文中一共展示了ModuleDefinition.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public void Main (ModuleDefinition module)
{
var type = module.GetType ("Program");
var main = type.GetMethod ("Main");
AssertCode (@"
.locals init (System.Int32 i)
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0000: ldc.i4.0
IL_0001: stloc.0
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0002: br IL_0013
.line 8,8:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_0007: ldarg.0
IL_0008: ldloc.0
IL_0009: ldelem.ref
IL_000a: call System.Void Program::Print(System.String)
.line 7,7:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_000f: ldloc.0
IL_0010: ldc.i4.1
IL_0011: add
IL_0012: stloc.0
IL_0013: ldloc.0
IL_0014: ldarg.0
IL_0015: ldlen
IL_0016: conv.i4
IL_0017: blt IL_0007
.line 10,10:0,0 'C:\sources\cecil\symbols\Mono.Cecil.Mdb\Test\Resources\assemblies\hello.cs'
IL_001c: ldc.i4.0
IL_001d: ret
", main);
}
示例2: OtherMethod
public void OtherMethod(ModuleDefinition module)
{
var type = module.GetType ("Others");
Assert.IsTrue (type.HasProperties);
var properties = type.Properties;
Assert.AreEqual (1, properties.Count);
var property = properties [0];
Assert.IsNotNull (property);
Assert.AreEqual ("Context", property.Name);
Assert.IsNotNull (property.PropertyType);
Assert.AreEqual ("System.String", property.PropertyType.FullName);
Assert.IsTrue (property.HasOtherMethods);
Assert.AreEqual (2, property.OtherMethods.Count);
var other = property.OtherMethods [0];
Assert.AreEqual ("let_Context", other.Name);
other = property.OtherMethods [1];
Assert.AreEqual ("bet_Context", other.Name);
}
示例3: PrintStringEmpty
public void PrintStringEmpty (ModuleDefinition module)
{
var foo = module.GetType ("Foo");
Assert.IsNotNull (foo);
var print_empty = foo.GetMethod ("PrintEmpty");
Assert.IsNotNull (print_empty);
AssertCode (@"
.locals ()
IL_0000: ldsfld System.String System.String::Empty
IL_0005: call System.Void System.Console::WriteLine(System.String)
IL_000a: ret
", print_empty);
}
示例4: BasicDocument
public void BasicDocument (ModuleDefinition module)
{
var type = module.GetType ("VBConsApp.Program");
var method = type.GetMethod ("Main");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\tmp\VBConsApp\Program.vb", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.Basic, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
示例5: Document
public void Document (ModuleDefinition module)
{
var type = module.GetType ("Program");
var method = type.GetMethod ("Main");
var sequence_point = method.Body.Instructions.Where (i => i.SequencePoint != null).First ().SequencePoint;
var document = sequence_point.Document;
Assert.IsNotNull (document);
Assert.AreEqual (@"c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs", document.Url);
Assert.AreEqual (DocumentType.Text, document.Type);
Assert.AreEqual (DocumentHashAlgorithm.None, document.HashAlgorithm);
Assert.AreEqual (DocumentLanguage.CSharp, document.Language);
Assert.AreEqual (DocumentLanguageVendor.Microsoft, document.LanguageVendor);
}
示例6: Branch
public void Branch (ModuleDefinition module)
{
var lib = module.GetType ("Library");
Assert.IsNotNull (lib);
var method = lib.GetMethod ("GetHelloString");
Assert.IsNotNull (method);
AssertCode (@"
.locals init (System.String V_0)
IL_0000: nop
IL_0001: ldstr ""hello world of tomorrow""
IL_0006: stloc.0
IL_0007: br.s IL_0009
IL_0009: ldloc.0
IL_000a: ret
", method);
}
示例7: Main
public void Main (ModuleDefinition module)
{
var type = module.GetType ("Program");
var main = type.GetMethod ("Main");
AssertCode (@"
.locals init (System.Int32 i, System.Int32 CS$1$0000, System.Boolean CS$4$0001)
.line 6,6:2,3 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0000: nop
.line 7,7:8,18 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0001: ldc.i4.0
IL_0002: stloc.0
.line 16707566,16707566:0,0 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0003: br.s IL_0012
.line 8,8:4,21 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0005: ldarg.0
IL_0006: ldloc.0
IL_0007: ldelem.ref
IL_0008: call System.Void Program::Print(System.String)
IL_000d: nop
.line 7,7:36,39 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_000e: ldloc.0
IL_000f: ldc.i4.1
IL_0010: add
IL_0011: stloc.0
.line 7,7:19,34 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0012: ldloc.0
IL_0013: ldarg.0
IL_0014: ldlen
IL_0015: conv.i4
IL_0016: clt
IL_0018: stloc.2
.line 16707566,16707566:0,0 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0019: ldloc.2
IL_001a: brtrue.s IL_0005
.line 10,10:3,12 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_001c: ldc.i4.0
IL_001d: stloc.1
IL_001e: br.s IL_0020
.line 11,11:2,3 'c:\sources\cecil\symbols\Mono.Cecil.Pdb\Test\Resources\assemblies\test.cs'
IL_0020: ldloc.1
IL_0021: ret
", main);
}
示例8: GetAllTypesTest
public void GetAllTypesTest (ModuleDefinition module)
{
var sequence = new [] {
module.GetType ("<Module>"),
module.GetType ("Foo"),
module.GetType ("Foo/Bar"),
module.GetType ("Foo/Gazonk"),
module.GetType ("Foo/Gazonk/Baz"),
module.GetType ("Pan"),
};
Assert.IsTrue (sequence.SequenceEqual (module.GetAllTypes ()));
}
示例9: AbstractMethod
public void AbstractMethod(ModuleDefinition module)
{
var type = module.GetType ("Foo");
Assert.IsTrue (type.HasProperties);
var properties = type.Properties;
Assert.AreEqual (3, properties.Count);
var property = properties [0];
Assert.IsNotNull (property);
Assert.AreEqual ("Bar", property.Name);
Assert.IsNotNull (property.PropertyType);
Assert.AreEqual ("System.Int32", property.PropertyType.FullName);
Assert.IsNotNull (property.GetMethod);
Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
Assert.IsNull (property.SetMethod);
property = properties [1];
Assert.IsNotNull (property);
Assert.AreEqual ("Baz", property.Name);
Assert.IsNotNull (property.PropertyType);
Assert.AreEqual ("System.String", property.PropertyType.FullName);
Assert.IsNotNull (property.GetMethod);
Assert.AreEqual (MethodSemanticsAttributes.Getter, property.GetMethod.SemanticsAttributes);
Assert.IsNotNull (property.SetMethod);
Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);
property = properties [2];
Assert.IsNotNull (property);
Assert.AreEqual ("Gazonk", property.Name);
Assert.IsNotNull (property.PropertyType);
Assert.AreEqual ("System.String", property.PropertyType.FullName);
Assert.IsNull (property.GetMethod);
Assert.IsNotNull (property.SetMethod);
Assert.AreEqual (MethodSemanticsAttributes.Setter, property.SetMethod.SemanticsAttributes);
}
示例10: Switch
public void Switch (ModuleDefinition module)
{
var program = module.GetType ("Program");
Assert.IsNotNull (program);
var method = program.GetMethod ("Main");
Assert.IsNotNull (method);
AssertCode (@"
.locals init (System.Int32 V_0)
IL_0000: ldarg.0
IL_0001: ldlen
IL_0002: conv.i4
IL_0003: stloc.0
IL_0004: ldloc.0
IL_0005: ldc.i4.8
IL_0006: bgt.s IL_0026
IL_0008: ldloc.0
IL_0009: ldc.i4.1
IL_000a: sub
IL_000b: switch (IL_0032, IL_0034, IL_0038, IL_0034)
IL_0020: ldloc.0
IL_0021: ldc.i4.8
IL_0022: beq.s IL_0036
IL_0024: br.s IL_0038
IL_0026: ldloc.0
IL_0027: ldc.i4.s 16
IL_0029: beq.s IL_0036
IL_002b: ldloc.0
IL_002c: ldc.i4.s 32
IL_002e: beq.s IL_0036
IL_0030: br.s IL_0038
IL_0032: ldc.i4.0
IL_0033: ret
IL_0034: ldc.i4.1
IL_0035: ret
IL_0036: ldc.i4.2
IL_0037: ret
IL_0038: ldc.i4.s 42
IL_003a: ret
", method);
}
示例11: MultiplyMethod
public void MultiplyMethod (ModuleDefinition module)
{
var foo = module.GetType ("Foo");
Assert.IsNotNull (foo);
var bar = foo.GetMethod ("Bar");
Assert.IsNotNull (bar);
Assert.IsTrue (bar.IsIL);
AssertCode (@"
.locals init (System.Int32 V_0)
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: mul
IL_0003: stloc.0
IL_0004: ldloc.0
IL_0005: call System.Void Foo::Baz(System.Int32)
IL_000a: ret
", bar);
}
示例12: ToPermissionSetFromSecurityAttribute
public void ToPermissionSetFromSecurityAttribute (ModuleDefinition module)
{
var type = module.GetType ("SubLibrary");
Assert.IsTrue (type.HasSecurityDeclarations);
Assert.AreEqual (1, type.SecurityDeclarations.Count);
var declaration = type.SecurityDeclarations [0];
var permission_set = declaration.ToPermissionSet ();
Assert.IsNotNull (permission_set);
string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
}
示例13: GetType
static TypeDefinition GetType (ModuleDefinition module, TypeReference type)
{
if (!type.IsNested)
return module.GetType (type.Namespace, type.Name);
var declaring_type = type.DeclaringType.Resolve ();
if (declaring_type == null)
return null;
return declaring_type.GetNestedType (type.Name);
}
示例14: ThisParameter
public void ThisParameter (ModuleDefinition module)
{
var type = module.GetType ("Foo");
var method = type.GetMethod ("Gazonk");
Assert.IsNotNull (method);
AssertCode (@"
.locals ()
IL_0000: ldarg 0
IL_0004: pop
IL_0005: ret
", method);
Assert.AreEqual (method.Body.ThisParameter, method.Body.Instructions [0].Operand);
}
示例15: FilterMaxStack
public void FilterMaxStack (ModuleDefinition module)
{
var type = module.GetType ("Foo");
var method = type.GetMethod ("TestFilter");
Assert.IsNotNull (method);
Assert.AreEqual (2, method.Body.MaxStackSize);
}