Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/Test
diff options
context:
space:
mode:
authorJb Evain <jbevain@gmail.com>2014-11-02 19:34:41 +0300
committerJb Evain <jbevain@gmail.com>2014-11-02 20:38:31 +0300
commit9c2281e6784c59fe961fd9a83c280c09740f2afe (patch)
tree33b199e2cbff896f44feef343243e78528380022 /Test
parenta64f56117305b4b7943298b38913bdf94e9f1fb6 (diff)
Update to ImportReference methods
Diffstat (limited to 'Test')
-rw-r--r--Test/Mono.Cecil.Tests/CustomAttributesTests.cs2
-rw-r--r--Test/Mono.Cecil.Tests/ImportCecilTests.cs68
-rw-r--r--Test/Mono.Cecil.Tests/ImportReflectionTests.cs48
3 files changed, 59 insertions, 59 deletions
diff --git a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
index 8344408..d299bf5 100644
--- a/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
+++ b/Test/Mono.Cecil.Tests/CustomAttributesTests.cs
@@ -396,7 +396,7 @@ namespace Mono.Cecil.Tests {
var file = Path.Combine (Path.GetTempPath (), "CaBlob.dll");
var module = ModuleDefinition.CreateModule ("CaBlob.dll", new ModuleParameters { Kind = ModuleKind.Dll, Runtime = TargetRuntime.Net_2_0 });
- var assembly_title_ctor = module.Import (typeof (System.Reflection.AssemblyTitleAttribute).GetConstructor (new [] {typeof (string)}));
+ var assembly_title_ctor = module.ImportReference (typeof (System.Reflection.AssemblyTitleAttribute).GetConstructor (new [] {typeof (string)}));
Assert.IsNotNull (assembly_title_ctor);
diff --git a/Test/Mono.Cecil.Tests/ImportCecilTests.cs b/Test/Mono.Cecil.Tests/ImportCecilTests.cs
index ae9a855..92f0cd7 100644
--- a/Test/Mono.Cecil.Tests/ImportCecilTests.cs
+++ b/Test/Mono.Cecil.Tests/ImportCecilTests.cs
@@ -29,10 +29,10 @@ namespace Mono.Cecil.Tests {
type.Methods.Add (method_by_ref);
- method_by_ref.MethodReturnType.ReturnType = module.Import (typeof (void).ToDefinition ());
+ method_by_ref.MethodReturnType.ReturnType = module.ImportReference (typeof (void).ToDefinition ());
- method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string).ToDefinition ())));
- method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (new ByReferenceType (typeof (string).ToDefinition ()))));
+ method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (typeof (string).ToDefinition ())));
+ method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (new ByReferenceType (typeof (string).ToDefinition ()))));
var m_il = method_by_ref.Body.GetILProcessor ();
m_il.Emit (OpCodes.Ldarg_1);
@@ -40,7 +40,7 @@ namespace Mono.Cecil.Tests {
m_il.Emit (OpCodes.Stind_Ref);
m_il.Emit (OpCodes.Ret);
- var v_0 = new VariableDefinition (module.Import (typeof (string).ToDefinition ()));
+ var v_0 = new VariableDefinition (module.ImportReference (typeof (string).ToDefinition ()));
body.Variables.Add (v_0);
var il = body.GetILProcessor ();
@@ -75,7 +75,7 @@ namespace Mono.Cecil.Tests {
{
var get_empty = Compile<Func<string>> ((module, body) => {
var il = body.GetILProcessor ();
- il.Emit (OpCodes.Ldsfld, module.Import (typeof (string).GetField ("Empty").ToDefinition ()));
+ il.Emit (OpCodes.Ldsfld, module.ImportReference (typeof (string).GetField ("Empty").ToDefinition ()));
il.Emit (OpCodes.Ret);
});
@@ -89,7 +89,7 @@ namespace Mono.Cecil.Tests {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Ldarg_1);
- il.Emit (OpCodes.Call, module.Import (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }).ToDefinition ()));
+ il.Emit (OpCodes.Call, module.ImportReference (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) }).ToDefinition ()));
il.Emit (OpCodes.Ret);
});
@@ -119,12 +119,12 @@ namespace Mono.Cecil.Tests {
public void ImportGenericField ()
{
var get_field = Compile<Func<Generic<string>, string>> ((module, body) => {
- var generic_def = module.Import (typeof (Generic<>)).Resolve ();
+ var generic_def = module.ImportReference (typeof (Generic<>)).Resolve ();
var field_def = generic_def.Fields.Where (f => f.Name == "Field").First ();
- var field_string = field_def.MakeGeneric (module.Import (typeof (string)));
+ var field_string = field_def.MakeGeneric (module.ImportReference (typeof (string)));
- var field_ref = module.Import (field_string);
+ var field_ref = module.ImportReference (field_string);
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -143,11 +143,11 @@ namespace Mono.Cecil.Tests {
public void ImportGenericMethod ()
{
var generic_identity = Compile<Func<Generic<int>, int, int>> ((module, body) => {
- var generic_def = module.Import (typeof (Generic<>)).Resolve ();
+ var generic_def = module.ImportReference (typeof (Generic<>)).Resolve ();
var method_def = generic_def.Methods.Where (m => m.Name == "Method").First ();
- var method_int = method_def.MakeGeneric (module.Import (typeof (int)));
- var method_ref = module.Import (method_int);
+ var method_int = method_def.MakeGeneric (module.ImportReference (typeof (int)));
+ var method_ref = module.ImportReference (method_int);
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -163,14 +163,14 @@ namespace Mono.Cecil.Tests {
public void ImportGenericMethodSpec ()
{
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => {
- var generic_def = module.Import (typeof (Generic<>)).Resolve ();
+ var generic_def = module.ImportReference (typeof (Generic<>)).Resolve ();
var method_def = generic_def.Methods.Where (m => m.Name == "GenericMethod").First ();
- var method_string = method_def.MakeGeneric (module.Import (typeof (string)));
+ var method_string = method_def.MakeGeneric (module.ImportReference (typeof (string)));
- var method_instance = method_string.MakeGenericMethod (module.Import (typeof (int)));
+ var method_instance = method_string.MakeGenericMethod (module.ImportReference (typeof (int)));
- var method_ref = module.Import (method_instance);
+ var method_ref = module.ImportReference (method_instance);
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -187,16 +187,16 @@ namespace Mono.Cecil.Tests {
public void ImportComplexGenericMethodSpec ()
{
var gen_spec_id = Compile<Func<Generic<string>, int, int>> ((module, body) => {
- var generic_def = module.Import (typeof (Generic<>)).Resolve ();
+ var generic_def = module.ImportReference (typeof (Generic<>)).Resolve ();
var method_def = generic_def.Methods.Where (m => m.Name == "ComplexGenericMethod").First ();
- var method_string = method_def.MakeGeneric (module.Import (typeof (string)));
- var method_instance = method_string.MakeGenericMethod (module.Import (typeof (int)));
- var method_ref = module.Import (method_instance);
+ var method_string = method_def.MakeGeneric (module.ImportReference (typeof (string)));
+ var method_instance = method_string.MakeGenericMethod (module.ImportReference (typeof (int)));
+ var method_ref = module.ImportReference (method_instance);
var field_def = generic_def.Fields.Where (f => f.Name == "Field").First ();
- var field_int = field_def.MakeGeneric (module.Import (typeof (int)));
- var field_ref = module.Import (field_int);
+ var field_int = field_def.MakeGeneric (module.ImportReference (typeof (int)));
+ var field_ref = module.ImportReference (field_int);
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
@@ -216,7 +216,7 @@ namespace Mono.Cecil.Tests {
var generic = typeof (Generic<>).ToDefinition ();
var module = ModuleDefinition.CreateModule ("foo", ModuleKind.Dll);
- var method = module.Import (generic.GetMethod ("Method"));
+ var method = module.ImportReference (generic.GetMethod ("Method"));
Assert.AreEqual ("T Mono.Cecil.Tests.ImportCecilTests/Generic`1::Method(T)", method.FullName);
}
@@ -258,29 +258,29 @@ namespace Mono.Cecil.Tests {
// by mixing open generics with 2 & 1 parameters, we make sure the right context is used (because otherwise, an exception will be thrown)
var type = typeof (ContextGeneric1Method2<>).MakeGenericType (typeof (ContextGeneric2Method1<,>));
var meth = type.GetMethod ("GenericMethod");
- var imported_type = module.Import (type);
- var method = module.Import (meth, imported_type);
+ var imported_type = module.ImportReference (type);
+ var method = module.ImportReference (meth, imported_type);
Assert.AreEqual ("G1 Mono.Cecil.Tests.ImportCecilTests/ContextGeneric1Method2`1<Mono.Cecil.Tests.ImportCecilTests/ContextGeneric2Method1`2<G2,H2>>::GenericMethod<R1,S1>(R1,S1)", method.FullName);
// and the other way around
type = typeof (ContextGeneric2Method1<,>).MakeGenericType (typeof (ContextGeneric1Method2<>), typeof (IList<>));
meth = type.GetMethod ("GenericMethod");
- imported_type = module.Import (type);
- method = module.Import (meth, imported_type);
+ imported_type = module.ImportReference (type);
+ method = module.ImportReference (meth, imported_type);
Assert.AreEqual ("R2 Mono.Cecil.Tests.ImportCecilTests/ContextGeneric2Method1`2<Mono.Cecil.Tests.ImportCecilTests/ContextGeneric1Method2`1<G1>,System.Collections.Generic.IList`1<T>>::GenericMethod<R2>(G2,H2)", method.FullName);
// not sure about this one
type = typeof (NestedGenericsA<string>.NestedGenericsB<int>.NestedGenericsC<float>);
meth = type.GetMethod ("GenericMethod");
- imported_type = module.Import (type);
- method = module.Import (meth, imported_type);
+ imported_type = module.ImportReference (type);
+ method = module.ImportReference (meth, imported_type);
Assert.AreEqual ("A Mono.Cecil.Tests.ImportCecilTests/NestedGenericsA`1/NestedGenericsB`1/NestedGenericsC`1<System.String,System.Int32,System.Single>::GenericMethod(B,C)", method.FullName);
// We need both the method & type !
type = typeof (Generic<>).MakeGenericType (typeof (string));
meth = type.GetMethod ("ComplexGenericMethod");
- imported_type = module.Import (type);
- method = module.Import (meth, imported_type);
+ imported_type = module.ImportReference (type);
+ method = module.ImportReference (meth, imported_type);
Assert.AreEqual ("Mono.Cecil.Tests.ImportCecilTests/Generic`1<TS> Mono.Cecil.Tests.ImportCecilTests/Generic`1<System.String>::ComplexGenericMethod<TS>(T,TS)", method.FullName);
}
@@ -326,7 +326,7 @@ namespace Mono.Cecil.Tests {
"",
name,
TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract,
- module.Import (typeof (object)));
+ module.ImportReference (typeof (object)));
module.Types.Add (type);
@@ -349,10 +349,10 @@ namespace Mono.Cecil.Tests {
type.Methods.Add (method);
- method.MethodReturnType.ReturnType = module.Import (pattern.ReturnType);
+ method.MethodReturnType.ReturnType = module.ImportReference (pattern.ReturnType);
foreach (var parameter_pattern in pattern.GetParameters ())
- method.Parameters.Add (new ParameterDefinition (module.Import (parameter_pattern.ParameterType)));
+ method.Parameters.Add (new ParameterDefinition (module.ImportReference (parameter_pattern.ParameterType)));
return method;
}
diff --git a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
index 6ded91c..cef6d20 100644
--- a/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
+++ b/Test/Mono.Cecil.Tests/ImportReflectionTests.cs
@@ -54,10 +54,10 @@ namespace Mono.Cecil.Tests {
type.Methods.Add (method_by_ref);
- method_by_ref.MethodReturnType.ReturnType = module.Import (typeof (void));
+ method_by_ref.MethodReturnType.ReturnType = module.ImportReference (typeof (void));
- method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string))));
- method_by_ref.Parameters.Add (new ParameterDefinition (module.Import (typeof (string).MakeByRefType ())));
+ method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (typeof (string))));
+ method_by_ref.Parameters.Add (new ParameterDefinition (module.ImportReference (typeof (string).MakeByRefType ())));
var m_il = method_by_ref.Body.GetILProcessor ();
m_il.Emit (OpCodes.Ldarg_1);
@@ -65,7 +65,7 @@ namespace Mono.Cecil.Tests {
m_il.Emit (OpCodes.Stind_Ref);
m_il.Emit (OpCodes.Ret);
- var v_0 = new VariableDefinition (module.Import (typeof (string)));
+ var v_0 = new VariableDefinition (module.ImportReference (typeof (string)));
body.Variables.Add (v_0);
var il = body.GetILProcessor ();
@@ -100,7 +100,7 @@ namespace Mono.Cecil.Tests {
{
var get_empty = Compile<Func<string>> ((module, body) => {
var il = body.GetILProcessor ();
- il.Emit (OpCodes.Ldsfld, module.Import (typeof (string).GetField ("Empty")));
+ il.Emit (OpCodes.Ldsfld, module.ImportReference (typeof (string).GetField ("Empty")));
il.Emit (OpCodes.Ret);
});
@@ -114,7 +114,7 @@ namespace Mono.Cecil.Tests {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Ldarg_1);
- il.Emit (OpCodes.Call, module.Import (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) })));
+ il.Emit (OpCodes.Call, module.ImportReference (typeof (string).GetMethod ("Concat", new [] { typeof (string), typeof (string) })));
il.Emit (OpCodes.Ret);
});
@@ -146,7 +146,7 @@ namespace Mono.Cecil.Tests {
var get_field = Compile<Func<Generic<string>, string>> ((module, body) => {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
- il.Emit (OpCodes.Ldfld, module.Import (typeof (Generic<string>).GetField ("Field")));
+ il.Emit (OpCodes.Ldfld, module.ImportReference (typeof (Generic<string>).GetField ("Field")));
il.Emit (OpCodes.Ret);
});
@@ -164,7 +164,7 @@ namespace Mono.Cecil.Tests {
var il = body.GetILProcessor ();
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Ldarg_1);
- il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<int>).GetMethod ("Method")));
+ il.Emit (OpCodes.Callvirt, module.ImportReference (typeof (Generic<int>).GetMethod ("Method")));
il.Emit (OpCodes.Ret);
});
@@ -179,7 +179,7 @@ namespace Mono.Cecil.Tests {
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Ldarg_1);
- il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<string>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))));
+ il.Emit (OpCodes.Callvirt, module.ImportReference (typeof (Generic<string>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))));
il.Emit (OpCodes.Ret);
});
@@ -194,8 +194,8 @@ namespace Mono.Cecil.Tests {
il.Emit (OpCodes.Ldarg_0);
il.Emit (OpCodes.Ldnull);
il.Emit (OpCodes.Ldarg_1);
- il.Emit (OpCodes.Callvirt, module.Import (typeof (Generic<string>).GetMethod ("ComplexGenericMethod").MakeGenericMethod (typeof (int))));
- il.Emit (OpCodes.Ldfld, module.Import (typeof (Generic<string>).GetField ("Field")));
+ il.Emit (OpCodes.Callvirt, module.ImportReference (typeof (Generic<string>).GetMethod ("ComplexGenericMethod").MakeGenericMethod (typeof (int))));
+ il.Emit (OpCodes.Ldfld, module.ImportReference (typeof (Generic<string>).GetField ("Field")));
il.Emit (OpCodes.Ret);
});
@@ -211,8 +211,8 @@ namespace Mono.Cecil.Tests {
{
var module = typeof (Foo<>).ToDefinition ().Module;
- var foo_def = module.Import (typeof (Foo<>));
- var foo_open = module.Import (typeof (Foo<>), foo_def);
+ var foo_def = module.ImportReference (typeof (Foo<>));
+ var foo_open = module.ImportReference (typeof (Foo<>), foo_def);
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1", foo_def.FullName);
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>", foo_open.FullName);
@@ -227,7 +227,7 @@ namespace Mono.Cecil.Tests {
var foo_def = typeof (Foo<>).ToDefinition ();
var module = foo_def.Module;
- var generic_foo = module.Import (generic_list_foo_open, foo_def);
+ var generic_foo = module.ImportReference (generic_list_foo_open, foo_def);
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>",
generic_foo.FullName);
@@ -242,7 +242,7 @@ namespace Mono.Cecil.Tests {
var foo_def = typeof (Foo<>).ToDefinition ();
var module = foo_def.Module;
- var generic_foo = module.Import (generic_foo_open, foo_def);
+ var generic_foo = module.ImportReference (generic_foo_open, foo_def);
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Generic`1<Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>>",
generic_foo.FullName);
@@ -257,7 +257,7 @@ namespace Mono.Cecil.Tests {
var foo_def = typeof (Foo<>).ToDefinition ();
var module = foo_def.Module;
- var array_foo = module.Import (foo_open_array, foo_def);
+ var array_foo = module.ImportReference (foo_open_array, foo_def);
Assert.AreEqual ("Mono.Cecil.Tests.ImportReflectionTests/Foo`1<TFoo>[]",
array_foo.FullName);
@@ -273,7 +273,7 @@ namespace Mono.Cecil.Tests {
var foo_def = typeof (Foo<>).ToDefinition ();
var module = foo_def.Module;
- var generic_field = module.Import (generic_list_foo_open_field, foo_def);
+ var generic_field = module.ImportReference (generic_list_foo_open_field, foo_def);
Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Field",
generic_field.FullName);
@@ -289,7 +289,7 @@ namespace Mono.Cecil.Tests {
var foo_def = typeof (Foo<>).ToDefinition ();
var module = foo_def.Module;
- var generic_method = module.Import (generic_list_foo_open_method, foo_def);
+ var generic_method = module.ImportReference (generic_list_foo_open_method, foo_def);
Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<System.Collections.Generic.List`1<TFoo>>::Method(T)",
generic_method.FullName);
@@ -300,7 +300,7 @@ namespace Mono.Cecil.Tests {
{
var module = typeof (Generic<>).ToDefinition ().Module;
- var method = module.Import (typeof (Generic<>).GetMethod ("Method"));
+ var method = module.ImportReference (typeof (Generic<>).GetMethod ("Method"));
Assert.AreEqual ("T Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::Method(T)", method.FullName);
}
@@ -310,11 +310,11 @@ namespace Mono.Cecil.Tests {
{
var module = typeof (Generic<>).ToDefinition ().Module;
- var generic_method = module.Import (typeof (Generic<>).GetMethod ("GenericMethod"));
+ var generic_method = module.ImportReference (typeof (Generic<>).GetMethod ("GenericMethod"));
Assert.AreEqual ("TS Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::GenericMethod(T,TS)", generic_method.FullName);
- generic_method = module.Import (typeof (Generic<>).GetMethod ("GenericMethod"), generic_method);
+ generic_method = module.ImportReference (typeof (Generic<>).GetMethod ("GenericMethod"), generic_method);
Assert.AreEqual ("TS Mono.Cecil.Tests.ImportReflectionTests/Generic`1<T>::GenericMethod<TS>(T,TS)", generic_method.FullName);
}
@@ -361,7 +361,7 @@ namespace Mono.Cecil.Tests {
"",
name,
TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Abstract,
- module.Import (typeof (object)));
+ module.ImportReference (typeof (object)));
module.Types.Add (type);
@@ -384,10 +384,10 @@ namespace Mono.Cecil.Tests {
type.Methods.Add (method);
- method.MethodReturnType.ReturnType = module.Import (pattern.ReturnType);
+ method.MethodReturnType.ReturnType = module.ImportReference (pattern.ReturnType);
foreach (var parameter_pattern in pattern.GetParameters ())
- method.Parameters.Add (new ParameterDefinition (module.Import (parameter_pattern.ParameterType)));
+ method.Parameters.Add (new ParameterDefinition (module.ImportReference (parameter_pattern.ParameterType)));
return method;
}