diff --git a/.nuspec/Xamarin.Forms.Debug.targets b/.nuspec/Xamarin.Forms.Debug.targets
index ce1977138..6ef2ffe38 100644
--- a/.nuspec/Xamarin.Forms.Debug.targets
+++ b/.nuspec/Xamarin.Forms.Debug.targets
@@ -63,8 +63,9 @@
diff --git a/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs
index 5f1826db5..0edc5f59d 100644
--- a/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs
@@ -26,7 +26,7 @@ namespace Xamarin.Forms.Build.Tasks
md.IsStatic &&
md.IsPublic &&
md.Parameters.Count == 1 &&
- md.Parameters[0].ParameterType.InheritsFromOrImplements(module.Import(typeof(BindableObject))), module).SingleOrDefault()?.Item1;
+ md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(typeof(BindableObject))), module).SingleOrDefault()?.Item1;
if (getter == null)
throw new XamlParseException($"Missing a public static Get{bpName} or a public instance property getter for the attached property \"{bpRef.DeclaringType}.{bpRef.Name}\"", iXmlLineInfo);
@@ -43,7 +43,7 @@ namespace Xamarin.Forms.Build.Tasks
md.IsStatic &&
md.IsPublic &&
md.Parameters.Count == 1 &&
- md.Parameters[0].ParameterType.InheritsFromOrImplements(module.Import(typeof(BindableObject))), module).SingleOrDefault()?.Item1;
+ md.Parameters[0].ParameterType.InheritsFromOrImplements(module.ImportReference(typeof(BindableObject))), module).SingleOrDefault()?.Item1;
var attributes = new List();
if (property != null && property.HasCustomAttributes)
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs
index c78e51840..b46d22dc5 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs
@@ -84,8 +84,8 @@ namespace Xamarin.Forms.Core.XamlC
TypeReference declaringTypeReference;
FieldReference bpRef = typeRef.GetField(fd => fd.Name == $"{propertyName}Property" && fd.IsStatic && fd.IsPublic, out declaringTypeReference);
if (bpRef != null) {
- bpRef = module.Import(bpRef.ResolveGenericParameters(declaringTypeReference));
- bpRef.FieldType = module.Import(bpRef.FieldType);
+ bpRef = module.ImportReference(bpRef.ResolveGenericParameters(declaringTypeReference));
+ bpRef.FieldType = module.ImportReference(bpRef.FieldType);
}
return bpRef;
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindingTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindingTypeConverter.cs
index 74990a86d..8c8f0411a 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindingTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindingTypeConverter.cs
@@ -17,8 +17,8 @@ namespace Xamarin.Forms.Core.XamlC
if (IsNullOrEmpty(value))
throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(Binding)}", node);
- var bindingCtor = module.Import(typeof(Binding)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 6);
- var bindingCtorRef = module.Import(bindingCtor);
+ var bindingCtor = module.ImportReference(typeof(Binding)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 6);
+ var bindingCtorRef = module.ImportReference(bindingCtor);
yield return Instruction.Create(OpCodes.Ldstr, value);
yield return Instruction.Create(OpCodes.Ldc_I4, (int)BindingMode.Default);
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/BoundsTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/BoundsTypeConverter.cs
index 1cc64fc55..88550bf14 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/BoundsTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/BoundsTypeConverter.cs
@@ -65,8 +65,8 @@ namespace Xamarin.Forms.Core.XamlC
yield return Instruction.Create(OpCodes.Ldc_R8, w);
yield return Instruction.Create(OpCodes.Ldc_R8, h);
- var rectangleCtor = module.Import(typeof(Rectangle)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 4);
- var rectangleCtorRef = module.Import(rectangleCtor);
+ var rectangleCtor = module.ImportReference(typeof(Rectangle)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 4);
+ var rectangleCtorRef = module.ImportReference(rectangleCtor);
yield return Instruction.Create(OpCodes.Newobj, rectangleCtorRef);
}
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/ColorTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/ColorTypeConverter.cs
index 395279540..cfb9d0165 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/ColorTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/ColorTypeConverter.cs
@@ -25,10 +25,10 @@ namespace Xamarin.Forms.Core.XamlC
yield return Instruction.Create(OpCodes.Ldc_R8, color.G);
yield return Instruction.Create(OpCodes.Ldc_R8, color.B);
yield return Instruction.Create(OpCodes.Ldc_R8, color.A);
- var colorCtor = module.Import(typeof(Color)).Resolve().Methods.FirstOrDefault(
+ var colorCtor = module.ImportReference(typeof(Color)).Resolve().Methods.FirstOrDefault(
md => md.IsConstructor && md.Parameters.Count == 4 &&
md.Parameters.All(p => p.ParameterType.FullName == "System.Double"));
- var colorCtorRef = module.Import(colorCtor);
+ var colorCtorRef = module.ImportReference(colorCtor);
yield return Instruction.Create(OpCodes.Newobj, colorCtorRef);
yield break;
}
@@ -36,14 +36,14 @@ namespace Xamarin.Forms.Core.XamlC
if (parts.Length == 1 || (parts.Length == 2 && parts [0] == "Color")) {
var color = parts [parts.Length - 1];
- var field = module.Import(typeof(Color)).Resolve().Fields.SingleOrDefault(fd => fd.Name == color && fd.IsStatic);
+ var field = module.ImportReference(typeof(Color)).Resolve().Fields.SingleOrDefault(fd => fd.Name == color && fd.IsStatic);
if (field != null) {
- yield return Instruction.Create(OpCodes.Ldsfld, module.Import(field));
+ yield return Instruction.Create(OpCodes.Ldsfld, module.ImportReference(field));
yield break;
}
- var propertyGetter = module.Import(typeof(Color)).Resolve().Properties.SingleOrDefault(pd => pd.Name == color && pd.GetMethod.IsStatic)?.GetMethod;
+ var propertyGetter = module.ImportReference(typeof(Color)).Resolve().Properties.SingleOrDefault(pd => pd.Name == color && pd.GetMethod.IsStatic)?.GetMethod;
if (propertyGetter != null) {
- yield return Instruction.Create(OpCodes.Call, module.Import(propertyGetter));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(propertyGetter));
yield break;
}
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs
index 18b1810cc..e166247da 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs
@@ -20,8 +20,8 @@ namespace Xamarin.Forms.Core.XamlC
yield return Instruction.Create(OpCodes.Ldc_R8, size);
- var constantDef = module.Import(typeof(Constraint)).Resolve().Methods.FirstOrDefault(md => md.IsStatic && md.Name == "Constant");
- var constantRef = module.Import(constantDef);
+ var constantDef = module.ImportReference(typeof(Constraint)).Resolve().Methods.FirstOrDefault(md => md.IsStatic && md.Name == "Constant");
+ var constantRef = module.ImportReference(constantDef);
yield return Instruction.Create(OpCodes.Call, constantRef);
}
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/ICompiledTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/ICompiledTypeConverter.cs
index 5ed88d0a5..d594cb736 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/ICompiledTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/ICompiledTypeConverter.cs
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using Mono.Cecil.Cil;
using Mono.Cecil;
-using System.Xml;
+using Xamarin.Forms.Xaml;
+using System;
namespace Xamarin.Forms.Xaml
{
@@ -9,4 +10,18 @@ namespace Xamarin.Forms.Xaml
{
IEnumerable ConvertFromString(string value, ModuleDefinition module, BaseNode node);
}
+}
+
+namespace Xamarin.Forms.Core.XamlC
+{
+ //only used in unit tests to make sure the compiled InitializeComponent is invoked
+ class IsCompiledTypeConverter : ICompiledTypeConverter
+ {
+ public IEnumerable ConvertFromString(string value, ModuleDefinition module, BaseNode node)
+ {
+ if (value != "IsCompiled?")
+ throw new Exception();
+ yield return Instruction.Create(OpCodes.Ldc_I4_1);
+ }
+ }
}
\ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/LayoutOptionsConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/LayoutOptionsConverter.cs
index e252ed9d1..d7c4597f6 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/LayoutOptionsConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/LayoutOptionsConverter.cs
@@ -23,9 +23,9 @@ namespace Xamarin.Forms.Core.XamlC
if (parts.Length == 1 || (parts.Length == 2 && parts [0] == "LayoutOptions")) {
var options = parts [parts.Length - 1];
- var field = module.Import(typeof(LayoutOptions)).Resolve().Fields.SingleOrDefault(fd => fd.Name == options && fd.IsStatic);
+ var field = module.ImportReference(typeof(LayoutOptions)).Resolve().Fields.SingleOrDefault(fd => fd.Name == options && fd.IsStatic);
if (field != null) {
- yield return Instruction.Create(OpCodes.Ldsfld, module.Import(field));
+ yield return Instruction.Create(OpCodes.Ldsfld, module.ImportReference(field));
yield break;
}
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/ListStringTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/ListStringTypeConverter.cs
index 62d7d69db..3f1c05697 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/ListStringTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/ListStringTypeConverter.cs
@@ -20,13 +20,13 @@ namespace Xamarin.Forms.Core.XamlC
}
var parts = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
- var listCtor = module.Import(typeof(List<>)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters[0].ParameterType.FullName == "System.Int32");
- var listCtorRef = module.Import(listCtor);
- listCtorRef = module.Import(listCtorRef.ResolveGenericParameters(module.Import(typeof(List)), module));
+ var listCtor = module.ImportReference(typeof(List<>)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters[0].ParameterType.FullName == "System.Int32");
+ var listCtorRef = module.ImportReference(listCtor);
+ listCtorRef = module.ImportReference(listCtorRef.ResolveGenericParameters(module.ImportReference(typeof(List)), module));
- var adder = module.Import(typeof(ICollection<>)).Resolve().Methods.FirstOrDefault(md => md.Name == "Add" && md.Parameters.Count == 1);
- var adderRef = module.Import(adder);
- adderRef = module.Import(adderRef.ResolveGenericParameters(module.Import(typeof(ICollection)), module));
+ var adder = module.ImportReference(typeof(ICollection<>)).Resolve().Methods.FirstOrDefault(md => md.Name == "Add" && md.Parameters.Count == 1);
+ var adderRef = module.ImportReference(adder);
+ adderRef = module.ImportReference(adderRef.ResolveGenericParameters(module.ImportReference(typeof(ICollection)), module));
yield return Instruction.Create(OpCodes.Ldc_I4, parts.Count);
yield return Instruction.Create(OpCodes.Newobj, listCtorRef);
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
index a7eda95e1..1175dd221 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
@@ -40,8 +40,8 @@ namespace Xamarin.Forms.Core.XamlC
yield return Instruction.Create(OpCodes.Ldc_R8, w);
yield return Instruction.Create(OpCodes.Ldc_R8, h);
- var rectangleCtor = module.Import(typeof(Rectangle)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 4);
- var rectangleCtorRef = module.Import(rectangleCtor);
+ var rectangleCtor = module.ImportReference(typeof(Rectangle)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 4);
+ var rectangleCtorRef = module.ImportReference(rectangleCtor);
yield return Instruction.Create(OpCodes.Newobj, rectangleCtorRef);
}
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs
index e16a8b01a..adca4d898 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs
@@ -42,8 +42,8 @@ namespace Xamarin.Forms.Core.XamlC
{
foreach (var d in args)
yield return Instruction.Create(OpCodes.Ldc_R8, d);
- var thicknessCtor = module.Import(typeof(Thickness)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == args.Length);
- var thicknessCtorRef = module.Import(thicknessCtor);
+ var thicknessCtor = module.ImportReference(typeof(Thickness)).Resolve().Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == args.Length);
+ var thicknessCtorRef = module.ImportReference(thicknessCtor);
yield return Instruction.Create(OpCodes.Newobj, thicknessCtorRef);
}
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs
index 93c3ee581..b8f02cc17 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs
@@ -31,9 +31,9 @@ namespace Xamarin.Forms.Core.XamlC
if (typeRef == null)
goto error;
- var getTypeFromHandle = module.Import(typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) }));
- yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeRef));
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
+ var getTypeFromHandle = module.ImportReference(typeof(Type).GetMethod("GetTypeFromHandle", new[] { typeof(RuntimeTypeHandle) }));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeRef));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
yield break;
error:
diff --git a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
index b7386a8b2..4565c64fe 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs
@@ -26,7 +26,7 @@ namespace Xamarin.Forms.Build.Tasks
var typename = member.Substring(0, dotIdx);
var membername = member.Substring(dotIdx + 1);
- var typeRef = module.Import(GetTypeReference(typename, module, node));
+ var typeRef = module.ImportReference(GetTypeReference(typename, module, node));
var fieldRef = GetFieldReference(typeRef, membername, module);
var propertyDef = GetPropertyDefinition(typeRef, membername, module);
@@ -75,7 +75,7 @@ namespace Xamarin.Forms.Build.Tasks
}
memberRef = propertyDef.PropertyType;
- var getterDef = module.Import(propertyDef.GetMethod);
+ var getterDef = module.ImportReference(propertyDef.GetMethod);
return new [] { Instruction.Create(OpCodes.Call, getterDef) };
}
@@ -105,8 +105,8 @@ namespace Xamarin.Forms.Build.Tasks
fd.IsStatic &&
fd.IsPublic, out declaringTypeReference);
if (fRef != null) {
- fRef = module.Import(fRef.ResolveGenericParameters(declaringTypeReference));
- fRef.FieldType = module.Import(fRef.FieldType);
+ fRef = module.ImportReference(fRef.ResolveGenericParameters(declaringTypeReference));
+ fRef.FieldType = module.ImportReference(fRef.FieldType);
}
return fRef;
}
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
index 60c3328f4..e417f118f 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs
@@ -29,7 +29,7 @@ namespace Xamarin.Forms.Core.XamlC
var bpRef = (new BindablePropertyConverter()).GetBindablePropertyFieldReference((string)bpNode.Value, module, bpNode);
TypeReference _;
- var setValueRef = module.Import(module.Import(typeof(Setter)).GetProperty(p => p.Name == "Value", out _).SetMethod);
+ var setValueRef = module.ImportReference(module.ImportReference(typeof(Setter)).GetProperty(p => p.Name == "Value", out _).SetMethod);
//push the setter
yield return Instruction.Create(OpCodes.Ldloc, vardefref.VariableDefinition);
diff --git a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
index f355a5287..e00a1c116 100644
--- a/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
+++ b/Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs
@@ -29,7 +29,7 @@ namespace Xamarin.Forms.Core.XamlC
var bpRef = (new BindablePropertyConverter()).GetBindablePropertyFieldReference((string)bpNode.Value, module, bpNode);
TypeReference _;
- var setValueRef = module.Import(module.Import(typeof(Trigger)).GetProperty(p => p.Name == "Value", out _).SetMethod);
+ var setValueRef = module.ImportReference(module.ImportReference(typeof(Trigger)).GetProperty(p => p.Name == "Value", out _).SetMethod);
//push the setter
yield return Instruction.Create(OpCodes.Ldloc, vardefref.VariableDefinition);
diff --git a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
index 3e3d10931..b73926fd4 100644
--- a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
@@ -39,7 +39,7 @@ namespace Xamarin.Forms.Build.Tasks
public void Visit(ElementNode node, INode parentNode)
{
- var typeref = Module.Import(node.XmlType.GetTypeReference(Module, node));
+ var typeref = Module.ImportReference(node.XmlType.GetTypeReference(Module, node));
TypeDefinition typedef = typeref.Resolve();
if (IsXaml2009LanguagePrimitive(node)) {
@@ -56,7 +56,7 @@ namespace Xamarin.Forms.Build.Tasks
var markupProvider = new StaticExtension();
var il = markupProvider.ProvideValue(node, Module, Context, out typeref);
- typeref = Module.Import(typeref);
+ typeref = Module.ImportReference(typeref);
var vardef = new VariableDefinition(typeref);
Context.Variables [node] = vardef;
@@ -141,15 +141,15 @@ namespace Xamarin.Forms.Build.Tasks
} else if (node.CollectionItems.Count == 1 && (vnode = node.CollectionItems.First() as ValueNode) != null &&
implicitOperatorref != null) {
//path.png
- var implicitOperator = Module.Import(implicitOperatorref);
+ var implicitOperator = Module.ImportReference(implicitOperatorref);
Context.IL.Emit(OpCodes.Ldstr, ((ValueNode)(node.CollectionItems.First())).Value as string);
Context.IL.Emit(OpCodes.Call, implicitOperator);
Context.IL.Emit(OpCodes.Stloc, vardef);
} else if (factorymethodinforef != null) {
- Context.IL.Emit(OpCodes.Call, Module.Import(factorymethodinforef));
+ Context.IL.Emit(OpCodes.Call, Module.ImportReference(factorymethodinforef));
Context.IL.Emit(OpCodes.Stloc, vardef);
} else if (!typedef.IsValueType) {
- var ctor = Module.Import(ctorinforef);
+ var ctor = Module.ImportReference(ctorinforef);
// IL_0001: newobj instance void class [Xamarin.Forms.Core]Xamarin.Forms.Button::'.ctor'()
// IL_0006: stloc.0
Context.IL.Emit(OpCodes.Newobj, ctor);
@@ -160,7 +160,7 @@ namespace Xamarin.Forms.Build.Tasks
// IL_000a: ldc.i4.1
// IL_000b: call instance void valuetype Test/Foo::'.ctor'(bool)
- var ctor = Module.Import(ctorinforef);
+ var ctor = Module.ImportReference(ctorinforef);
Context.IL.Emit(OpCodes.Ldloca, vardef);
Context.IL.Append(PushCtorXArguments(factoryCtorInfo, node));
Context.IL.Emit(OpCodes.Call, ctor);
@@ -168,7 +168,7 @@ namespace Xamarin.Forms.Build.Tasks
// IL_0000: ldloca.s 0
// IL_0002: initobj Test/Foo
Context.IL.Emit(OpCodes.Ldloca, vardef);
- Context.IL.Emit(OpCodes.Initobj, Module.Import(typedef));
+ Context.IL.Emit(OpCodes.Initobj, Module.ImportReference(typedef));
}
if (typeref.FullName == "Xamarin.Forms.Xaml.TypeExtension") {
@@ -433,7 +433,7 @@ namespace Xamarin.Forms.Build.Tasks
var ctorinfo =
Context.Body.Method.Module.TypeSystem.Object.Resolve()
.Methods.FirstOrDefault(md => md.IsConstructor && !md.HasParameters);
- var ctor = Context.Body.Method.Module.Import(ctorinfo);
+ var ctor = Context.Body.Method.Module.ImportReference(ctorinfo);
yield return Instruction.Create(OpCodes.Newobj, ctor);
break;
case "System.Char":
@@ -446,7 +446,7 @@ namespace Xamarin.Forms.Build.Tasks
case "System.Decimal":
decimal outdecimal;
if (hasValue && decimal.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out outdecimal)) {
- var vardef = new VariableDefinition(Context.Body.Method.Module.Import(typeof(decimal)));
+ var vardef = new VariableDefinition(Context.Body.Method.Module.ImportReference(typeof(decimal)));
Context.Body.Variables.Add(vardef);
//Use an extra temp var so we can push the value to the stack, just like other cases
// IL_0003: ldstr "adecimal"
@@ -458,29 +458,29 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldstr, valueString);
yield return Instruction.Create(OpCodes.Ldc_I4, 0x6f); //NumberStyles.Number
var getInvariantInfo =
- Context.Body.Method.Module.Import(typeof(CultureInfo))
+ Context.Body.Method.Module.ImportReference(typeof(CultureInfo))
.Resolve()
.Properties.FirstOrDefault(pd => pd.Name == "InvariantCulture")
.GetMethod;
- var getInvariant = Context.Body.Method.Module.Import(getInvariantInfo);
+ var getInvariant = Context.Body.Method.Module.ImportReference(getInvariantInfo);
yield return Instruction.Create(OpCodes.Call, getInvariant);
yield return Instruction.Create(OpCodes.Ldloca, vardef);
var tryParseInfo =
- Context.Body.Method.Module.Import(typeof(decimal))
+ Context.Body.Method.Module.ImportReference(typeof(decimal))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "TryParse" && md.Parameters.Count == 4);
- var tryParse = Context.Body.Method.Module.Import(tryParseInfo);
+ var tryParse = Context.Body.Method.Module.ImportReference(tryParseInfo);
yield return Instruction.Create(OpCodes.Call, tryParse);
yield return Instruction.Create(OpCodes.Pop);
yield return Instruction.Create(OpCodes.Ldloc, vardef);
} else {
yield return Instruction.Create(OpCodes.Ldc_I4_0);
var decimalctorinfo =
- Context.Body.Method.Module.Import(typeof(decimal))
+ Context.Body.Method.Module.ImportReference(typeof(decimal))
.Resolve()
.Methods.FirstOrDefault(
md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters [0].ParameterType.FullName == "System.Int32");
- var decimalctor = Context.Body.Method.Module.Import(decimalctorinfo);
+ var decimalctor = Context.Body.Method.Module.ImportReference(decimalctorinfo);
yield return Instruction.Create(OpCodes.Newobj, decimalctor);
}
break;
@@ -501,51 +501,51 @@ namespace Xamarin.Forms.Build.Tasks
case "System.TimeSpan":
TimeSpan outspan;
if (hasValue && TimeSpan.TryParse(valueString, CultureInfo.InvariantCulture, out outspan)) {
- var vardef = new VariableDefinition(Context.Body.Method.Module.Import(typeof(TimeSpan)));
+ var vardef = new VariableDefinition(Context.Body.Method.Module.ImportReference(typeof(TimeSpan)));
Context.Body.Variables.Add(vardef);
//Use an extra temp var so we can push the value to the stack, just like other cases
yield return Instruction.Create(OpCodes.Ldstr, valueString);
var getInvariantInfo =
- Context.Body.Method.Module.Import(typeof(CultureInfo))
+ Context.Body.Method.Module.ImportReference(typeof(CultureInfo))
.Resolve()
.Properties.FirstOrDefault(pd => pd.Name == "InvariantCulture")
.GetMethod;
- var getInvariant = Context.Body.Method.Module.Import(getInvariantInfo);
+ var getInvariant = Context.Body.Method.Module.ImportReference(getInvariantInfo);
yield return Instruction.Create(OpCodes.Call, getInvariant);
yield return Instruction.Create(OpCodes.Ldloca, vardef);
var tryParseInfo =
- Context.Body.Method.Module.Import(typeof(TimeSpan))
+ Context.Body.Method.Module.ImportReference(typeof(TimeSpan))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "TryParse" && md.Parameters.Count == 3);
- var tryParse = Context.Body.Method.Module.Import(tryParseInfo);
+ var tryParse = Context.Body.Method.Module.ImportReference(tryParseInfo);
yield return Instruction.Create(OpCodes.Call, tryParse);
yield return Instruction.Create(OpCodes.Pop);
yield return Instruction.Create(OpCodes.Ldloc, vardef);
} else {
yield return Instruction.Create(OpCodes.Ldc_I8, 0L);
var timespanctorinfo =
- Context.Body.Method.Module.Import(typeof(TimeSpan))
+ Context.Body.Method.Module.ImportReference(typeof(TimeSpan))
.Resolve()
.Methods.FirstOrDefault(
md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters [0].ParameterType.FullName == "System.Int64");
- var timespanctor = Context.Body.Method.Module.Import(timespanctorinfo);
+ var timespanctor = Context.Body.Method.Module.ImportReference(timespanctorinfo);
yield return Instruction.Create(OpCodes.Newobj, timespanctor);
}
break;
case "System.Uri":
Uri outuri;
if (hasValue && Uri.TryCreate(valueString, UriKind.RelativeOrAbsolute, out outuri)) {
- var vardef = new VariableDefinition(Context.Body.Method.Module.Import(typeof(Uri)));
+ var vardef = new VariableDefinition(Context.Body.Method.Module.ImportReference(typeof(Uri)));
Context.Body.Variables.Add(vardef);
//Use an extra temp var so we can push the value to the stack, just like other cases
yield return Instruction.Create(OpCodes.Ldstr, valueString);
yield return Instruction.Create(OpCodes.Ldc_I4, (int)UriKind.RelativeOrAbsolute);
yield return Instruction.Create(OpCodes.Ldloca, vardef);
var tryCreateInfo =
- Context.Body.Method.Module.Import(typeof(Uri))
+ Context.Body.Method.Module.ImportReference(typeof(Uri))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "TryCreate" && md.Parameters.Count == 3);
- var tryCreate = Context.Body.Method.Module.Import(tryCreateInfo);
+ var tryCreate = Context.Body.Method.Module.ImportReference(tryCreateInfo);
yield return Instruction.Create(OpCodes.Call, tryCreate);
yield return Instruction.Create(OpCodes.Pop);
yield return Instruction.Create(OpCodes.Ldloc, vardef);
@@ -555,7 +555,7 @@ namespace Xamarin.Forms.Build.Tasks
default:
var defaultctorinfo = typedef.Methods.FirstOrDefault(md => md.IsConstructor && !md.HasParameters);
if (defaultctorinfo != null) {
- var defaultctor = Context.Body.Method.Module.Import(defaultctorinfo);
+ var defaultctor = Context.Body.Method.Module.ImportReference(defaultctorinfo);
yield return Instruction.Create(OpCodes.Newobj, defaultctor);
} else {
//should never happen. but if it does, this prevents corrupting the IL stack
diff --git a/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs b/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs
index a8ef874af..1c7acac4a 100644
--- a/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs
+++ b/Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs
@@ -2,16 +2,22 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+
using Mono.Cecil;
using Mono.Cecil.Cil;
+using Mono.Cecil.Mdb;
+using Mono.Cecil.Pdb;
using Mono.Cecil.Rocks;
+using Xamarin.Forms.Xaml;
+
namespace Xamarin.Forms.Build.Tasks
{
public class DebugXamlCTask : XamlTask
{
- public override bool Execute(IList thrownExceptions)
+ public override bool Execute(out IList thrownExceptions)
{
+ thrownExceptions = null;
Logger = Logger ?? new Logger(null, Verbosity);
Logger.LogLine(1, "Preparing debug code for xamlc");
Logger.LogLine(1, "\nAssembly: {0}", Assembly);
@@ -37,109 +43,116 @@ namespace Xamarin.Forms.Build.Tasks
// resolver.AddAssembly (p);
}
}
- var assemblyDefinition = AssemblyDefinition.ReadAssembly(Assembly, new ReaderParameters
- {
- //ReadSymbols = DebugSymbols,
+ using (var assemblyDefinition = AssemblyDefinition.ReadAssembly(Assembly, new ReaderParameters {
+ ReadWrite = true,
+ ReadSymbols = DebugSymbols,
+ SymbolReaderProvider = System.Type.GetType("Mono.Runtime") != null ? ((ISymbolReaderProvider)(new MdbReaderProvider())) : ((ISymbolReaderProvider)new PdbReaderProvider()),
AssemblyResolver = resolver
- });
+ })) {
+ foreach (var module in assemblyDefinition.Modules) {
+ Logger.LogLine(2, " Module: {0}", module.Name);
+ foreach (var resource in module.Resources.OfType()) {
+ Logger.LogString(2, " Resource: {0}... ", resource.Name);
+ string classname;
+ if (!resource.IsXaml(out classname)) {
+ Logger.LogLine(2, "skipped.");
+ continue;
+ } else
+ Logger.LogLine(2, "");
+ TypeDefinition typeDef = module.GetType(classname);
+ if (typeDef == null) {
+ Logger.LogLine(2, "no type found... skipped.");
+ continue;
+ }
- foreach (var module in assemblyDefinition.Modules)
- {
- Logger.LogLine(2, " Module: {0}", module.Name);
- foreach (var resource in module.Resources.OfType())
- {
- Logger.LogString(2, " Resource: {0}... ", resource.Name);
- string classname;
- if (!resource.IsXaml(out classname))
- {
- Logger.LogLine(2, "skipped.");
- continue;
- }
- TypeDefinition typeDef = module.GetType(classname);
- if (typeDef == null)
- {
- Logger.LogLine(2, "no type found... skipped.");
- continue;
- }
- var initComp = typeDef.Methods.FirstOrDefault(md => md.Name == "InitializeComponent");
- if (initComp == null)
- {
- Logger.LogLine(2, "no InitializeComponent found... skipped.");
- continue;
- }
- var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime");
- if (initCompRuntime == null) {
- Logger.LogLine(2, "no __InitComponentRuntime found... duplicating.");
- initCompRuntime = DuplicateMethodDef(typeDef, initComp, "__InitComponentRuntime");
- }
+ var initComp = typeDef.Methods.FirstOrDefault(md => md.Name == "InitializeComponent");
+ if (initComp == null) {
+ Logger.LogLine(2, "no InitializeComponent found... skipped.");
+ continue;
+ }
+ var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime");
+ if (initCompRuntime == null) {
+ Logger.LogString(2, " Creating empty {0}.__InitComponentRuntime ...", typeDef.Name);
+ initCompRuntime = new MethodDefinition("__InitComponentRuntime", initComp.Attributes, initComp.ReturnType);
+ Logger.LogLine(2, "done.");
+ Logger.LogString(2, " Copying body of InitializeComponent to __InitComponentRuntime ...", typeDef.Name);
+ initCompRuntime.Body = new MethodBody(initCompRuntime);
+ var iCRIl = initCompRuntime.Body.GetILProcessor();
+ foreach (var instr in initComp.Body.Instructions)
+ iCRIl.Append(instr);
+ initComp.Body.Instructions.Clear();
+ initComp.Body.GetILProcessor().Emit(OpCodes.Ret);
+ typeDef.Methods.Add(initCompRuntime);
+ Logger.LogLine(2, "done.");
+ }
-// IL_0000: ldarg.0
-// IL_0001: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.ContentPage::'.ctor'()
+// IL_0000: ldarg.0
+// IL_0001: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.ContentPage::'.ctor'()
//
-// IL_0006: nop
-// IL_0007: ldarg.1
-// IL_0008: brfalse IL_0018
+// IL_0006: nop
+// IL_0007: ldarg.1
+// IL_0008: brfalse IL_0018
//
-// IL_000d: ldarg.0
-// IL_000e: callvirt instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::InitializeComponent()
-// IL_0013: br IL_001e
+// IL_000d: ldarg.0
+// IL_000e: callvirt instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::InitializeComponent()
+// IL_0013: br IL_001e
//
-// IL_0018: ldarg.0
-// IL_0019: callvirt instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::__InitComponentRuntime()
-// IL_001e: ret
+// IL_0018: ldarg.0
+// IL_0019: callvirt instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::__InitComponentRuntime()
+// IL_001e: ret
- var altCtor =
- typeDef.Methods.Where(
- md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters[0].ParameterType == module.TypeSystem.Boolean)
- .FirstOrDefault();
- if (altCtor != null)
- Logger.LogString(2, " Replacing body of {0}.{0} (bool {1}) ... ", typeDef.Name, altCtor.Parameters[0].Name);
- else
- {
- Logger.LogString(2, " Adding {0}.{0} (bool useCompiledXaml) ... ", typeDef.Name);
- altCtor = new MethodDefinition(".ctor",
- MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName |
- MethodAttributes.RTSpecialName, module.TypeSystem.Void);
- altCtor.Parameters.Add(new ParameterDefinition("useCompiledXaml", ParameterAttributes.None,
- module.TypeSystem.Boolean));
+ var altCtor =
+ typeDef.Methods.Where(
+ md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters[0].ParameterType == module.TypeSystem.Boolean)
+ .FirstOrDefault();
+ if (altCtor != null)
+ Logger.LogString(2, " Replacing body of {0}.{0} (bool {1}) ... ", typeDef.Name, altCtor.Parameters[0].Name);
+ else {
+ Logger.LogString(2, " Adding {0}.{0} (bool useCompiledXaml) ... ", typeDef.Name);
+ altCtor = new MethodDefinition(".ctor",
+ MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName |
+ MethodAttributes.RTSpecialName, module.TypeSystem.Void);
+ altCtor.Parameters.Add(new ParameterDefinition("useCompiledXaml", ParameterAttributes.None,
+ module.TypeSystem.Boolean));
+ }
+
+ var body = new MethodBody(altCtor);
+ var il = body.GetILProcessor();
+ var br2 = Instruction.Create(OpCodes.Ldarg_0);
+ var ret = Instruction.Create(OpCodes.Ret);
+ il.Emit(OpCodes.Ldarg_0);
+ il.Emit(OpCodes.Callvirt,
+ module.ImportReference(typeDef.BaseType.Resolve().GetConstructors().First(c => c.HasParameters == false)));
+
+ il.Emit(OpCodes.Nop);
+ il.Emit(OpCodes.Ldarg_1);
+ il.Emit(OpCodes.Brfalse, br2);
+
+ il.Emit(OpCodes.Ldarg_0);
+ il.Emit(OpCodes.Callvirt, initComp);
+ il.Emit(OpCodes.Br, ret);
+
+ il.Append(br2);
+ il.Emit(OpCodes.Callvirt, initCompRuntime);
+ il.Append(ret);
+
+ altCtor.Body = body;
+ if (!typeDef.Methods.Contains(altCtor))
+ typeDef.Methods.Add(altCtor);
+ Logger.LogLine(2, "done.");
}
- var body = new MethodBody(altCtor);
- var il = body.GetILProcessor();
- var br2 = Instruction.Create(OpCodes.Ldarg_0);
- var ret = Instruction.Create(OpCodes.Ret);
- il.Emit(OpCodes.Ldarg_0);
- il.Emit(OpCodes.Callvirt,
- module.Import(typeDef.BaseType.Resolve().GetConstructors().First(c => c.HasParameters == false)));
-
- il.Emit(OpCodes.Nop);
- il.Emit(OpCodes.Ldarg_1);
- il.Emit(OpCodes.Brfalse, br2);
-
- il.Emit(OpCodes.Ldarg_0);
- il.Emit(OpCodes.Callvirt, initComp);
- il.Emit(OpCodes.Br, ret);
-
- il.Append(br2);
- il.Emit(OpCodes.Callvirt, initCompRuntime);
- il.Append(ret);
-
- altCtor.Body = body;
- if (!typeDef.Methods.Contains(altCtor))
- typeDef.Methods.Add(altCtor);
- Logger.LogLine(2, "done.");
+ Logger.LogLine(2, "");
}
-
- Logger.LogLine(2, "");
+ Logger.LogString(1, "Writing the assembly... ");
+ assemblyDefinition.Write(new WriterParameters {
+ SymbolWriterProvider = System.Type.GetType("Mono.Runtime") != null ? ((ISymbolWriterProvider)(new MdbWriterProvider())) : ((ISymbolWriterProvider)new MdbWriterProvider()),
+ WriteSymbols = DebugSymbols
+ });
}
- Logger.LogString(1, "Writing the assembly... ");
- assemblyDefinition.Write(Assembly, new WriterParameters
- {
- WriteSymbols = DebugSymbols
- });
Logger.LogLine(1, "done.");
return true;
}
}
-}
\ No newline at end of file
+}
diff --git a/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs
index e3b2f3ab5..2c0d8ba94 100644
--- a/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs
@@ -13,16 +13,16 @@ namespace Xamarin.Forms.Build.Tasks
if (declaringTypeRef == null)
throw new ArgumentNullException(nameof(declaringTypeRef));
- var reference = new MethodReference(self.Name, module.Import(self.ReturnType))
+ var reference = new MethodReference(self.Name, module.ImportReference(self.ReturnType))
{
- DeclaringType = module.Import(declaringTypeRef),
+ DeclaringType = module.ImportReference(declaringTypeRef),
HasThis = self.HasThis,
ExplicitThis = self.ExplicitThis,
CallingConvention = self.CallingConvention
};
foreach (var parameter in self.Parameters) {
- var p = parameter.ParameterType.IsGenericParameter ? parameter.ParameterType : module.Import(parameter.ParameterType);
+ var p = parameter.ParameterType.IsGenericParameter ? parameter.ParameterType : module.ImportReference(parameter.ParameterType);
reference.Parameters.Add(new ParameterDefinition(p));
}
@@ -37,7 +37,7 @@ namespace Xamarin.Forms.Build.Tasks
if (self.HasParameters)
{
for (var i = 0; i < self.Parameters.Count; i++)
- self.Parameters[i].ParameterType = module.Import(self.Parameters[i].ParameterType);
+ self.Parameters[i].ParameterType = module.ImportReference(self.Parameters[i].ParameterType);
}
}
diff --git a/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs b/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
index 08c102aee..ca0f9fd64 100644
--- a/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/NodeILExtensions.cs
@@ -52,7 +52,7 @@ namespace Xamarin.Forms.Build.Tasks
var str = (string)node.Value;
//If the TypeConverter has a ProvideCompiledAttribute that can be resolved, shortcut this
- var compiledConverterName = typeConverter?.GetCustomAttribute (module.Import(typeof(ProvideCompiledAttribute)))?.ConstructorArguments?.First().Value as string;
+ var compiledConverterName = typeConverter?.GetCustomAttribute (module.ImportReference(typeof(ProvideCompiledAttribute)))?.ConstructorArguments?.First().Value as string;
Type compiledConverterType;
if (compiledConverterName != null && (compiledConverterType = Type.GetType (compiledConverterName)) != null) {
var compiledConverter = Activator.CreateInstance (compiledConverterType);
@@ -62,24 +62,24 @@ namespace Xamarin.Forms.Build.Tasks
foreach (var i in instructions)
yield return i;
if (targetTypeRef.IsValueType && boxValueTypes)
- yield return Instruction.Create (OpCodes.Box, module.Import (targetTypeRef));
+ yield return Instruction.Create (OpCodes.Box, module.ImportReference (targetTypeRef));
yield break;
}
//If there's a [TypeConverter], use it
if (typeConverter != null)
{
- var isExtendedConverter = typeConverter.ImplementsInterface(module.Import(typeof (IExtendedTypeConverter)));
+ var isExtendedConverter = typeConverter.ImplementsInterface(module.ImportReference(typeof (IExtendedTypeConverter)));
var typeConverterCtor = typeConverter.Resolve().Methods.Single(md => md.IsConstructor && md.Parameters.Count == 0 && !md.IsStatic);
- var typeConverterCtorRef = module.Import(typeConverterCtor);
+ var typeConverterCtorRef = module.ImportReference(typeConverterCtor);
var convertFromInvariantStringDefinition = isExtendedConverter
- ? module.Import(typeof (IExtendedTypeConverter))
+ ? module.ImportReference(typeof (IExtendedTypeConverter))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "ConvertFromInvariantString" && md.Parameters.Count == 2)
: typeConverter.Resolve()
.AllMethods()
.FirstOrDefault(md => md.Name == "ConvertFromInvariantString" && md.Parameters.Count == 1);
- var convertFromInvariantStringReference = module.Import(convertFromInvariantStringDefinition);
+ var convertFromInvariantStringReference = module.ImportReference(convertFromInvariantStringDefinition);
yield return Instruction.Create(OpCodes.Newobj, typeConverterCtorRef);
yield return Instruction.Create(OpCodes.Ldstr, node.Value as string);
@@ -93,7 +93,7 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Callvirt, convertFromInvariantStringReference);
if (targetTypeRef.IsValueType && unboxValueTypes)
- yield return Instruction.Create(OpCodes.Unbox_Any, module.Import(targetTypeRef));
+ yield return Instruction.Create(OpCodes.Unbox_Any, module.ImportReference(targetTypeRef));
//ConvertFrom returns an object, no need to Box
yield break;
@@ -146,10 +146,10 @@ namespace Xamarin.Forms.Build.Tasks
var ts = TimeSpan.Parse(str, CultureInfo.InvariantCulture);
var ticks = ts.Ticks;
var timeSpanCtor =
- module.Import(typeof(TimeSpan))
+ module.ImportReference(typeof(TimeSpan))
.Resolve()
.Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 1);
- var timeSpanCtorRef = module.Import(timeSpanCtor);
+ var timeSpanCtorRef = module.ImportReference(timeSpanCtor);
yield return Instruction.Create(OpCodes.Ldc_I8, ticks);
yield return Instruction.Create(OpCodes.Newobj, timeSpanCtorRef);
@@ -157,10 +157,10 @@ namespace Xamarin.Forms.Build.Tasks
var dt = DateTime.Parse(str, CultureInfo.InvariantCulture);
var ticks = dt.Ticks;
var dateTimeCtor =
- module.Import(typeof(DateTime))
+ module.ImportReference(typeof(DateTime))
.Resolve()
.Methods.FirstOrDefault(md => md.IsConstructor && md.Parameters.Count == 1);
- var dateTimeCtorRef = module.Import(dateTimeCtor);
+ var dateTimeCtorRef = module.ImportReference(dateTimeCtor);
yield return Instruction.Create(OpCodes.Ldc_I8, ticks);
yield return Instruction.Create(OpCodes.Newobj, dateTimeCtorRef);
@@ -173,7 +173,7 @@ namespace Xamarin.Forms.Build.Tasks
else if (targetTypeRef.FullName == "System.Decimal") {
decimal outdecimal;
if (decimal.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out outdecimal)) {
- var vardef = new VariableDefinition(context.Body.Method.Module.Import(typeof(decimal)));
+ var vardef = new VariableDefinition(context.Body.Method.Module.ImportReference(typeof(decimal)));
context.Body.Variables.Add(vardef);
//Use an extra temp var so we can push the value to the stack, just like other cases
// IL_0003: ldstr "adecimal"
@@ -185,41 +185,41 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldstr, str);
yield return Instruction.Create(OpCodes.Ldc_I4, 0x6f); //NumberStyles.Number
var getInvariantInfo =
- context.Body.Method.Module.Import(typeof(CultureInfo))
+ context.Body.Method.Module.ImportReference(typeof(CultureInfo))
.Resolve()
.Properties.FirstOrDefault(pd => pd.Name == "InvariantCulture")
.GetMethod;
- var getInvariant = context.Body.Method.Module.Import(getInvariantInfo);
+ var getInvariant = context.Body.Method.Module.ImportReference(getInvariantInfo);
yield return Instruction.Create(OpCodes.Call, getInvariant);
yield return Instruction.Create(OpCodes.Ldloca, vardef);
var tryParseInfo =
- context.Body.Method.Module.Import(typeof(decimal))
+ context.Body.Method.Module.ImportReference(typeof(decimal))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "TryParse" && md.Parameters.Count == 4);
- var tryParse = context.Body.Method.Module.Import(tryParseInfo);
+ var tryParse = context.Body.Method.Module.ImportReference(tryParseInfo);
yield return Instruction.Create(OpCodes.Call, tryParse);
yield return Instruction.Create(OpCodes.Pop);
yield return Instruction.Create(OpCodes.Ldloc, vardef);
} else {
yield return Instruction.Create(OpCodes.Ldc_I4_0);
var decimalctorinfo =
- context.Body.Method.Module.Import(typeof(decimal))
+ context.Body.Method.Module.ImportReference(typeof(decimal))
.Resolve()
.Methods.FirstOrDefault(
md => md.IsConstructor && md.Parameters.Count == 1 && md.Parameters[0].ParameterType.FullName == "System.Int32");
- var decimalctor = context.Body.Method.Module.Import(decimalctorinfo);
+ var decimalctor = context.Body.Method.Module.ImportReference(decimalctorinfo);
yield return Instruction.Create(OpCodes.Newobj, decimalctor);
}
} else if (implicitOperator != null) {
yield return Instruction.Create(OpCodes.Ldstr, node.Value as string);
- yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(implicitOperator));
} else
yield return Instruction.Create(OpCodes.Ldnull);
if (isNullable)
- yield return Instruction.Create(OpCodes.Newobj, module.Import(nullableCtor));
+ yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(nullableCtor));
if (originalTypeRef.IsValueType && boxValueTypes)
- yield return Instruction.Create(OpCodes.Box, module.Import(originalTypeRef));
+ yield return Instruction.Create(OpCodes.Box, module.ImportReference(originalTypeRef));
}
static Instruction PushParsedEnum(TypeReference enumRef, string value, IXmlLineInfo lineInfo)
@@ -320,10 +320,10 @@ namespace Xamarin.Forms.Build.Tasks
{
yield return Instruction.Create(OpCodes.Ldc_I4, xmlLineInfo.LineNumber);
yield return Instruction.Create(OpCodes.Ldc_I4, xmlLineInfo.LinePosition);
- ctor = module.Import(typeof (XmlLineInfo).GetConstructor(new[] { typeof (int), typeof (int) }));
+ ctor = module.ImportReference(typeof (XmlLineInfo).GetConstructor(new[] { typeof (int), typeof (int) }));
}
else
- ctor = module.Import(typeof (XmlLineInfo).GetConstructor(new Type[] { }));
+ ctor = module.ImportReference(typeof (XmlLineInfo).GetConstructor(new Type[] { }));
yield return Instruction.Create(OpCodes.Newobj, ctor);
}
@@ -373,7 +373,7 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldc_I4, nodes.Count);
yield return Instruction.Create(OpCodes.Add);
yield return Instruction.Create(OpCodes.Newarr, module.TypeSystem.Object);
- var finalArray = new VariableDefinition(module.Import(typeof (object[])));
+ var finalArray = new VariableDefinition(module.ImportReference(typeof (object[])));
context.Body.Variables.Add(finalArray);
yield return Instruction.Create(OpCodes.Stloc, finalArray);
@@ -387,13 +387,13 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldc_I4, nodes.Count); //destinationIndex
yield return Instruction.Create(OpCodes.Ldloc, parentObjectLength); //length
var arrayCopy =
- module.Import(typeof (Array))
+ module.ImportReference(typeof (Array))
.Resolve()
.Methods.First(
md =>
md.Name == "Copy" && md.Parameters.Count == 5 &&
md.Parameters[1].ParameterType.FullName == module.TypeSystem.Int32.FullName);
- yield return Instruction.Create(OpCodes.Call, module.Import(arrayCopy));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(arrayCopy));
}
//Add nodes to array
@@ -407,7 +407,7 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldc_I4, i);
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[en]);
if (context.Variables[en].VariableType.IsValueType)
- yield return Instruction.Create(OpCodes.Box, module.Import(context.Variables[en].VariableType));
+ yield return Instruction.Create(OpCodes.Box, module.ImportReference(context.Variables[en].VariableType));
yield return Instruction.Create(OpCodes.Stelem_Ref);
}
}
@@ -424,12 +424,12 @@ namespace Xamarin.Forms.Build.Tasks
// IL_0005: call class [mscorlib]System.Type class [mscorlib] System.Type::GetTypeFromHandle(valuetype [mscorlib] System.RuntimeTypeHandle)
// IL_000a: ldstr "Foo"
// IL_000f: callvirt instance class [mscorlib] System.Reflection.PropertyInfo class [mscorlib] System.Type::GetProperty(string)
- var getTypeFromHandle = module.Import(typeof(Type).GetMethod("GetTypeFromHandle", new [] { typeof(RuntimeTypeHandle) }));
- var getPropertyInfo = module.Import(typeof(Type).GetMethod("GetProperty", new [] { typeof(string) }));
- yield return Instruction.Create(OpCodes.Ldtoken, module.Import(declaringTypeReference ?? propertyRef.DeclaringType));
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
+ var getTypeFromHandle = module.ImportReference(typeof(Type).GetMethod("GetTypeFromHandle", new [] { typeof(RuntimeTypeHandle) }));
+ var getPropertyInfo = module.ImportReference(typeof(Type).GetMethod("GetProperty", new [] { typeof(string) }));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(declaringTypeReference ?? propertyRef.DeclaringType));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
yield return Instruction.Create(OpCodes.Ldstr, propertyRef.Name);
- yield return Instruction.Create(OpCodes.Callvirt, module.Import(getPropertyInfo));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(getPropertyInfo));
yield break;
}
yield return Instruction.Create(OpCodes.Ldnull);
@@ -446,14 +446,14 @@ namespace Xamarin.Forms.Build.Tasks
#endif
var ctorinfo = typeof (XamlServiceProvider).GetConstructor(new Type[] { });
- var ctor = module.Import(ctorinfo);
+ var ctor = module.ImportReference(ctorinfo);
var addServiceInfo = typeof (XamlServiceProvider).GetMethod("Add", new[] { typeof (Type), typeof (object) });
- var addService = module.Import(addServiceInfo);
+ var addService = module.ImportReference(addServiceInfo);
var getTypeFromHandle =
- module.Import(typeof (Type).GetMethod("GetTypeFromHandle", new[] { typeof (RuntimeTypeHandle) }));
- var getAssembly = module.Import(typeof (Type).GetProperty("Assembly").GetMethod);
+ module.ImportReference(typeof (Type).GetMethod("GetTypeFromHandle", new[] { typeof (RuntimeTypeHandle) }));
+ var getAssembly = module.ImportReference(typeof (Type).GetProperty("Assembly").GetMethod);
yield return Instruction.Create(OpCodes.Newobj, ctor);
@@ -462,8 +462,8 @@ namespace Xamarin.Forms.Build.Tasks
if (pushParentIl[pushParentIl.Count - 1].OpCode != OpCodes.Ldnull)
{
yield return Instruction.Create(OpCodes.Dup); //Keep the serviceProvider on the stack
- yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeof (IProvideValueTarget)));
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeof (IProvideValueTarget)));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
foreach (var instruction in pushParentIl)
yield return instruction;
@@ -472,7 +472,7 @@ namespace Xamarin.Forms.Build.Tasks
yield return instruction;
var targetProviderCtor =
- module.Import(typeof (SimpleValueTargetProvider).GetConstructor(new[] { typeof (object[]), typeof(object) }));
+ module.ImportReference(typeof (SimpleValueTargetProvider).GetConstructor(new[] { typeof (object[]), typeof(object) }));
yield return Instruction.Create(OpCodes.Newobj, targetProviderCtor);
yield return Instruction.Create(OpCodes.Callvirt, addService);
}
@@ -481,12 +481,12 @@ namespace Xamarin.Forms.Build.Tasks
if (context.Scopes.ContainsKey(node))
{
yield return Instruction.Create(OpCodes.Dup); //Dupicate the serviceProvider
- yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeof (INameScopeProvider)));
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
- var namescopeProviderCtor = module.Import(typeof (NameScopeProvider).GetConstructor(new Type[] { }));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeof (INameScopeProvider)));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
+ var namescopeProviderCtor = module.ImportReference(typeof (NameScopeProvider).GetConstructor(new Type[] { }));
yield return Instruction.Create(OpCodes.Newobj, namescopeProviderCtor);
yield return Instruction.Create(OpCodes.Dup); //Duplicate the namescopeProvider
- var setNamescope = module.Import(typeof (NameScopeProvider).GetProperty("NameScope").GetSetMethod());
+ var setNamescope = module.ImportReference(typeof (NameScopeProvider).GetProperty("NameScope").GetSetMethod());
yield return Instruction.Create(OpCodes.Ldloc, context.Scopes[node].Item1);
yield return Instruction.Create(OpCodes.Callvirt, setNamescope);
@@ -497,10 +497,10 @@ namespace Xamarin.Forms.Build.Tasks
if (node.NamespaceResolver != null)
{
yield return Instruction.Create(OpCodes.Dup); //Dupicate the serviceProvider
- yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeof (IXamlTypeResolver)));
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
- var xmlNamespaceResolverCtor = module.Import(typeof (XmlNamespaceResolver).GetConstructor(new Type[] { }));
- var addNamespace = module.Import(typeof (XmlNamespaceResolver).GetMethod("Add"));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeof (IXamlTypeResolver)));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
+ var xmlNamespaceResolverCtor = module.ImportReference(typeof (XmlNamespaceResolver).GetConstructor(new Type[] { }));
+ var addNamespace = module.ImportReference(typeof (XmlNamespaceResolver).GetMethod("Add"));
yield return Instruction.Create(OpCodes.Newobj, xmlNamespaceResolverCtor);
foreach (var kvp in node.NamespaceResolver.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml))
{
@@ -510,10 +510,10 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Callvirt, addNamespace);
}
yield return Instruction.Create(OpCodes.Ldtoken, context.Body.Method.DeclaringType);
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
yield return Instruction.Create(OpCodes.Callvirt, getAssembly);
- var xtr = module.Import(typeof (XamlTypeResolver)).Resolve();
- var xamlTypeResolverCtor = module.Import(xtr.Methods.First(md => md.IsConstructor && md.Parameters.Count == 2));
+ var xtr = module.ImportReference(typeof (XamlTypeResolver)).Resolve();
+ var xamlTypeResolverCtor = module.ImportReference(xtr.Methods.First(md => md.IsConstructor && md.Parameters.Count == 2));
yield return Instruction.Create(OpCodes.Newobj, xamlTypeResolverCtor);
yield return Instruction.Create(OpCodes.Callvirt, addService);
}
@@ -521,17 +521,17 @@ namespace Xamarin.Forms.Build.Tasks
if (node is IXmlLineInfo)
{
yield return Instruction.Create(OpCodes.Dup); //Dupicate the serviceProvider
- yield return Instruction.Create(OpCodes.Ldtoken, module.Import(typeof (IXmlLineInfoProvider)));
- yield return Instruction.Create(OpCodes.Call, module.Import(getTypeFromHandle));
+ yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeof (IXmlLineInfoProvider)));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(getTypeFromHandle));
foreach (var instruction in node.PushXmlLineInfo(context))
yield return instruction;
- var lip = module.Import(typeof (XmlLineInfoProvider)).Resolve();
- var lineInfoProviderCtor = module.Import(lip.Methods.First(md => md.IsConstructor && md.Parameters.Count == 1));
+ var lip = module.ImportReference(typeof (XmlLineInfoProvider)).Resolve();
+ var lineInfoProviderCtor = module.ImportReference(lip.Methods.First(md => md.IsConstructor && md.Parameters.Count == 1));
yield return Instruction.Create(OpCodes.Newobj, lineInfoProviderCtor);
yield return Instruction.Create(OpCodes.Callvirt, addService);
}
}
}
-}
\ No newline at end of file
+}
diff --git a/Xamarin.Forms.Build.Tasks/Properties/AssemblyInfo.cs b/Xamarin.Forms.Build.Tasks/Properties/AssemblyInfo.cs
index ea4bda348..454c5cb86 100644
--- a/Xamarin.Forms.Build.Tasks/Properties/AssemblyInfo.cs
+++ b/Xamarin.Forms.Build.Tasks/Properties/AssemblyInfo.cs
@@ -27,4 +27,5 @@ using System.Runtime.CompilerServices;
//[assembly: AssemblyKeyFile("")]
[assembly: InternalsVisibleTo("xamlg")]
+[assembly: InternalsVisibleTo("xamlc")]
[assembly: InternalsVisibleTo("Xamarin.Forms.Xaml.UnitTests")]
\ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs
index 674b1f35d..1c776ab8f 100644
--- a/Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs
@@ -44,7 +44,7 @@ namespace Xamarin.Forms.Build.Tasks
namescopeVarDef = Context.Scopes[parentNode].Item1;
namesInNamescope = Context.Scopes[parentNode].Item2;
}
- if (Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.Import(typeof (BindableObject))))
+ if (Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.ImportReference(typeof (BindableObject))))
SetNameScope(node, namescopeVarDef);
Context.Scopes[node] = new System.Tuple>(namescopeVarDef, namesInNamescope);
}
@@ -53,7 +53,7 @@ namespace Xamarin.Forms.Build.Tasks
{
var namescopeVarDef = CreateNamescope();
IList namesInNamescope = new List();
- if (Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.Import(typeof (BindableObject))))
+ if (Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.ImportReference(typeof (BindableObject))))
SetNameScope(node, namescopeVarDef);
Context.Scopes[node] = new System.Tuple>(namescopeVarDef, namesInNamescope);
}
@@ -91,12 +91,12 @@ namespace Xamarin.Forms.Build.Tasks
VariableDefinition CreateNamescope()
{
var module = Context.Body.Method.Module;
- var nsRef = module.Import(typeof (NameScope));
+ var nsRef = module.ImportReference(typeof (NameScope));
var vardef = new VariableDefinition(nsRef);
Context.Body.Variables.Add(vardef);
var nsDef = nsRef.Resolve();
var ctorinfo = nsDef.Methods.First(md => md.IsConstructor && !md.HasParameters);
- var ctor = module.Import(ctorinfo);
+ var ctor = module.ImportReference(ctorinfo);
Context.IL.Emit(OpCodes.Newobj, ctor);
Context.IL.Emit(OpCodes.Stloc, vardef);
return vardef;
@@ -105,10 +105,10 @@ namespace Xamarin.Forms.Build.Tasks
void SetNameScope(ElementNode node, VariableDefinition ns)
{
var module = Context.Body.Method.Module;
- var nsRef = module.Import(typeof (NameScope));
+ var nsRef = module.ImportReference(typeof (NameScope));
var nsDef = nsRef.Resolve();
var setNSInfo = nsDef.Methods.First(md => md.Name == "SetNameScope" && md.IsStatic);
- var setNS = module.Import(setNSInfo);
+ var setNS = module.ImportReference(setNSInfo);
Context.IL.Emit(OpCodes.Ldloc, Context.Variables[node]);
Context.IL.Emit(OpCodes.Ldloc, ns);
Context.IL.Emit(OpCodes.Call, setNS);
@@ -121,10 +121,10 @@ namespace Xamarin.Forms.Build.Tasks
namesInNamescope.Add(str);
var module = Context.Body.Method.Module;
- var nsRef = module.Import(typeof (INameScope));
+ var nsRef = module.ImportReference(typeof (INameScope));
var nsDef = nsRef.Resolve();
var registerInfo = nsDef.Methods.First(md => md.Name == "RegisterName" && md.Parameters.Count == 2);
- var register = module.Import(registerInfo);
+ var register = module.ImportReference(registerInfo);
Context.IL.Emit(OpCodes.Ldloc, namescopeVarDef);
Context.IL.Emit(OpCodes.Ldstr, str);
diff --git a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
index 8d087ab7b..608fab5b5 100644
--- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
@@ -128,14 +128,14 @@ namespace Xamarin.Forms.Build.Tasks
// Collection element, implicit content, or implicit collection element.
string contentProperty;
var parentVar = Context.Variables[(IElementNode)parentNode];
- if (parentVar.VariableType.ImplementsInterface(Module.Import(typeof (IEnumerable))))
+ if (parentVar.VariableType.ImplementsInterface(Module.ImportReference(typeof (IEnumerable))))
{
var elementType = parentVar.VariableType;
if (elementType.FullName != "Xamarin.Forms.ResourceDictionary" && elementType.Resolve().BaseType.FullName != "Xamarin.Forms.ResourceDictionary")
{
var adderTuple = elementType.GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, Module).First();
- var adderRef = Module.Import(adderTuple.Item1);
- adderRef = Module.Import(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));
+ var adderRef = Module.ImportReference(adderTuple.Item1);
+ adderRef = Module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));
Context.IL.Emit(OpCodes.Ldloc, parentVar);
Context.IL.Emit(OpCodes.Ldloc, vardef);
@@ -179,13 +179,13 @@ namespace Xamarin.Forms.Build.Tasks
if (property != null && (propertyGetter = property.GetMethod) != null && propertyGetter.IsPublic)
{
- var propertyGetterRef = Module.Import(propertyGetter);
- propertyGetterRef = Module.Import(propertyGetterRef.ResolveGenericParameters(propertyDeclaringType, Module));
+ var propertyGetterRef = Module.ImportReference(propertyGetter);
+ propertyGetterRef = Module.ImportReference(propertyGetterRef.ResolveGenericParameters(propertyDeclaringType, Module));
var propertyType = propertyGetterRef.ReturnType.ResolveGenericParameters(propertyDeclaringType);
var adderTuple = propertyType.GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, Module).First();
- var adderRef = Module.Import(adderTuple.Item1);
- adderRef = Module.Import(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));
+ var adderRef = Module.ImportReference(adderTuple.Item1);
+ adderRef = Module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));
Context.IL.Emit(OpCodes.Ldloc, parent);
Context.IL.Emit(OpCodes.Callvirt, propertyGetterRef);
@@ -256,23 +256,23 @@ namespace Xamarin.Forms.Build.Tasks
{
var markExt = markupExtension.Resolve();
var provideValueInfo = markExt.Methods.First(md => md.Name == "ProvideValue");
- var provideValue = module.Import(provideValueInfo);
+ var provideValue = module.ImportReference(provideValueInfo);
provideValue =
- module.Import(provideValue.ResolveGenericParameters(markupExtension, module));
+ module.ImportReference(provideValue.ResolveGenericParameters(markupExtension, module));
var typeNode = node.Properties[new XmlName("", "Type")];
TypeReference arrayTypeRef;
if (context.TypeExtensions.TryGetValue(typeNode, out arrayTypeRef))
- vardefref.VariableDefinition = new VariableDefinition(module.Import(arrayTypeRef.MakeArrayType()));
+ vardefref.VariableDefinition = new VariableDefinition(module.ImportReference(arrayTypeRef.MakeArrayType()));
else
- vardefref.VariableDefinition = new VariableDefinition(module.Import(genericArguments.First()));
+ vardefref.VariableDefinition = new VariableDefinition(module.ImportReference(genericArguments.First()));
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[node]);
foreach (var instruction in node.PushServiceProvider(context, bpRef, propertyRef, propertyDeclaringTypeRef))
yield return instruction;
yield return Instruction.Create(OpCodes.Callvirt, provideValue);
if (arrayTypeRef != null)
- yield return Instruction.Create(OpCodes.Castclass, module.Import(arrayTypeRef.MakeArrayType()));
+ yield return Instruction.Create(OpCodes.Castclass, module.ImportReference(arrayTypeRef.MakeArrayType()));
yield return Instruction.Create(OpCodes.Stloc, vardefref.VariableDefinition);
}
else if (vardefref.VariableDefinition.VariableType.ImplementsGenericInterface("Xamarin.Forms.Xaml.IMarkupExtension`1",
@@ -284,22 +284,22 @@ namespace Xamarin.Forms.Build.Tasks
var markExt = markupExtension.Resolve();
var provideValueInfo = markExt.Methods.First(md => md.Name == "ProvideValue");
- var provideValue = module.Import(provideValueInfo);
+ var provideValue = module.ImportReference(provideValueInfo);
provideValue =
- module.Import(provideValue.ResolveGenericParameters(markupExtension, module));
+ module.ImportReference(provideValue.ResolveGenericParameters(markupExtension, module));
- vardefref.VariableDefinition = new VariableDefinition(module.Import(genericArguments.First()));
+ vardefref.VariableDefinition = new VariableDefinition(module.ImportReference(genericArguments.First()));
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[node]);
foreach (var instruction in node.PushServiceProvider(context, bpRef, propertyRef, propertyDeclaringTypeRef))
yield return instruction;
yield return Instruction.Create(OpCodes.Callvirt, provideValue);
yield return Instruction.Create(OpCodes.Stloc, vardefref.VariableDefinition);
}
- else if (context.Variables[node].VariableType.ImplementsInterface(module.Import(typeof (IMarkupExtension))))
+ else if (context.Variables[node].VariableType.ImplementsInterface(module.ImportReference(typeof (IMarkupExtension))))
{
- var markExt = module.Import(typeof (IMarkupExtension)).Resolve();
+ var markExt = module.ImportReference(typeof (IMarkupExtension)).Resolve();
var provideValueInfo = markExt.Methods.First(md => md.Name == "ProvideValue");
- var provideValue = module.Import(provideValueInfo);
+ var provideValue = module.ImportReference(provideValueInfo);
vardefref.VariableDefinition = new VariableDefinition(module.TypeSystem.Object);
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[node]);
@@ -308,11 +308,11 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Callvirt, provideValue);
yield return Instruction.Create(OpCodes.Stloc, vardefref.VariableDefinition);
}
- else if (context.Variables[node].VariableType.ImplementsInterface(module.Import(typeof (IValueProvider))))
+ else if (context.Variables[node].VariableType.ImplementsInterface(module.ImportReference(typeof (IValueProvider))))
{
var valueProviderType = context.Variables[node].VariableType;
//If the IValueProvider has a ProvideCompiledAttribute that can be resolved, shortcut this
- var compiledValueProviderName = valueProviderType?.GetCustomAttribute(module.Import(typeof(ProvideCompiledAttribute)))?.ConstructorArguments?[0].Value as string;
+ var compiledValueProviderName = valueProviderType?.GetCustomAttribute(module.ImportReference(typeof(ProvideCompiledAttribute)))?.ConstructorArguments?[0].Value as string;
Type compiledValueProviderType;
if (compiledValueProviderName != null && (compiledValueProviderType = Type.GetType(compiledValueProviderName)) != null) {
var compiledValueProvider = Activator.CreateInstance(compiledValueProviderType);
@@ -327,9 +327,9 @@ namespace Xamarin.Forms.Build.Tasks
yield break;
}
- var valueProviderDef = module.Import(typeof (IValueProvider)).Resolve();
+ var valueProviderDef = module.ImportReference(typeof (IValueProvider)).Resolve();
var provideValueInfo = valueProviderDef.Methods.First(md => md.Name == "ProvideValue");
- var provideValue = module.Import(provideValueInfo);
+ var provideValue = module.ImportReference(provideValueInfo);
vardefref.VariableDefinition = new VariableDefinition(module.TypeSystem.Object);
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[node]);
@@ -372,16 +372,16 @@ namespace Xamarin.Forms.Build.Tasks
var properties = ParsePath(path, tSourceRef, node as IXmlLineInfo, context.Module);
var tPropertyRef = properties != null && properties.Any() ? properties.Last().Item1.PropertyType : tSourceRef;
- var funcRef = context.Module.Import(context.Module.Import(typeof(Func<,>)).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
- var actionRef = context.Module.Import(context.Module.Import(typeof(Action<,>)).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
- var funcObjRef = context.Module.Import(context.Module.Import(typeof(Func<,>)).MakeGenericInstanceType(new [] { tSourceRef, context.Module.TypeSystem.Object }));
- var tupleRef = context.Module.Import(context.Module.Import(typeof(Tuple<,>)).MakeGenericInstanceType(new [] { funcObjRef, context.Module.TypeSystem.String}));
- var typedBindingRef = context.Module.Import(context.Module.Import(typeof(TypedBinding<,>)).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef}));
+ var funcRef = context.Module.ImportReference(context.Module.ImportReference(typeof(Func<,>)).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
+ var actionRef = context.Module.ImportReference(context.Module.ImportReference(typeof(Action<,>)).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
+ var funcObjRef = context.Module.ImportReference(context.Module.ImportReference(typeof(Func<,>)).MakeGenericInstanceType(new [] { tSourceRef, context.Module.TypeSystem.Object }));
+ var tupleRef = context.Module.ImportReference(context.Module.ImportReference(typeof(Tuple<,>)).MakeGenericInstanceType(new [] { funcObjRef, context.Module.TypeSystem.String}));
+ var typedBindingRef = context.Module.ImportReference(context.Module.ImportReference(typeof(TypedBinding<,>)).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef}));
TypeReference _;
- var ctorInfo = context.Module.Import(typedBindingRef.Resolve().Methods.FirstOrDefault(md => md.IsConstructor && !md.IsStatic && md.Parameters.Count == 3 ));
+ var ctorInfo = context.Module.ImportReference(typedBindingRef.Resolve().Methods.FirstOrDefault(md => md.IsConstructor && !md.IsStatic && md.Parameters.Count == 3 ));
var ctorinforef = ctorInfo.MakeGeneric(typedBindingRef, funcRef, actionRef, tupleRef);
- var setTypedBinding = context.Module.Import(typeof(BindingExtension)).GetProperty(pd => pd.Name == "TypedBinding", out _).SetMethod;
+ var setTypedBinding = context.Module.ImportReference(typeof(BindingExtension)).GetProperty(pd => pd.Name == "TypedBinding", out _).SetMethod;
yield return Instruction.Create(OpCodes.Ldloc, bindingExt);
foreach (var instruction in CompiledBindingGetGetter(tSourceRef, tPropertyRef, properties, node, context))
@@ -390,8 +390,8 @@ namespace Xamarin.Forms.Build.Tasks
yield return instruction;
foreach (var instruction in CompiledBindingGetHandlers(tSourceRef, tPropertyRef, properties, node, context))
yield return instruction;
- yield return Instruction.Create(OpCodes.Newobj, context.Module.Import(ctorinforef));
- yield return Instruction.Create(OpCodes.Callvirt, context.Module.Import(setTypedBinding));
+ yield return Instruction.Create(OpCodes.Newobj, context.Module.ImportReference(ctorinforef));
+ yield return Instruction.Create(OpCodes.Callvirt, context.Module.ImportReference(setTypedBinding));
}
static IList> ParsePath(string path, TypeReference tSourceRef, IXmlLineInfo lineInfo, ModuleDefinition module)
@@ -431,7 +431,7 @@ namespace Xamarin.Forms.Build.Tasks
previousPartTypeRef = property.PropertyType;
}
if (indexArg != null) {
- var defaultMemberAttribute = previousPartTypeRef.GetCustomAttribute(module.Import(typeof(System.Reflection.DefaultMemberAttribute)));
+ var defaultMemberAttribute = previousPartTypeRef.GetCustomAttribute(module.ImportReference(typeof(System.Reflection.DefaultMemberAttribute)));
var indexerName = defaultMemberAttribute?.ConstructorArguments?.FirstOrDefault().Value as string ?? "Item";
var indexer = previousPartTypeRef.GetProperty(pd => pd.Name == indexerName && pd.GetMethod != null && pd.GetMethod.IsPublic, out _);
properties.Add(new Tuple(indexer, indexArg));
@@ -456,7 +456,7 @@ namespace Xamarin.Forms.Build.Tasks
// }
var module = context.Module;
- var compilerGeneratedCtor = module.Import(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
+ var compilerGeneratedCtor = module.ImportReference(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
var getter = new MethodDefinition($"<{context.Body.Method.Name}>typedBindingsM__{typedBindingCount++}",
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static,
tPropertyRef) {
@@ -464,7 +464,7 @@ namespace Xamarin.Forms.Build.Tasks
new ParameterDefinition(tSourceRef)
},
CustomAttributes = {
- new CustomAttribute (context.Module.Import(compilerGeneratedCtor))
+ new CustomAttribute (context.Module.ImportReference(compilerGeneratedCtor))
}
};
var il = getter.Body.GetILProcessor();
@@ -484,7 +484,7 @@ namespace Xamarin.Forms.Build.Tasks
il.Emit(OpCodes.Ldc_I4, index);
}
}
- il.Emit(OpCodes.Callvirt, module.Import(property.GetMethod));
+ il.Emit(OpCodes.Callvirt, module.ImportReference(property.GetMethod));
}
}
@@ -492,9 +492,9 @@ namespace Xamarin.Forms.Build.Tasks
context.Body.Method.DeclaringType.Methods.Add(getter);
- var funcRef = module.Import(typeof(Func<,>));
- funcRef = module.Import(funcRef.MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
- var funcCtor = module.Import(funcRef.Resolve().GetConstructors().First());
+ var funcRef = module.ImportReference(typeof(Func<,>));
+ funcRef = module.ImportReference(funcRef.MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
+ var funcCtor = module.ImportReference(funcRef.Resolve().GetConstructors().First());
funcCtor = funcCtor.MakeGeneric(funcRef, new [] { tSourceRef, tPropertyRef });
// IL_0007: ldnull
@@ -503,7 +503,7 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldnull);
yield return Instruction.Create(OpCodes.Ldftn, getter);
- yield return Instruction.Create(OpCodes.Newobj, module.Import(funcCtor));
+ yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(funcCtor));
}
static IEnumerable CompiledBindingGetSetter(TypeReference tSourceRef, TypeReference tPropertyRef, IList> properties, ElementNode node, ILContext context)
@@ -525,7 +525,7 @@ namespace Xamarin.Forms.Build.Tasks
// }
var module = context.Module;
- var compilerGeneratedCtor = module.Import(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
+ var compilerGeneratedCtor = module.ImportReference(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
var setter = new MethodDefinition($"<{context.Body.Method.Name}>typedBindingsM__{typedBindingCount++}",
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static,
module.TypeSystem.Void) {
@@ -534,7 +534,7 @@ namespace Xamarin.Forms.Build.Tasks
new ParameterDefinition(tPropertyRef)
},
CustomAttributes = {
- new CustomAttribute (module.Import(compilerGeneratedCtor))
+ new CustomAttribute (module.ImportReference(compilerGeneratedCtor))
}
};
@@ -560,7 +560,7 @@ namespace Xamarin.Forms.Build.Tasks
il.Emit(OpCodes.Ldc_I4, index);
}
}
- il.Emit(OpCodes.Callvirt, module.Import(property.GetMethod));
+ il.Emit(OpCodes.Callvirt, module.ImportReference(property.GetMethod));
}
var indexer = properties.Last().Item2;
@@ -575,14 +575,14 @@ namespace Xamarin.Forms.Build.Tasks
}
}
il.Emit(OpCodes.Ldarg_1);
- il.Emit(OpCodes.Callvirt, module.Import(setterRef));
+ il.Emit(OpCodes.Callvirt, module.ImportReference(setterRef));
il.Emit(OpCodes.Ret);
context.Body.Method.DeclaringType.Methods.Add(setter);
- var actionRef = module.Import(typeof(Action<,>));
- actionRef = module.Import(actionRef.MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
- var actionCtor = module.Import(actionRef.Resolve().GetConstructors().First());
+ var actionRef = module.ImportReference(typeof(Action<,>));
+ actionRef = module.ImportReference(actionRef.MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
+ var actionCtor = module.ImportReference(actionRef.Resolve().GetConstructors().First());
actionCtor = actionCtor.MakeGeneric(actionRef, new [] { tSourceRef, tPropertyRef });
// IL_0024: ldnull
@@ -590,7 +590,7 @@ namespace Xamarin.Forms.Build.Tasks
// IL_002b: newobj instance void class [mscorlib]System.Action`2::'.ctor'(object, native int)
yield return Instruction.Create(OpCodes.Ldnull);
yield return Instruction.Create(OpCodes.Ldftn, setter);
- yield return Instruction.Create(OpCodes.Newobj, module.Import(actionCtor));
+ yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(actionCtor));
}
static IEnumerable CompiledBindingGetHandlers(TypeReference tSourceRef, TypeReference tPropertyRef, IList> properties, ElementNode node, ILContext context)
@@ -609,7 +609,7 @@ namespace Xamarin.Forms.Build.Tasks
// }
var module = context.Module;
- var compilerGeneratedCtor = module.Import(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
+ var compilerGeneratedCtor = module.ImportReference(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
var partGetters = new List();
if (properties == null || properties.Count == 0) {
@@ -624,7 +624,7 @@ namespace Xamarin.Forms.Build.Tasks
new ParameterDefinition(tSourceRef)
},
CustomAttributes = {
- new CustomAttribute (context.Module.Import(compilerGeneratedCtor))
+ new CustomAttribute (context.Module.ImportReference(compilerGeneratedCtor))
}
};
var il = partGetter.Body.GetILProcessor();
@@ -643,18 +643,18 @@ namespace Xamarin.Forms.Build.Tasks
il.Emit(OpCodes.Ldc_I4, index);
}
}
- il.Emit(OpCodes.Callvirt, module.Import(property.GetMethod));
+ il.Emit(OpCodes.Callvirt, module.ImportReference(property.GetMethod));
}
il.Emit(OpCodes.Ret);
context.Body.Method.DeclaringType.Methods.Add(partGetter);
partGetters.Add(partGetter);
}
- var funcObjRef = context.Module.Import(module.Import(typeof(Func<,>)).MakeGenericInstanceType(new [] { tSourceRef, module.TypeSystem.Object }));
- var tupleRef = context.Module.Import(module.Import(typeof(Tuple<,>)).MakeGenericInstanceType(new [] { funcObjRef, module.TypeSystem.String }));
- var funcCtor = module.Import(funcObjRef.Resolve().GetConstructors().First());
+ var funcObjRef = context.Module.ImportReference(module.ImportReference(typeof(Func<,>)).MakeGenericInstanceType(new [] { tSourceRef, module.TypeSystem.Object }));
+ var tupleRef = context.Module.ImportReference(module.ImportReference(typeof(Tuple<,>)).MakeGenericInstanceType(new [] { funcObjRef, module.TypeSystem.String }));
+ var funcCtor = module.ImportReference(funcObjRef.Resolve().GetConstructors().First());
funcCtor = funcCtor.MakeGeneric(funcObjRef, new [] { tSourceRef, module.TypeSystem.Object });
- var tupleCtor = module.Import(tupleRef.Resolve().GetConstructors().First());
+ var tupleCtor = module.ImportReference(tupleRef.Resolve().GetConstructors().First());
tupleCtor = tupleCtor.MakeGeneric(tupleRef, new [] { funcObjRef, module.TypeSystem.String});
// IL_003a: ldc.i4.2
@@ -686,9 +686,9 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldc_I4, i);
yield return Instruction.Create(OpCodes.Ldnull);
yield return Instruction.Create(OpCodes.Ldftn, partGetters [i]);
- yield return Instruction.Create(OpCodes.Newobj, module.Import(funcCtor));
+ yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(funcCtor));
yield return Instruction.Create(OpCodes.Ldstr, properties [i].Item1.Name);
- yield return Instruction.Create(OpCodes.Newobj, module.Import(tupleCtor));
+ yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(tupleCtor));
yield return Instruction.Create(OpCodes.Stelem_Ref);
}
}
@@ -740,8 +740,8 @@ namespace Xamarin.Forms.Build.Tasks
fd.IsStatic &&
fd.IsPublic, out declaringTypeReference);
if (bpRef != null) {
- bpRef = module.Import(bpRef.ResolveGenericParameters(declaringTypeReference));
- bpRef.FieldType = module.Import(bpRef.FieldType);
+ bpRef = module.ImportReference(bpRef.ResolveGenericParameters(declaringTypeReference));
+ bpRef.FieldType = module.ImportReference(bpRef.FieldType);
}
return bpRef;
}
@@ -791,10 +791,10 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldftn, handler);
//FIXME: eventually get the right ctor instead fo the First() one, just in case another one could exists (not even sure it's possible).
- var ctor = module.Import(eventinfo.EventType.Resolve().GetConstructors().First());
+ var ctor = module.ImportReference(eventinfo.EventType.Resolve().GetConstructors().First());
ctor = ctor.ResolveGenericParameters(eventinfo.EventType, module);
- yield return Instruction.Create(OpCodes.Newobj, module.Import(ctor));
- yield return Instruction.Create(OpCodes.Callvirt, module.Import(eventinfo.AddMethod));
+ yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(ctor));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(eventinfo.AddMethod));
}
static bool CanSetDynamicResource(FieldReference bpRef, INode valueNode, ILContext context)
@@ -815,14 +815,14 @@ namespace Xamarin.Forms.Build.Tasks
{
var module = context.Body.Method.Module;
var varValue = context.Variables [elementNode];
- var setDynamicResource = module.Import(typeof(IDynamicResourceHandler)).Resolve().Methods.First(m => m.Name == "SetDynamicResource");
+ var setDynamicResource = module.ImportReference(typeof(IDynamicResourceHandler)).Resolve().Methods.First(m => m.Name == "SetDynamicResource");
var getKey = typeof(DynamicResource).GetProperty("Key").GetMethod;
yield return Instruction.Create(OpCodes.Ldloc, parent);
yield return Instruction.Create(OpCodes.Ldsfld, bpRef);
yield return Instruction.Create(OpCodes.Ldloc, varValue);
- yield return Instruction.Create(OpCodes.Callvirt, module.Import(getKey));
- yield return Instruction.Create(OpCodes.Callvirt, module.Import(setDynamicResource));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(getKey));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(setDynamicResource));
}
static bool CanSetBinding(FieldReference bpRef, INode valueNode, ILContext context)
@@ -838,18 +838,18 @@ namespace Xamarin.Forms.Build.Tasks
VariableDefinition varValue;
if (!context.Variables.TryGetValue(valueNode as IElementNode, out varValue))
return false;
- var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(module.Import(typeof(BindingBase)), module);
+ var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(module.ImportReference(typeof(BindingBase)), module);
if (implicitOperator != null)
return true;
- return varValue.VariableType.InheritsFromOrImplements(module.Import(typeof(BindingBase)));
+ return varValue.VariableType.InheritsFromOrImplements(module.ImportReference(typeof(BindingBase)));
}
static IEnumerable SetBinding(VariableDefinition parent, FieldReference bpRef, IElementNode elementNode, IXmlLineInfo iXmlLineInfo, ILContext context)
{
var module = context.Body.Method.Module;
var varValue = context.Variables [elementNode];
- var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(module.Import(typeof(BindingBase)), module);
+ var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(module.ImportReference(typeof(BindingBase)), module);
//TODO: check if parent is a BP
var setBinding = typeof(BindableObject).GetMethod("SetBinding", new [] { typeof(BindableProperty), typeof(BindingBase) });
@@ -859,8 +859,8 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldloc, varValue);
if (implicitOperator != null)
// IL_000f: call !0 class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1::op_Implicit(class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1)
- yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator));
- yield return Instruction.Create(OpCodes.Callvirt, module.Import(setBinding));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(implicitOperator));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(setBinding));
}
static bool CanSetValue(FieldReference bpRef, bool attached, INode node, IXmlLineInfo iXmlLineInfo, ILContext context)
@@ -918,14 +918,14 @@ namespace Xamarin.Forms.Build.Tasks
var implicitOperator = varDef.VariableType.GetImplicitOperatorTo(bpTypeRef, module);
yield return Instruction.Create(OpCodes.Ldloc, varDef);
if (implicitOperator != null) {
- yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator));
- varType = module.Import(bpTypeRef);
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(implicitOperator));
+ varType = module.ImportReference(bpTypeRef);
}
if (varType.IsValueType)
yield return Instruction.Create(OpCodes.Box, varType);
}
- yield return Instruction.Create(OpCodes.Callvirt, module.Import(setValue));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(setValue));
}
static bool CanSet(VariableDefinition parent, string localName, INode node, ILContext context)
@@ -975,8 +975,8 @@ namespace Xamarin.Forms.Build.Tasks
// IL_0008: ldstr "foo"
// IL_000d: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.Label::set_Text(string)
- module.Import(parent.VariableType.Resolve());
- var propertySetterRef = module.Import(module.Import(propertySetter).ResolveGenericParameters(declaringTypeReference, module));
+ module.ImportReference(parent.VariableType.Resolve());
+ var propertySetterRef = module.ImportReference(module.ImportReference(propertySetter).ResolveGenericParameters(declaringTypeReference, module));
propertySetterRef.ImportTypes(module);
var propertyType = property.ResolveGenericPropertyType(declaringTypeReference);
var valueNode = node as ValueNode;
@@ -1001,9 +1001,9 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Ldloc, vardef);
if (implicitOperator != null) {
// IL_000f: call !0 class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1::op_Implicit(class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1)
- yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(implicitOperator));
} else if (!vardef.VariableType.IsValueType && propertyType.IsValueType)
- yield return Instruction.Create(OpCodes.Unbox_Any, module.Import(propertyType));
+ yield return Instruction.Create(OpCodes.Unbox_Any, module.ImportReference(propertyType));
else if (vardef.VariableType.IsValueType && propertyType.FullName == "System.Object")
yield return Instruction.Create(OpCodes.Box, vardef.VariableType);
if (parent.VariableType.IsValueType)
@@ -1028,8 +1028,8 @@ namespace Xamarin.Forms.Build.Tasks
return false;
var vardef = context.Variables [elementNode];
- var propertyGetterRef = module.Import(propertyGetter);
- propertyGetterRef = module.Import(propertyGetterRef.ResolveGenericParameters(declaringTypeReference, module));
+ var propertyGetterRef = module.ImportReference(propertyGetter);
+ propertyGetterRef = module.ImportReference(propertyGetterRef.ResolveGenericParameters(declaringTypeReference, module));
var propertyType = propertyGetterRef.ReturnType.ResolveGenericParameters(declaringTypeReference);
//TODO check md.Parameters[0] type
@@ -1048,13 +1048,13 @@ namespace Xamarin.Forms.Build.Tasks
var propertyGetter = property.GetMethod;
var elementNode = node as IElementNode;
var vardef = context.Variables [elementNode];
- var propertyGetterRef = module.Import(propertyGetter);
- propertyGetterRef = module.Import(propertyGetterRef.ResolveGenericParameters(declaringTypeReference, module));
+ var propertyGetterRef = module.ImportReference(propertyGetter);
+ propertyGetterRef = module.ImportReference(propertyGetterRef.ResolveGenericParameters(declaringTypeReference, module));
var propertyType = propertyGetterRef.ReturnType.ResolveGenericParameters(declaringTypeReference);
//TODO check md.Parameters[0] type
var adderTuple = propertyType.GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, module).FirstOrDefault();
- var adderRef = module.Import(adderTuple.Item1);
- adderRef = module.Import(adderRef.ResolveGenericParameters(adderTuple.Item2, module));
+ var adderRef = module.ImportReference(adderTuple.Item1);
+ adderRef = module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, module));
var childType = GetParameterType(adderRef.Parameters [0]);
var implicitOperator = vardef.VariableType.GetImplicitOperatorTo(childType, module);
@@ -1062,7 +1062,7 @@ namespace Xamarin.Forms.Build.Tasks
yield return Instruction.Create(OpCodes.Callvirt, propertyGetterRef);
yield return Instruction.Create(OpCodes.Ldloc, vardef);
if (implicitOperator != null)
- yield return Instruction.Create(OpCodes.Call, module.Import(implicitOperator));
+ yield return Instruction.Create(OpCodes.Call, module.ImportReference(implicitOperator));
if (implicitOperator == null && vardef.VariableType.IsValueType && !childType.IsValueType)
yield return Instruction.Create(OpCodes.Box, vardef.VariableType);
yield return Instruction.Create(OpCodes.Callvirt, adderRef);
@@ -1105,7 +1105,7 @@ namespace Xamarin.Forms.Build.Tasks
var module = parentContext.Module;
- var compilerGeneratedCtor = module.Import(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
+ var compilerGeneratedCtor = module.ImportReference(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute)).GetMethods(md => md.IsConstructor, module).First().Item1;
var anonType = new TypeDefinition(
null,
"<" + parentContext.Body.Method.Name + ">_anonXamlCDataTemplate_" + dtcount++,
@@ -1115,7 +1115,7 @@ namespace Xamarin.Forms.Build.Tasks
{
BaseType = module.TypeSystem.Object,
CustomAttributes = {
- new CustomAttribute (module.Import(compilerGeneratedCtor))
+ new CustomAttribute (module.ImportReference(compilerGeneratedCtor))
}
};
@@ -1127,7 +1127,7 @@ namespace Xamarin.Forms.Build.Tasks
module.TypeSystem.Object);
anonType.Methods.Add(loadTemplate);
- var parentValues = new FieldDefinition("parentValues", FieldAttributes.Assembly, module.Import(typeof (object[])));
+ var parentValues = new FieldDefinition("parentValues", FieldAttributes.Assembly, module.ImportReference(typeof (object[])));
anonType.Fields.Add(parentValues);
TypeReference rootType = null;
@@ -1179,19 +1179,19 @@ namespace Xamarin.Forms.Build.Tasks
//SetDataTemplate
parentIl.Emit(OpCodes.Ldftn, loadTemplate);
- var funcObjRef = module.Import(typeof(Func