public void NullString() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var dentist = module.GetType("Dentist"); var attribute = GetAttribute(dentist, "Foo"); Assert.IsNotNull(attribute); AssertArgument <string> (null, attribute.ConstructorArguments [0]); }
public void BoxedArraysArguments() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var sheep = module.GetType("Sheep"); var attribute = GetAttribute(sheep, "Foo"); Assert.IsNotNull(attribute); // [Foo (new object [] { "2", 2, 'c' }, new object [] { new object [] { 1, 2, 3}, null })] AssertCustomAttribute(".ctor ((Object:(Object[]:{(Object:(String:\"2\")), (Object:(Int32:2)), (Object:(Char:'c'))})), (Object:(Object[]:{(Object:(Object[]:{(Object:(Int32:1)), (Object:(Int32:2)), (Object:(Int32:3))})), (Object:(String:null))})))", attribute); }
public void ArrayMarshalerSized() { var module = SampleInputLoader.LoadAssembly("marshal").MainModule; var delegate_type = module.GetType("SomeMethod"); var parameter = delegate_type.GetMethod("Invoke").Parameters [1]; Assert.IsTrue(parameter.HasMarshalInfo); var array_info = (ArrayMarshalInfo)parameter.MarshalInfo; Assert.IsNotNull(array_info); Assert.AreEqual(0, array_info.SizeParameterMultiplier); }
public void GenericMethodDefinition() { ModuleDefinition module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var baz = module.GetType("Baz"); var gazonk = baz.GetMethod("Gazonk"); Assert.IsNotNull(gazonk); Assert.IsTrue(gazonk.HasGenericParameters); Assert.AreEqual(1, gazonk.GenericParameters.Count); Assert.AreEqual("TBang", gazonk.GenericParameters [0].Name); }
public void ArrayConstant() { var module = SampleInputLoader.LoadAssembly("Fields").MainModule; var panpan = module.GetType("PanPan"); Assert.IsNotNull(panpan); var field = panpan.GetField("ints"); Assert.IsTrue(field.HasConstant); Assert.IsNull(field.Constant); }
public void MethodRefDeclaredOnGenerics() { ModuleDefinition module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var type = module.GetType("Tamtam"); var beta = type.GetMethod("Beta"); var charlie = type.GetMethod("Charlie"); var new_list_beta = (MethodReference)beta.Body.Instructions.First(i => i.OpCode != Mi.Assemblies.Cil.OpCodes.Nop).Operand; var new_list_charlie = (MethodReference)charlie.Body.Instructions.First(i => i.OpCode != Mi.Assemblies.Cil.OpCodes.Nop).Operand; Assert.AreEqual("System.Collections.Generic.List`1<TBeta>", new_list_beta.DeclaringType.FullName); Assert.AreEqual("System.Collections.Generic.List`1<TCharlie>", new_list_charlie.DeclaringType.FullName); }
public void SimplePInvoke() { ModuleDefinition module = SampleInputLoader.LoadAssembly("Methods").MainModule; var bar = module.GetType("Bar"); var pan = bar.GetMethod("Pan"); Assert.IsTrue(pan.IsPInvokeImpl); Assert.IsNotNull(pan.PInvokeInfo); Assert.AreEqual("Pan", pan.PInvokeInfo.EntryPoint); Assert.IsNotNull(pan.PInvokeInfo.Module); Assert.AreEqual("foo.dll", pan.PInvokeInfo.Module.Name); }
public void AssemblyReferences() { var assembly = SampleInputLoader.LoadAssembly("hello"); var module = assembly.MainModule; Assert.AreEqual(1, module.AssemblyReferences.Count); var reference = module.AssemblyReferences [0]; Assert.AreEqual("mscorlib", reference.Name); Assert.AreEqual(new Version(2, 0, 0, 0), reference.Version); Assert.IsTrue(Enumerable.SequenceEqual(new byte [] { 0xB7, 0x7A, 0x5C, 0x56, 0x19, 0x34, 0xE0, 0x89 }, reference.PublicKeyToken)); }
public void GenericParameterConstant() { var module = SampleInputLoader.LoadAssembly("hello").MainModule; var foo = module.GetType("Foo"); var method = foo.GetMethod("GetState"); Assert.IsNotNull(method); var parameter = method.Parameters [1]; Assert.IsTrue(parameter.HasConstant); Assert.IsNull(parameter.Constant); }
public void ReadSemanticsFirst() { var module = SampleInputLoader.LoadAssembly("Properties").MainModule; var type = module.GetType("Baz"); var setter = type.GetMethod("set_Bingo"); Assert.AreEqual(MethodSemanticsAttributes.Setter, setter.SemanticsAttributes); var property = type.Properties.Where(p => p.Name == "Bingo").First(); Assert.AreEqual(setter, property.SetMethod); Assert.AreEqual(type.GetMethod("get_Bingo"), property.GetMethod); }
public void GenericConstraintOnGenericParameter() { var module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var duel = module.GetType("Duel`3"); Assert.AreEqual(3, duel.GenericParameters.Count); var t1 = duel.GenericParameters [0]; var t2 = duel.GenericParameters [1]; var t3 = duel.GenericParameters [2]; Assert.AreEqual(t1, t2.Constraints [0]); Assert.AreEqual(t2, t3.Constraints [0]); }
public void LinkedResource() { var assembly = SampleInputLoader.LoadAssembly("libres"); var module = assembly.MainModule; var resource = module.Resources.Where(res => res.Name == "linked.txt").First() as LinkedResource; Assert.IsNotNull(resource); Assert.AreEqual("linked.txt", resource.Name); Assert.AreEqual("linked.txt", resource.File); Assert.AreEqual(ResourceType.Linked, resource.ResourceType); Assert.IsTrue(resource.IsPublic); }
public void BoxedStringField() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var type = module.GetType("BoxedStringField"); var attribute = GetAttribute(type, "Foo"); Assert.IsNotNull(attribute); Assert.AreEqual(1, attribute.Fields.Count); var argument = attribute.Fields.Where(a => a.Name == "Pan").First(); AssertCustomAttributeArgument("(Object:(String:\"fiouuu\"))", argument); }
public void GenericForwardBaseType() { var module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var tamchild = module.GetType("TamChild"); Assert.IsNotNull(tamchild); Assert.IsNotNull(tamchild.BaseType); var generic_instance = tamchild.BaseType as GenericInstanceType; Assert.IsNotNull(generic_instance); Assert.AreEqual(1, generic_instance.GenericArguments.Count); Assert.AreEqual(module.GetType("Tamtam"), generic_instance.GenericArguments [0]); }
public void TypeExtentingGenericOfSelf() { var module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var rec_child = module.GetType("RecChild"); Assert.IsNotNull(rec_child); Assert.IsNotNull(rec_child.BaseType); var generic_instance = rec_child.BaseType as GenericInstanceType; Assert.IsNotNull(generic_instance); Assert.AreEqual(1, generic_instance.GenericArguments.Count); Assert.AreEqual(rec_child, generic_instance.GenericArguments [0]); }
public void TypeDefinitionEnum() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var zero = module.GetType("Zero"); var attribute = GetAttribute(zero, "Foo"); Assert.IsNotNull(attribute); Assert.AreEqual(1, attribute.ConstructorArguments.Count); Assert.AreEqual((short)2, attribute.ConstructorArguments [0].Value); Assert.AreEqual("Bingo", attribute.ConstructorArguments [0].Type.FullName); }
public void MarshalAsFixedStr() { var module = SampleInputLoader.LoadAssembly("marshal").MainModule; var boc = module.GetType("Boc"); var field = boc.GetField("a"); Assert.IsNotNull(field); Assert.IsTrue(field.HasMarshalInfo); var info = (FixedSysStringMarshalInfo)field.MarshalInfo; Assert.AreEqual(42, info.Size); }
public void EnumFieldsConstant() { var module = SampleInputLoader.LoadAssembly("Fields").MainModule; var pim = module.GetType("Pim"); Assert.IsNotNull(pim); var field = pim.GetField("Pam"); Assert.IsTrue(field.HasConstant); Assert.AreEqual(1, (int)field.Constant); field = pim.GetField("Poum"); Assert.AreEqual(2, (int)field.Constant); }
public void FieldNullTypeOf() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var truc = module.GetType("Machin"); var attribute = GetAttribute(truc, "Foo"); Assert.IsNotNull(attribute); var argument = attribute.Fields.Where(a => a.Name == "Chose").First().Argument; Assert.AreEqual("System.Type", argument.Type.FullName); Assert.IsNull(argument.Value); }
public void Primitives2() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var seagull = module.GetType("Seagull"); var attribute = GetAttribute(seagull, "Foo"); Assert.IsNotNull(attribute); AssertArgument <int> (-100000, attribute.ConstructorArguments [0]); AssertArgument <uint> (200000, attribute.ConstructorArguments [1]); AssertArgument <float> (12.12f, attribute.ConstructorArguments [2]); AssertArgument <long> (long.MaxValue, attribute.ConstructorArguments [3]); AssertArgument <ulong> (ulong.MaxValue, attribute.ConstructorArguments [4]); AssertArgument <double> (64.646464, attribute.ConstructorArguments [5]); }
public void VolatileField() { var module = SampleInputLoader.LoadAssembly("Fields").MainModule; var type = module.GetType("Bar"); Assert.IsTrue(type.HasFields); Assert.AreEqual(1, type.Fields.Count); var field = type.Fields [0]; Assert.AreEqual("oiseau", field.Name); Assert.AreEqual("System.Int32 modreq(System.Runtime.CompilerServices.IsVolatile)", field.FieldType.FullName); Assert.IsFalse(field.HasConstant); }
public void MarshalAsFixedArray() { var module = SampleInputLoader.LoadAssembly("marshal").MainModule; var boc = module.GetType("Boc"); var field = boc.GetField("b"); Assert.IsNotNull(field); Assert.IsTrue(field.HasMarshalInfo); var info = (FixedArrayMarshalInfo)field.MarshalInfo; Assert.AreEqual(12, info.Size); Assert.AreEqual(NativeType.Boolean, info.ElementType); }
public void TypeReferenceEnum() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var ace = module.GetType("Ace"); var attribute = GetAttribute(ace, "Foo"); Assert.IsNotNull(attribute); Assert.AreEqual(1, attribute.ConstructorArguments.Count); Assert.AreEqual((byte)0x04, attribute.ConstructorArguments [0].Value); Assert.AreEqual("System.Security.AccessControl.AceFlags", attribute.ConstructorArguments [0].Type.FullName); Assert.AreEqual(module, attribute.ConstructorArguments [0].Type.Module); }
public void MarshalAsI4() { var module = SampleInputLoader.LoadAssembly("marshal").MainModule; var bar = module.GetType("Bar"); var pan = bar.GetMethod("Pan"); Assert.AreEqual(1, pan.Parameters.Count); var parameter = pan.Parameters [0]; Assert.IsTrue(parameter.HasMarshalInfo); var info = parameter.MarshalInfo; Assert.AreEqual(typeof(MarshalInfo), info.GetType()); Assert.AreEqual(NativeType.I4, info.NativeType); }
public void GenericBaseType() { var module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var child = module.GetType("Child`1"); var child_t = child.GenericParameters [0]; Assert.IsNotNull(child_t); var instance = child.BaseType as GenericInstanceType; Assert.IsNotNull(instance); Assert.AreNotEqual(0, instance.MetadataToken.RID); Assert.AreEqual(child_t, instance.GenericArguments [0]); }
public void SimpleInterfaces() { var module = SampleInputLoader.LoadAssembly("types").MainModule; var ibaz = module.GetType("IBaz"); Assert.IsNotNull(ibaz); Assert.IsTrue(ibaz.HasInterfaces); var interfaces = ibaz.Interfaces; Assert.AreEqual(2, interfaces.Count); Assert.AreEqual("IBar", interfaces [0].FullName); Assert.AreEqual("IFoo", interfaces [1].FullName); }
public void Primitives1() { ModuleDefinition module = SampleInputLoader.LoadAssembly("CustomAttributes").MainModule; var steven = module.GetType("Steven"); var attribute = GetAttribute(steven, "Foo"); Assert.IsNotNull(attribute); AssertArgument <sbyte> (-12, attribute.ConstructorArguments [0]); AssertArgument <byte> (242, attribute.ConstructorArguments [1]); AssertArgument <bool> (true, attribute.ConstructorArguments [2]); AssertArgument <bool> (false, attribute.ConstructorArguments [3]); AssertArgument <ushort> (4242, attribute.ConstructorArguments [4]); AssertArgument <short> (-1983, attribute.ConstructorArguments [5]); AssertArgument <char> ('c', attribute.ConstructorArguments [6]); }
public void TypeLayout() { var module = SampleInputLoader.LoadAssembly("Layouts").MainModule; var foo = module.GetType("Foo"); Assert.IsNotNull(foo); Assert.IsTrue(foo.IsValueType); Assert.IsTrue(foo.HasLayoutInfo); Assert.AreEqual(16, foo.ClassSize); var babar = module.GetType("Babar"); Assert.IsNotNull(babar); Assert.IsFalse(babar.IsValueType); Assert.IsFalse(babar.HasLayoutInfo); }
public void ReturnGenericInstanceWithMethodParameter() { ModuleDefinition module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var baz = module.GetType("Baz"); var gazoo = baz.GetMethod("Gazoo"); Assert.IsNotNull(gazoo); var bar_bingo = gazoo.ReturnType; Assert.IsTrue(bar_bingo.IsGenericInstance); var bar_bingo_instance = (GenericInstanceType)bar_bingo; Assert.AreEqual(gazoo.GenericParameters [0], bar_bingo_instance.GenericArguments [0]); }
public void NestedEnumOfGenericTypeDefinition() { var module = SampleInputLoader.LoadAssembly("GenericsAsm").MainModule; var dang = module.GetType("Bongo`1/Dang"); Assert.IsNotNull(dang); var field = dang.GetField("Ding"); Assert.IsNotNull(field); Assert.AreEqual(2, field.Constant); field = dang.GetField("Dong"); Assert.IsNotNull(field); Assert.AreEqual(12, field.Constant); }