summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Build.Tasks')
-rw-r--r--Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/BindingTypeConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/BoundsTypeConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/ColorTypeConverter.cs12
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/ConstraintTypeConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/ICompiledTypeConverter.cs17
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/LayoutOptionsConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/ThicknessTypeConverter.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledConverters/TypeTypeConverter.cs6
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledMarkupExtensions/StaticExtension.cs8
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/SetterValueProvider.cs2
-rw-r--r--Xamarin.Forms.Build.Tasks/CompiledValueProviders/TriggerValueProvider.cs2
-rw-r--r--Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs52
-rw-r--r--Xamarin.Forms.Build.Tasks/DebugXamlCTask.cs187
-rw-r--r--Xamarin.Forms.Build.Tasks/MethodReferenceExtensions.cs8
-rw-r--r--Xamarin.Forms.Build.Tasks/NodeILExtensions.cs110
-rw-r--r--Xamarin.Forms.Build.Tasks/Properties/AssemblyInfo.cs1
-rw-r--r--Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs16
-rw-r--r--Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs174
-rw-r--r--Xamarin.Forms.Build.Tasks/SetResourcesVisitor.cs12
-rw-r--r--Xamarin.Forms.Build.Tasks/TypeDefinitionExtensions.cs4
-rw-r--r--Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs24
-rw-r--r--Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj14
-rw-r--r--Xamarin.Forms.Build.Tasks/XamlCTask.cs309
-rw-r--r--Xamarin.Forms.Build.Tasks/XamlTask.cs16
-rw-r--r--Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs6
-rw-r--r--Xamarin.Forms.Build.Tasks/packages.config2
29 files changed, 520 insertions, 494 deletions
diff --git a/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/BindablePropertyReferenceExtensions.cs
index 5f1826db..0edc5f59 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<CustomAttribute>();
if (property != null && property.HasCustomAttributes)
diff --git a/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/BindablePropertyConverter.cs
index c78e5184..b46d22dc 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 74990a86..8c8f0411 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 1cc64fc5..88550bf1 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 39527954..cfb9d016 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 18b1810c..e166247d 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 5ed88d0a..d594cb73 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<Instruction> 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<Instruction> 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 e252ed9d..d7c4597f 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/RectangleTypeConverter.cs b/Xamarin.Forms.Build.Tasks/CompiledConverters/RectangleTypeConverter.cs
index a7eda95e..1175dd22 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 e16a8b01..adca4d89 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 93c3ee58..b8f02cc1 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 b7386a8b..4565c64f 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 60c3328f..e417f118 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 f355a528..e00a1c11 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 ff8f84f9..c684e512 100644
--- a/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/CreateObjectVisitor.cs
@@ -48,7 +48,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)) {
@@ -65,7 +65,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;
@@ -150,15 +150,15 @@ namespace Xamarin.Forms.Build.Tasks
} else if (node.CollectionItems.Count == 1 && (vnode = node.CollectionItems.First() as ValueNode) != null &&
implicitOperatorref != null) {
//<FileImageSource>path.png</FileImageSource>
- 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);
@@ -169,7 +169,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);
@@ -177,7 +177,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") {
@@ -442,7 +442,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":
@@ -455,7 +455,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"
@@ -467,29 +467,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;
@@ -510,51 +510,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);
@@ -564,7 +564,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 a8ef874a..1e441c97 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<Exception> thrownExceptions)
+ public override bool Execute(out IList<Exception> 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,114 @@ 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,
AssemblyResolver = resolver
- });
+ })) {
+ foreach (var module in assemblyDefinition.Modules) {
+ Logger.LogLine(2, " Module: {0}", module.Name);
+ foreach (var resource in module.Resources.OfType<EmbeddedResource>()) {
+ 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<EmbeddedResource>())
- {
- 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.Import(typeDef.BaseType.Resolve().GetConstructors().First(c => c.HasParameters == false)));
+ 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.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.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);
+ 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.");
- }
+ 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 {
+ 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 e3b2f3ab..2c0d8ba9 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 cfd22f30..a1eea6c3 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);
- 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 ea4bda34..454c5cb8 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 860ff44e..d810bd80 100644
--- a/Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/SetNamescopesAndRegisterNamesVisitor.cs
@@ -54,7 +54,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<VariableDefinition, IList<string>>(namescopeVarDef, namesInNamescope);
}
@@ -63,7 +63,7 @@ namespace Xamarin.Forms.Build.Tasks
{
var namescopeVarDef = CreateNamescope();
IList<string> namesInNamescope = new List<string>();
- 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<VariableDefinition, IList<string>>(namescopeVarDef, namesInNamescope);
}
@@ -101,12 +101,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;
@@ -115,10 +115,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);
@@ -131,10 +131,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 9cf62221..9c94daf0 100644
--- a/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/SetPropertiesVisitor.cs
@@ -125,14 +125,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);
@@ -176,13 +176,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);
@@ -253,23 +253,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",
@@ -281,22 +281,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]);
@@ -305,11 +305,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);
@@ -324,9 +324,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]);
@@ -369,16 +369,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))
@@ -387,8 +387,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<Tuple<PropertyDefinition, string>> ParsePath(string path, TypeReference tSourceRef, IXmlLineInfo lineInfo, ModuleDefinition module)
@@ -428,7 +428,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<PropertyDefinition, string>(indexer, indexArg));
@@ -453,7 +453,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) {
@@ -461,7 +461,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();
@@ -481,7 +481,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));
}
}
@@ -489,9 +489,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
@@ -500,7 +500,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<Instruction> CompiledBindingGetSetter(TypeReference tSourceRef, TypeReference tPropertyRef, IList<Tuple<PropertyDefinition, string>> properties, ElementNode node, ILContext context)
@@ -522,7 +522,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) {
@@ -531,7 +531,7 @@ namespace Xamarin.Forms.Build.Tasks
new ParameterDefinition(tPropertyRef)
},
CustomAttributes = {
- new CustomAttribute (module.Import(compilerGeneratedCtor))
+ new CustomAttribute (module.ImportReference(compilerGeneratedCtor))
}
};
@@ -557,7 +557,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;
@@ -572,14 +572,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
@@ -587,7 +587,7 @@ namespace Xamarin.Forms.Build.Tasks
// IL_002b: newobj instance void class [mscorlib]System.Action`2<class ViewModel, string>::'.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<Instruction> CompiledBindingGetHandlers(TypeReference tSourceRef, TypeReference tPropertyRef, IList<Tuple<PropertyDefinition, string>> properties, ElementNode node, ILContext context)
@@ -606,7 +606,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<MethodDefinition>();
if (properties == null || properties.Count == 0) {
@@ -621,7 +621,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();
@@ -640,18 +640,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
@@ -683,9 +683,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);
}
}
@@ -737,8 +737,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;
}
@@ -788,10 +788,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)
@@ -812,14 +812,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)
@@ -835,7 +835,7 @@ namespace Xamarin.Forms.Build.Tasks
VariableDefinition varValue;
if (!context.Variables.TryGetValue(valueNode as IElementNode, out varValue))
return false;
- return varValue.VariableType.InheritsFromOrImplements(module.Import(typeof(BindingBase)));
+ return varValue.VariableType.InheritsFromOrImplements(module.ImportReference(typeof(BindingBase)));
}
static IEnumerable<Instruction> SetBinding(VariableDefinition parent, FieldReference bpRef, IElementNode elementNode, IXmlLineInfo iXmlLineInfo, ILContext context)
@@ -849,7 +849,7 @@ namespace Xamarin.Forms.Build.Tasks
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(setBinding));
+ yield return Instruction.Create(OpCodes.Callvirt, module.ImportReference(setBinding));
}
static bool CanSetValue(FieldReference bpRef, bool attached, INode node, IXmlLineInfo iXmlLineInfo, ILContext context)
@@ -907,14 +907,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)
@@ -964,8 +964,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;
@@ -990,9 +990,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<bool>::op_Implicit(class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1<!0>)
- 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)
@@ -1017,8 +1017,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
@@ -1037,13 +1037,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);
@@ -1051,7 +1051,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);
@@ -1094,7 +1094,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++,
@@ -1104,7 +1104,7 @@ namespace Xamarin.Forms.Build.Tasks
{
BaseType = module.TypeSystem.Object,
CustomAttributes = {
- new CustomAttribute (module.Import(compilerGeneratedCtor))
+ new CustomAttribute (module.ImportReference(compilerGeneratedCtor))
}
};
@@ -1116,7 +1116,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;
@@ -1168,19 +1168,19 @@ namespace Xamarin.Forms.Build.Tasks
//SetDataTemplate
parentIl.Emit(OpCodes.Ldftn, loadTemplate);
- var funcObjRef = module.Import(typeof(Func<object>));
+ var funcObjRef = module.ImportReference(typeof(Func<object>));
var funcCtor =
funcObjRef
.Resolve()
.Methods.First(md => md.IsConstructor && md.Parameters.Count == 2)
.ResolveGenericParameters(funcObjRef, module);
- parentIl.Emit(OpCodes.Newobj, module.Import(funcCtor));
+ parentIl.Emit(OpCodes.Newobj, module.ImportReference(funcCtor));
#pragma warning disable 0612
var propertySetter =
- module.Import(typeof (IDataTemplate)).Resolve().Properties.First(p => p.Name == "LoadTemplate").SetMethod;
+ module.ImportReference(typeof (IDataTemplate)).Resolve().Properties.First(p => p.Name == "LoadTemplate").SetMethod;
#pragma warning restore 0612
- parentContext.IL.Emit(OpCodes.Callvirt, module.Import(propertySetter));
+ parentContext.IL.Emit(OpCodes.Callvirt, module.ImportReference(propertySetter));
loadTemplate.Body.Optimize();
}
diff --git a/Xamarin.Forms.Build.Tasks/SetResourcesVisitor.cs b/Xamarin.Forms.Build.Tasks/SetResourcesVisitor.cs
index 95a93393..f046efcb 100644
--- a/Xamarin.Forms.Build.Tasks/SetResourcesVisitor.cs
+++ b/Xamarin.Forms.Build.Tasks/SetResourcesVisitor.cs
@@ -71,7 +71,7 @@ namespace Xamarin.Forms.Build.Tasks
{
// Collection element, implicit content, or implicit collection element.
var parentVar = Context.Variables[(IElementNode)parentNode];
- if (parentVar.VariableType.ImplementsInterface(Module.Import(typeof (IEnumerable))))
+ if (parentVar.VariableType.ImplementsInterface(Module.ImportReference(typeof (IEnumerable))))
{
if ((parentVar.VariableType.FullName == "Xamarin.Forms.ResourceDictionary" ||
parentVar.VariableType.Resolve().BaseType.FullName == "Xamarin.Forms.ResourceDictionary") &&
@@ -96,8 +96,8 @@ namespace Xamarin.Forms.Build.Tasks
Context.IL.Emit(OpCodes.Ldloc, parentVar);
Context.IL.Emit(OpCodes.Ldloc, Context.Variables[node]);
Context.IL.Emit(OpCodes.Callvirt,
- Module.Import(
- Module.Import(typeof (ResourceDictionary))
+ Module.ImportReference(
+ Module.ImportReference(typeof (ResourceDictionary))
.Resolve()
.Methods.Single(md => md.Name == "Add" && md.Parameters.Count == 1)));
}
@@ -127,10 +127,10 @@ namespace Xamarin.Forms.Build.Tasks
var varDef = Context.Variables[node];
Context.IL.Emit(OpCodes.Ldloc, varDef);
if (varDef.VariableType.IsValueType)
- Context.IL.Emit(OpCodes.Box, Module.Import(varDef.VariableType));
+ Context.IL.Emit(OpCodes.Box, Module.ImportReference(varDef.VariableType));
Context.IL.Emit(OpCodes.Callvirt,
- Module.Import(
- Module.Import(typeof (ResourceDictionary))
+ Module.ImportReference(
+ Module.ImportReference(typeof (ResourceDictionary))
.Resolve()
.Methods.Single(md => md.Name == "Add" && md.Parameters.Count == 2)));
}
diff --git a/Xamarin.Forms.Build.Tasks/TypeDefinitionExtensions.cs b/Xamarin.Forms.Build.Tasks/TypeDefinitionExtensions.cs
index 51b3fdbf..bd0b4b49 100644
--- a/Xamarin.Forms.Build.Tasks/TypeDefinitionExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/TypeDefinitionExtensions.cs
@@ -20,7 +20,7 @@ namespace Xamarin.Forms.Build.Tasks
public static MethodDefinition AddDefaultConstructor(this TypeDefinition targetType, Type parentType)
{
var module = targetType.Module;
- var voidType = module.Import(typeof (void));
+ var voidType = module.ImportReference(typeof (void));
var methodAttributes = MethodAttributes.Public |
MethodAttributes.HideBySig |
MethodAttributes.SpecialName |
@@ -35,7 +35,7 @@ namespace Xamarin.Forms.Build.Tasks
if (objectConstructor == null)
objectConstructor = typeof (object).GetConstructor(new Type[0]);
- var baseConstructor = module.Import(objectConstructor);
+ var baseConstructor = module.ImportReference(objectConstructor);
var ctor = new MethodDefinition(".ctor", methodAttributes, voidType)
{
diff --git a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
index a347c2ff..3b69bfd5 100644
--- a/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/TypeReferenceExtensions.cs
@@ -85,7 +85,7 @@ namespace Xamarin.Forms.Build.Tasks
public static bool ImplementsInterface(this TypeReference typeRef, TypeReference @interface)
{
var typeDef = typeRef.Resolve();
- if (typeDef.Interfaces.Any(tr => tr.FullName == @interface.FullName))
+ if (typeDef.Interfaces.Any(tr => tr.InterfaceType.FullName == @interface.FullName))
return true;
var baseTypeRef = typeDef.BaseType;
if (baseTypeRef != null && baseTypeRef.FullName != "System.Object")
@@ -99,13 +99,13 @@ namespace Xamarin.Forms.Build.Tasks
interfaceReference = null;
genericArguments = null;
var typeDef = typeRef.Resolve();
- TypeReference iface;
+ InterfaceImplementation iface;
if ((iface = typeDef.Interfaces.FirstOrDefault(tr =>
- tr.FullName.StartsWith(@interface, StringComparison.Ordinal) &&
- tr.IsGenericInstance && (tr as GenericInstanceType).HasGenericArguments)) != null)
+ tr.InterfaceType.FullName.StartsWith(@interface, StringComparison.Ordinal) &&
+ tr.InterfaceType.IsGenericInstance && (tr.InterfaceType as GenericInstanceType).HasGenericArguments)) != null)
{
- interfaceReference = iface as GenericInstanceType;
- genericArguments = (iface as GenericInstanceType).GenericArguments;
+ interfaceReference = iface.InterfaceType as GenericInstanceType;
+ genericArguments = (iface.InterfaceType as GenericInstanceType).GenericArguments;
return true;
}
var baseTypeRef = typeDef.BaseType;
@@ -157,7 +157,7 @@ namespace Xamarin.Forms.Build.Tasks
var typeDef = typeRef.Resolve();
if (TypeRefComparer.Default.Equals(typeDef, baseClass.Resolve()))
return true;
- if (typeDef.Interfaces.Any(ir => TypeRefComparer.Default.Equals(ir, baseClass)))
+ if (typeDef.Interfaces.Any(ir => TypeRefComparer.Default.Equals(ir.InterfaceType, baseClass)))
return true;
if (typeDef.BaseType == null)
return false;
@@ -201,7 +201,7 @@ namespace Xamarin.Forms.Build.Tasks
{
foreach (var face in typeDef.Interfaces)
{
- var m = face.GetMethod(predicate);
+ var m = face.InterfaceType.GetMethod(predicate);
if (m != null)
return m;
}
@@ -226,13 +226,13 @@ namespace Xamarin.Forms.Build.Tasks
{
foreach (var face in typeDef.Interfaces)
{
- if (face.IsGenericInstance && typeRef is GenericInstanceType)
+ if (face.InterfaceType.IsGenericInstance && typeRef is GenericInstanceType)
{
int i = 0;
foreach (var arg in ((GenericInstanceType)typeRef).GenericArguments)
- ((GenericInstanceType)face).GenericArguments[i++] = module.Import(arg);
+ ((GenericInstanceType)face.InterfaceType).GenericArguments[i++] = module.ImportReference(arg);
}
- foreach (var tuple in face.GetMethods(predicate, module))
+ foreach (var tuple in face.InterfaceType.GetMethods(predicate, module))
yield return tuple;
}
yield break;
@@ -253,7 +253,7 @@ namespace Xamarin.Forms.Build.Tasks
foreach (var op in implicitOperators) {
var cast = op.Item1;
var opDeclTypeRef = op.Item2;
- var castDef = module.Import(cast).ResolveGenericParameters(opDeclTypeRef, module);
+ var castDef = module.ImportReference(cast).ResolveGenericParameters(opDeclTypeRef, module);
var returnType = castDef.ReturnType;
if (returnType.IsGenericParameter)
returnType = ((GenericInstanceType)opDeclTypeRef).GenericArguments [((GenericParameter)returnType).Position];
diff --git a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
index 21c51688..6424c930 100644
--- a/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
+++ b/Xamarin.Forms.Build.Tasks/Xamarin.Forms.Build.Tasks.csproj
@@ -52,16 +52,16 @@
<Reference Include="System.Xml" />
<Reference Include="Microsoft.Build.Tasks.v4.0" />
<Reference Include="Mono.Cecil">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.10.0-beta4\lib\net40\Mono.Cecil.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Mdb">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Mdb.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.10.0-beta4\lib\net40\Mono.Cecil.Mdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Pdb">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Pdb.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.10.0-beta4\lib\net40\Mono.Cecil.Pdb.dll</HintPath>
</Reference>
<Reference Include="Mono.Cecil.Rocks">
- <HintPath>..\packages\Mono.Cecil.0.9.6.4\lib\net45\Mono.Cecil.Rocks.dll</HintPath>
+ <HintPath>..\packages\Mono.Cecil.0.10.0-beta4\lib\net40\Mono.Cecil.Rocks.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
@@ -118,9 +118,6 @@
<Copy SourceFiles="@(_CopyItems)" DestinationFolder="..\.nuspec\" ContinueOnError="true" />
</Target>
<ItemGroup>
- <None Include="packages.config" />
- </ItemGroup>
- <ItemGroup>
<ProjectReference Include="..\Xamarin.Forms.Xaml\Xamarin.Forms.Xaml.csproj">
<Project>{9DB2F292-8034-4E06-89AD-98BBDA4306B9}</Project>
<Name>Xamarin.Forms.Xaml</Name>
@@ -144,4 +141,7 @@
<ItemGroup>
<Folder Include="CompiledConverters\" />
</ItemGroup>
+ <ItemGroup>
+ <None Include="packages.config" />
+ </ItemGroup>
</Project>
diff --git a/Xamarin.Forms.Build.Tasks/XamlCTask.cs b/Xamarin.Forms.Build.Tasks/XamlCTask.cs
index 4e2029c4..c41ddd97 100644
--- a/Xamarin.Forms.Build.Tasks/XamlCTask.cs
+++ b/Xamarin.Forms.Build.Tasks/XamlCTask.cs
@@ -2,9 +2,10 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+
using Mono.Cecil;
using Mono.Cecil.Cil;
-using Mono.Cecil.Rocks;
+
using Xamarin.Forms.Xaml;
namespace Xamarin.Forms.Build.Tasks
@@ -23,9 +24,12 @@ namespace Xamarin.Forms.Build.Tasks
}
internal string Type { get; set; }
+ internal MethodDefinition InitCompForType { get; private set; }
+ internal bool ReadOnly { get; set; }
- public override bool Execute(IList<Exception> thrownExceptions)
+ public override bool Execute(out IList<Exception> thrownExceptions)
{
+ thrownExceptions = null;
Logger = Logger ?? new Logger(null, Verbosity);
Logger.LogLine(1, "Compiling Xaml");
Logger.LogLine(1, "\nAssembly: {0}", Assembly);
@@ -64,175 +68,173 @@ namespace Xamarin.Forms.Build.Tasks
}
}
- var assemblyDefinition = AssemblyDefinition.ReadAssembly(Path.GetFullPath(Assembly), new ReaderParameters
- {
+ var readerParameters = new ReaderParameters {
AssemblyResolver = resolver,
- ReadSymbols = DebugSymbols
- });
-
- CustomAttribute xamlcAttr;
- if (assemblyDefinition.HasCustomAttributes &&
- (xamlcAttr =
- assemblyDefinition.CustomAttributes.FirstOrDefault(
- ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null)
- {
- var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
- if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
- skipassembly = true;
- if ((options & XamlCompilationOptions.Compile) == XamlCompilationOptions.Compile)
- skipassembly = false;
- }
-
- foreach (var module in assemblyDefinition.Modules)
- {
- var skipmodule = skipassembly;
- if (module.HasCustomAttributes &&
- (xamlcAttr =
- module.CustomAttributes.FirstOrDefault(
- ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null)
- {
+ ReadWrite = !ReadOnly,
+ ReadSymbols = DebugSymbols,
+ };
+
+ using (var assemblyDefinition = AssemblyDefinition.ReadAssembly(Path.GetFullPath(Assembly),readerParameters)) {
+ CustomAttribute xamlcAttr;
+ if (assemblyDefinition.HasCustomAttributes &&
+ (xamlcAttr =
+ assemblyDefinition.CustomAttributes.FirstOrDefault(
+ ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null) {
var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
- skipmodule = true;
+ skipassembly = true;
if ((options & XamlCompilationOptions.Compile) == XamlCompilationOptions.Compile)
- skipmodule = false;
+ skipassembly = false;
}
- Logger.LogLine(2, " Module: {0}", module.Name);
- var resourcesToPrune = new List<EmbeddedResource>();
- foreach (var resource in module.Resources.OfType<EmbeddedResource>())
- {
- 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 skiptype = skipmodule;
- if (typeDef.HasCustomAttributes &&
- (xamlcAttr =
- typeDef.CustomAttributes.FirstOrDefault(
- ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null)
- {
+ foreach (var module in assemblyDefinition.Modules) {
+ var skipmodule = skipassembly;
+ if (module.HasCustomAttributes &&
+ (xamlcAttr =
+ module.CustomAttributes.FirstOrDefault(
+ ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null) {
var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
- skiptype = true;
+ skipmodule = true;
if ((options & XamlCompilationOptions.Compile) == XamlCompilationOptions.Compile)
- skiptype = false;
+ skipmodule = false;
}
- if (Type != null)
- skiptype = !(Type == classname);
+ Logger.LogLine(2, " Module: {0}", module.Name);
+ var resourcesToPrune = new List<EmbeddedResource>();
+ foreach (var resource in module.Resources.OfType<EmbeddedResource>()) {
+ 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 skiptype = skipmodule;
+ if (typeDef.HasCustomAttributes &&
+ (xamlcAttr =
+ typeDef.CustomAttributes.FirstOrDefault(
+ ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null) {
+ var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
+ if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
+ skiptype = true;
+ if ((options & XamlCompilationOptions.Compile) == XamlCompilationOptions.Compile)
+ skiptype = false;
+ }
+
+ if (Type != null)
+ skiptype = !(Type == classname);
+
+ if (skiptype) {
+ Logger.LogLine(2, "Has XamlCompilationAttribute set to Skip and not Compile... skipped");
+ continue;
+ }
+
+ var initComp = typeDef.Methods.FirstOrDefault(md => md.Name == "InitializeComponent");
+ if (initComp == null) {
+ Logger.LogLine(2, "no InitializeComponent found... skipped.");
+ continue;
+ }
+ Logger.LogLine(2, "");
+
+ CustomAttribute xamlFilePathAttr;
+ var xamlFilePath = typeDef.HasCustomAttributes && (xamlFilePathAttr = typeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlFilePathAttribute")) != null ?
+ (string)xamlFilePathAttr.ConstructorArguments[0].Value :
+ resource.Name;
+
+ var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime");
+ if (initCompRuntime != null)
+ Logger.LogLine(2, " __InitComponentRuntime already exists... not creating");
+ else {
+ 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.");
+ }
+
+ Logger.LogString(2, " Parsing Xaml... ");
+ var rootnode = ParseXaml(resource.GetResourceStream(), typeDef);
+ if (rootnode == null) {
+ Logger.LogLine(2, "failed.");
+ continue;
+ }
+ Logger.LogLine(2, "done.");
- if (skiptype)
- {
- Logger.LogLine(2, "Has XamlCompilationAttribute set to Skip and not Compile... skipped");
- continue;
- }
+ hasCompiledXamlResources = true;
+
+ Logger.LogString(2, " Replacing {0}.InitializeComponent ()... ", typeDef.Name);
+ Exception e;
+ if (!TryCoreCompile(initComp, initCompRuntime, rootnode, out e)) {
+ success = false;
+ Logger.LogLine(2, "failed.");
+ (thrownExceptions = thrownExceptions ?? new List<Exception>()).Add(e);
+ Logger.LogException(null, null, null, xamlFilePath, e);
+ Logger.LogLine(4, e.StackTrace);
+ continue;
+ }
+ if (Type != null)
+ InitCompForType = initComp;
- var initComp = typeDef.Methods.FirstOrDefault(md => md.Name == "InitializeComponent");
- if (initComp == null)
- {
- Logger.LogLine(2, "no InitializeComponent found... skipped.");
- continue;
- }
- Logger.LogLine(2, "");
-
- CustomAttribute xamlFilePathAttr;
- var xamlFilePath = typeDef.HasCustomAttributes && (xamlFilePathAttr = typeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlFilePathAttribute")) != null ?
- (string)xamlFilePathAttr.ConstructorArguments [0].Value :
- resource.Name;
-
- var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime");
- if (initCompRuntime != null)
- Logger.LogLine(2, " __InitComponentRuntime already exists... not duplicating");
- else {
- Logger.LogString(2, " Duplicating {0}.InitializeComponent () into {0}.__InitComponentRuntime ... ", typeDef.Name);
- initCompRuntime = DuplicateMethodDef(typeDef, initComp, "__InitComponentRuntime");
Logger.LogLine(2, "done.");
- }
-
- Logger.LogString(2, " Parsing Xaml... ");
- var rootnode = ParseXaml(resource.GetResourceStream(), typeDef);
- if (rootnode == null)
- {
- Logger.LogLine(2, "failed.");
- continue;
- }
- Logger.LogLine(2, "done.");
-
- hasCompiledXamlResources = true;
-
- Logger.LogString(2, " Replacing {0}.InitializeComponent ()... ", typeDef.Name);
- Exception e;
- if (!TryCoreCompile(initComp, initCompRuntime, rootnode, out e)) {
- success = false;
- Logger.LogLine(2, "failed.");
- thrownExceptions?.Add(e);
- Logger.LogException(null, null, null, xamlFilePath, e);
- Logger.LogLine(4, e.StackTrace);
- continue;
- }
- Logger.LogLine(2, "done.");
- if (OptimizeIL)
- {
- Logger.LogString(2, " Optimizing IL... ");
- initComp.Body.Optimize();
- Logger.LogLine(2, "done");
- }
+ if (OptimizeIL) {
+ Logger.LogString(2, " Optimizing IL... ");
+ initComp.Body.Optimize();
+ Logger.LogLine(2, "done");
+ }
- if (outputGeneratedILAsCode)
- Logger.LogLine(2, " Decompiling option has been removed. Use a 3rd party decompiler to admire the beauty of the IL generated");
+ if (outputGeneratedILAsCode)
+ Logger.LogLine(2, " Decompiling option has been removed. Use a 3rd party decompiler to admire the beauty of the IL generated");
- resourcesToPrune.Add(resource);
- }
- if (!KeepXamlResources)
- {
- if (resourcesToPrune.Any())
- Logger.LogLine(2, " Removing compiled xaml resources");
- foreach (var resource in resourcesToPrune)
- {
- Logger.LogString(2, " Removing {0}... ", resource.Name);
- module.Resources.Remove(resource);
- Logger.LogLine(2, "done");
+ resourcesToPrune.Add(resource);
+ }
+ if (!KeepXamlResources) {
+ if (resourcesToPrune.Any())
+ Logger.LogLine(2, " Removing compiled xaml resources");
+ foreach (var resource in resourcesToPrune) {
+ Logger.LogString(2, " Removing {0}... ", resource.Name);
+ module.Resources.Remove(resource);
+ Logger.LogLine(2, "done");
+ }
}
- }
- Logger.LogLine(2, "");
- }
+ Logger.LogLine(2, "");
+ }
- if (!hasCompiledXamlResources)
- {
- Logger.LogLine(1, "No compiled resources. Skipping writing assembly.");
- return success;
- }
+ if (!hasCompiledXamlResources) {
+ Logger.LogLine(1, "No compiled resources. Skipping writing assembly.");
+ return success;
+ }
- Logger.LogString(1, "Writing the assembly... ");
- try
- {
- assemblyDefinition.Write(Assembly, new WriterParameters
- {
- WriteSymbols = DebugSymbols
- });
- Logger.LogLine(1, "done.");
- }
- catch (Exception e)
- {
- Logger.LogLine(1, "failed.");
- Logger.LogException(null, null, null, null, e);
- thrownExceptions?.Add(e);
- Logger.LogLine(4, e.StackTrace);
- success = false;
+ if (ReadOnly)
+ return success;
+
+ Logger.LogString(1, "Writing the assembly... ");
+ try {
+ assemblyDefinition.Write(new WriterParameters {
+ WriteSymbols = DebugSymbols,
+ });
+ Logger.LogLine(1, "done.");
+ } catch (Exception e) {
+ Logger.LogLine(1, "failed.");
+ Logger.LogException(null, null, null, null, e);
+ (thrownExceptions = thrownExceptions ?? new List<Exception>()).Add(e);
+ Logger.LogLine(4, e.StackTrace);
+ success = false;
+ }
}
-
return success;
}
@@ -258,7 +260,8 @@ namespace Xamarin.Forms.Build.Tasks
// IL_0031: nop
var nop = Instruction.Create(OpCodes.Nop);
- var getXamlFileProvider = body.Method.Module.Import(body.Method.Module.Import(typeof(Xamarin.Forms.Xaml.Internals.XamlLoader))
+
+ var getXamlFileProvider = body.Method.Module.ImportReference(body.Method.Module.ImportReference(typeof(Xamarin.Forms.Xaml.Internals.XamlLoader))
.Resolve()
.Properties.FirstOrDefault(pd => pd.Name == "XamlFileProvider")
.GetMethod);
@@ -266,14 +269,14 @@ namespace Xamarin.Forms.Build.Tasks
il.Emit(OpCodes.Brfalse, nop);
il.Emit(OpCodes.Call, getXamlFileProvider);
il.Emit(OpCodes.Ldarg_0);
- var getType = body.Method.Module.Import(body.Method.Module.Import(typeof(object))
+ var getType = body.Method.Module.ImportReference(body.Method.Module.ImportReference(typeof(object))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "GetType"));
il.Emit(OpCodes.Call, getType);
- var func = body.Method.Module.Import(body.Method.Module.Import(typeof(Func<Type, string>))
+ var func = body.Method.Module.ImportReference(body.Method.Module.ImportReference(typeof(Func<Type, string>))
.Resolve()
.Methods.FirstOrDefault(md => md.Name == "Invoke"));
- func = func.ResolveGenericParameters(body.Method.Module.Import(typeof(Func<Type, string>)), body.Method.Module);
+ func = func.ResolveGenericParameters(body.Method.Module.ImportReference(typeof(Func<Type, string>)), body.Method.Module);
il.Emit(OpCodes.Callvirt, func);
il.Emit(OpCodes.Brfalse, nop);
il.Emit(OpCodes.Ldarg_0);
diff --git a/Xamarin.Forms.Build.Tasks/XamlTask.cs b/Xamarin.Forms.Build.Tasks/XamlTask.cs
index d4864ac3..0e00f239 100644
--- a/Xamarin.Forms.Build.Tasks/XamlTask.cs
+++ b/Xamarin.Forms.Build.Tasks/XamlTask.cs
@@ -10,6 +10,9 @@ using Microsoft.Build.Utilities;
using Mono.Cecil;
using Xamarin.Forms.Xaml;
+using Mono.Cecil.Cil;
+using Mono.Cecil.Pdb;
+using Mono.Cecil.Mdb;
namespace Xamarin.Forms.Build.Tasks
{
@@ -31,18 +34,11 @@ namespace Xamarin.Forms.Build.Tasks
public override bool Execute()
{
Logger = new Logger(Log, Verbosity);
- return Execute(null);
+ IList<Exception> _;
+ return Execute(out _);
}
- public abstract bool Execute(IList<Exception> thrownExceptions);
-
- protected static MethodDefinition DuplicateMethodDef(TypeDefinition typeDef, MethodDefinition methodDef, string newName)
- {
- var dup = new MethodDefinition(newName, methodDef.Attributes, methodDef.ReturnType);
- dup.Body = methodDef.Body;
- typeDef.Methods.Add(dup);
- return dup;
- }
+ public abstract bool Execute(out IList<Exception> thrownExceptions);
internal static ILRootNode ParseXaml(Stream stream, TypeReference typeReference)
{
diff --git a/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs b/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
index 7682ec86..59b72acc 100644
--- a/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
+++ b/Xamarin.Forms.Build.Tasks/XmlTypeExtensions.cs
@@ -91,7 +91,7 @@ namespace Xamarin.Forms.Build.Tasks
var assemblydefinition = module.Assembly.Name.Name == asm.AssemblyName ?
module.Assembly :
- module.AssemblyResolver.Resolve(asm.AssemblyName);
+ module.AssemblyResolver.Resolve(AssemblyNameReference.Parse(asm.AssemblyName));
type = assemblydefinition.MainModule.GetType(asm.ClrNamespace, name);
if (type == null)
@@ -108,14 +108,14 @@ namespace Xamarin.Forms.Build.Tasks
if (type != null && typeArguments != null && type.HasGenericParameters)
{
type =
- module.Import(type)
+ module.ImportReference(type)
.MakeGenericInstanceType(typeArguments.Select(x => GetTypeReference(x, module, xmlInfo)).ToArray());
}
if (type == null)
throw new XamlParseException(string.Format("Type {0} not found in xmlns {1}", elementName, namespaceURI), xmlInfo);
- return module.Import(type);
+ return module.ImportReference(type);
}
}
} \ No newline at end of file
diff --git a/Xamarin.Forms.Build.Tasks/packages.config b/Xamarin.Forms.Build.Tasks/packages.config
index 0bc4be16..809273bc 100644
--- a/Xamarin.Forms.Build.Tasks/packages.config
+++ b/Xamarin.Forms.Build.Tasks/packages.config
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="Mono.Cecil" version="0.9.6.4" targetFramework="net451" />
+ <package id="Mono.Cecil" version="0.10.0-beta4" targetFramework="net451" />
</packages> \ No newline at end of file