зеркало из https://github.com/DeGsoft/maui-linux.git
[XamlC] cache ImportReference and ImportMethodReference as they're slow (#2025)
* [XamlC] cache ImportReference and ImportMethodReference as they're slow on ns1.4 * more ns14 fixes
This commit is contained in:
Родитель
6100b00662
Коммит
ad1b0d8e15
|
@ -1,7 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
@ -20,14 +17,19 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
if (IsNullOrEmpty(value))
|
||||
throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(Binding)}", node);
|
||||
|
||||
var bindingCtorRef = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Binding"), paramCount: 6);
|
||||
yield return Instruction.Create(OpCodes.Ldstr, value);
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, (int)BindingMode.Default);
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Instruction.Create(OpCodes.Newobj, bindingCtorRef);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Binding"), parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "BindingMode"),
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "IValueConverter"),
|
||||
("mscorlib", "System", "Object"),
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System", "Object")}));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -67,9 +67,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield return Instruction.Create(OpCodes.Ldc_R8, y);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, w);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, h);
|
||||
|
||||
var rectangleCtorRef = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Rectangle"), paramCount: 4);
|
||||
yield return Instruction.Create(OpCodes.Newobj, rectangleCtorRef);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Rectangle"), parameterTypes: new[] {
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double")}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,10 +29,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield return Instruction.Create(OpCodes.Ldc_R8, color.B);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, color.A);
|
||||
|
||||
var colorCtorRef = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Color"),
|
||||
paramCount: 4,
|
||||
predicate: md => md.Parameters.All(p => p.ParameterType.FullName == "System.Double"));
|
||||
yield return Instruction.Create(OpCodes.Newobj, colorCtorRef);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Color"), parameterTypes: new[] {
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double")}));
|
||||
yield break;
|
||||
}
|
||||
var parts = value.Split('.');
|
||||
|
@ -41,14 +42,12 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
|
||||
var fieldReference = module.ImportFieldReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Color"),
|
||||
color,
|
||||
fd => fd.IsStatic);
|
||||
isStatic: true);
|
||||
if (fieldReference != null) {
|
||||
yield return Instruction.Create(OpCodes.Ldsfld, fieldReference);
|
||||
yield break;
|
||||
}
|
||||
var propertyGetterReference = module.ImportPropertyGetterReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Color"),
|
||||
color,
|
||||
pd => pd.GetMethod.IsStatic);
|
||||
var propertyGetterReference = module.ImportPropertyGetterReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Color"), color, isStatic: true);
|
||||
if (propertyGetterReference != null) {
|
||||
yield return Instruction.Create(OpCodes.Call, propertyGetterReference);
|
||||
yield break;
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
class ConstraintTypeConverter : ICompiledTypeConverter
|
||||
|
@ -21,12 +22,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
if (string.IsNullOrEmpty(value) || !double.TryParse(value, NumberStyles.Number, CultureInfo.InvariantCulture, out size))
|
||||
throw new XamlParseException($"Cannot convert \"{value}\" into {typeof(Constraint)}", node);
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, size);
|
||||
var constantReference = module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Constraint"),
|
||||
methodName: "Constant",
|
||||
paramCount: 1,
|
||||
predicate: md => md.IsStatic);
|
||||
yield return Instruction.Create(OpCodes.Call, constantReference);
|
||||
yield return Create(Ldc_R8, size);
|
||||
yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Constraint"),
|
||||
methodName: "Constant",
|
||||
parameterTypes: new[] { ("mscorlib", "System", "Double") },
|
||||
isStatic: true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
|
||||
var fieldReference = module.ImportFieldReference(("Xamarin.Forms.Core", "Xamarin.Forms", "LayoutOptions"),
|
||||
fieldName: options,
|
||||
predicate: fd => fd.IsStatic);
|
||||
isStatic: true);
|
||||
if (fieldReference != null) {
|
||||
yield return Instruction.Create(OpCodes.Ldsfld, fieldReference);
|
||||
yield break;
|
||||
|
|
|
@ -2,12 +2,14 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
class ListStringTypeConverter : ICompiledTypeConverter
|
||||
|
@ -17,25 +19,22 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
var module = context.Body.Method.Module;
|
||||
|
||||
if (value == null) {
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Create(Ldnull);
|
||||
yield break;
|
||||
}
|
||||
var parts = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToList();
|
||||
|
||||
var add = module.ImportMethodReference(("mscorlib", "System.Collections.Generic", "ICollection`1"),
|
||||
methodName: "Add",
|
||||
paramCount: 1,
|
||||
classArguments: new[] { ("mscorlib", "System", "String") });
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, parts.Count);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("System.Collections", "System.Collections.Generic", "List`1"),
|
||||
paramCount: 1,
|
||||
predicate: md => md.Parameters[0].ParameterType.FullName == "System.Int32",
|
||||
classArguments: new[] { ("mscorlib", "System", "String") }));
|
||||
yield return Create(Ldc_I4, parts.Count);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("System.Collections", "System.Collections.Generic", "List`1"),
|
||||
parameterTypes: new[] { ("mscorlib", "System", "Int32") },
|
||||
classArguments: new[] { ("mscorlib", "System", "String") }));
|
||||
foreach (var part in parts) {
|
||||
yield return Instruction.Create(OpCodes.Dup);
|
||||
yield return Instruction.Create(OpCodes.Ldstr, part);
|
||||
yield return Instruction.Create(OpCodes.Callvirt, add);
|
||||
yield return Create(Dup);
|
||||
yield return Create(Ldstr, part);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("mscorlib", "System.Collections.Generic", "ICollection`1"),
|
||||
methodName: "Add",
|
||||
paramCount: 1,
|
||||
classArguments: new[] { ("mscorlib", "System", "String") }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,13 +49,15 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield return Create(Stloc, uriVarDef);
|
||||
yield return Create(Ldstr, resourcePath); //resourcePath
|
||||
yield return Create(Ldtoken, module.ImportReference(((ILRootNode)rootNode).TypeReference));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", parameterTypes: new[] { ("mscorlib", "System", "Type") }, isStatic: true));
|
||||
yield return Create(Callvirt, module.ImportPropertyGetterReference(("mscorlib", "System.Reflection", "TypeInfo"), propertyName: "Assembly", flatten: true));
|
||||
|
||||
foreach (var instruction in node.PushXmlLineInfo(context))
|
||||
yield return instruction; //lineinfo
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "ResourceDictionary"), methodName: "SetAndLoadSource", paramCount: 4));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "ResourceDictionary"),
|
||||
methodName: "SetAndLoadSource",
|
||||
parameterTypes: new[] { ("System", "System", "Uri"), ("mscorlib", "System", "String"), ("mscorlib", "System.Reflection", "Assembly"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") }));
|
||||
//ldloc the stored uri as return value
|
||||
yield return Create(Ldloc, uriVarDef);
|
||||
}
|
||||
|
|
|
@ -42,8 +42,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield return Instruction.Create(OpCodes.Ldc_R8, y);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, w);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, h);
|
||||
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Rectangle"), paramCount: 4));
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Rectangle"), parameterTypes: new[] {
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double"),
|
||||
("mscorlib", "System", "Double")}));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -45,8 +45,7 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
foreach (var d in args)
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, d);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Thickness"),
|
||||
paramCount: args.Length));
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Thickness"), parameterTypes: args.Select(a => ("mscorlib", "System", "Double")).ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,12 +2,14 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
class TypeTypeConverter : ICompiledTypeConverter
|
||||
|
@ -33,8 +35,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
if (typeRef == null)
|
||||
goto error;
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeRef));
|
||||
yield return Instruction.Create(OpCodes.Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Ldtoken, module.ImportReference(typeRef));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"),
|
||||
methodName: "GetTypeFromHandle",
|
||||
parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") },
|
||||
isStatic: true));
|
||||
|
||||
yield break;
|
||||
|
||||
|
|
|
@ -24,12 +24,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield break;
|
||||
}
|
||||
|
||||
var uriCtorRef = module.ImportCtorReference(("System", "System", "Uri"),
|
||||
paramCount: 2,
|
||||
predicate: md => md.Parameters[1].ParameterType.FullName == "System.UriKind");
|
||||
yield return Create(Ldstr, value);
|
||||
yield return Create(Ldc_I4_0); //UriKind.RelativeOrAbsolute
|
||||
yield return Create(Newobj, uriCtorRef);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("System", "System", "Uri"), parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("System", "System", "UriKind")}));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using System.Xml;
|
||||
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
{
|
||||
|
@ -29,15 +34,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
|
||||
var typeref = module.ImportReference(XmlTypeExtensions.GetTypeReference(valueNode.Value as string, module, node as BaseNode));
|
||||
if (typeref == null)
|
||||
throw new XamlParseException($"Can't resolve type `{valueNode.Value}'.", node as IXmlLineInfo);
|
||||
|
||||
context.TypeExtensions[node] = typeref;
|
||||
context.TypeExtensions[node] = typeref ?? throw new XamlParseException($"Can't resolve type `{valueNode.Value}'.", node as IXmlLineInfo);
|
||||
|
||||
return new List<Instruction> {
|
||||
Instruction.Create(OpCodes.Ldtoken, module.ImportReference(typeref)),
|
||||
Instruction.Create(OpCodes.Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic)),
|
||||
|
||||
Create(Ldtoken, module.ImportReference(typeref)),
|
||||
Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"),
|
||||
methodName: "GetTypeFromHandle",
|
||||
parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") },
|
||||
isStatic: true)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using System.Xml;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
@ -13,7 +10,6 @@ using Xamarin.Forms.Xaml;
|
|||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
class StyleSheetProvider : ICompiledValueProvider
|
||||
|
@ -48,8 +44,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield return Create(Ldstr, style);
|
||||
yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.StyleSheets", "StyleSheet"),
|
||||
methodName: "FromString",
|
||||
paramCount: 1,
|
||||
predicate: md => md.IsStatic));
|
||||
parameterTypes: new[] { ("mscorlib", "System", "String") },
|
||||
isStatic: true));
|
||||
}
|
||||
else {
|
||||
var source = (sourceNode as ValueNode)?.Value as string;
|
||||
|
@ -67,8 +63,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
throw new XamlParseException($"Resource '{source}' not found.", node);
|
||||
|
||||
yield return Create(Ldtoken, module.ImportReference(((ILRootNode)rootNode).TypeReference));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", parameterTypes: new[] { ("mscorlib", "System", "Type") }, isStatic: true));
|
||||
yield return Create(Callvirt, module.ImportPropertyGetterReference(("mscorlib", "System.Reflection", "TypeInfo"), propertyName: "Assembly", flatten: true));
|
||||
|
||||
yield return Create(Ldstr, resourceId); //resourceId
|
||||
|
@ -78,8 +74,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
|
||||
yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.StyleSheets", "StyleSheet"),
|
||||
methodName: "FromAssemblyResource",
|
||||
paramCount: 3,
|
||||
predicate: md => md.IsStatic));
|
||||
parameterTypes: new[] { ("mscorlib", "System.Reflection", "Assembly"), ("mscorlib", "System", "String"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") },
|
||||
isStatic: true));
|
||||
}
|
||||
|
||||
//the variable is of type `object`. fix that
|
||||
|
|
|
@ -437,22 +437,24 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
// IL_0016: pop
|
||||
yield return Create(Ldstr, valueString);
|
||||
yield return Create(Ldc_I4, 0x6f); //NumberStyles.Number
|
||||
var getInvariant = module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
propertyName: "InvariantCulture");
|
||||
yield return Create(Call, getInvariant);
|
||||
yield return Create(Call, module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
propertyName: "InvariantCulture",
|
||||
isStatic: true));
|
||||
yield return Create(Ldloca, vardef);
|
||||
var tryParse = module.ImportMethodReference(("mscorlib", "System", "Decimal"),
|
||||
methodName: "TryParse",
|
||||
paramCount: 4);
|
||||
yield return Create(Call, tryParse);
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Decimal"),
|
||||
methodName: "TryParse",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System.Globalization", "NumberStyles"),
|
||||
("mscorlib", "System", "IFormatProvider"),
|
||||
("mscorlib", "System", "Decimal"),
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
} else {
|
||||
yield return Create(Ldc_I4_0);
|
||||
var decimalctor = module.ImportCtorReference(("mscorlib", "System", "Decimal"),
|
||||
paramCount: 1,
|
||||
predicate: md => md.Parameters[0].ParameterType.FullName == "System.Int32");
|
||||
yield return Create(Newobj, decimalctor);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Decimal"), parameterTypes: new[] { ("mscorlib", "System", "Int32") }));
|
||||
}
|
||||
break;
|
||||
case "System.Single":
|
||||
|
@ -473,23 +475,22 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
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 Create(Ldstr, valueString);
|
||||
var getInvariant = module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
propertyName: "InvariantCulture");
|
||||
yield return Create(Call, getInvariant);
|
||||
yield return Create(Call, module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
propertyName: "InvariantCulture", isStatic: true));
|
||||
yield return Create(Ldloca, vardef);
|
||||
var tryParse = module.ImportMethodReference(("mscorlib", "System", "TimeSpan"),
|
||||
methodName: "TryParse",
|
||||
paramCount: 3);
|
||||
|
||||
yield return Create(Call, tryParse);
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "TimeSpan"),
|
||||
methodName: "TryParse",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System", "IFormatProvider"),
|
||||
("mscorlib", "System", "TimeSpan"),
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
} else {
|
||||
yield return Create(Ldc_I8, 0L);
|
||||
var timespanctor = module.ImportCtorReference(("mscorlib", "System", "TimeSpan"),
|
||||
paramCount: 1,
|
||||
predicate: md => md.Parameters[0].ParameterType.FullName == "System.Int64");
|
||||
yield return Create(Newobj, timespanctor);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "TimeSpan"), parameterTypes: new[] { ("mscorlib", "System", "Int64") }));
|
||||
}
|
||||
break;
|
||||
case "System.Uri":
|
||||
|
@ -500,17 +501,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return Create(Ldstr, valueString);
|
||||
yield return Create(Ldc_I4, (int)UriKind.RelativeOrAbsolute);
|
||||
yield return Create(Ldloca, vardef);
|
||||
var tryCreate = module.ImportMethodReference(("System", "System", "Uri"),
|
||||
methodName: "TryCreate",
|
||||
paramCount: 3);
|
||||
yield return Create(Call, tryCreate);
|
||||
yield return Create(Call, module.ImportMethodReference(("System", "System", "Uri"),
|
||||
methodName: "TryCreate",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("System", "System", "UriKind"),
|
||||
("System", "System", "Uri"),
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
} else
|
||||
yield return Create(Ldnull);
|
||||
break;
|
||||
default:
|
||||
var defaultCtor = module.ImportCtorReference(typedef, paramCount: 0);
|
||||
var defaultCtor = module.ImportCtorReference(typedef, parameterTypes: null);
|
||||
if (defaultCtor != null)
|
||||
yield return Create(Newobj, defaultCtor);
|
||||
else {
|
||||
|
|
|
@ -8,32 +8,35 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
static class ModuleDefinitionExtensions
|
||||
{
|
||||
public static TypeReference ImportReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, (string assemblyName, string clrNamespace, string typeName)[] classArguments = null)
|
||||
static Dictionary<(ModuleDefinition module, string typeKey), TypeReference> TypeRefCache = new Dictionary<(ModuleDefinition module, string typeKey), TypeReference>();
|
||||
public static TypeReference ImportReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type)
|
||||
{
|
||||
var typeRef = module.ImportReference(module.GetTypeDefinition(type));
|
||||
if (classArguments is null)
|
||||
return typeRef;
|
||||
return module.ImportReference(typeRef.MakeGenericInstanceType(classArguments.Select(gp => module.GetTypeDefinition((gp.assemblyName, gp.clrNamespace, gp.typeName))).ToArray()));
|
||||
var typeKey = type.ToString();
|
||||
if (!TypeRefCache.TryGetValue((module, typeKey), out var typeRef))
|
||||
TypeRefCache.Add((module, typeKey), typeRef = module.ImportReference(module.GetTypeDefinition(type)));
|
||||
return typeRef;
|
||||
}
|
||||
|
||||
public static TypeReference ImportReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, (string assemblyName, string clrNamespace, string typeName)[] classArguments)
|
||||
{
|
||||
var typeKey = $"{type}<{string.Join(",",classArguments)}>";
|
||||
if (!TypeRefCache.TryGetValue((module, typeKey), out var typeRef))
|
||||
TypeRefCache.Add((module, typeKey), typeRef = module.ImportReference(module.ImportReference(type).MakeGenericInstanceType(classArguments.Select(gp => module.GetTypeDefinition((gp.assemblyName, gp.clrNamespace, gp.typeName))).ToArray())));
|
||||
return typeRef;
|
||||
}
|
||||
|
||||
public static TypeReference ImportArrayReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type)
|
||||
{
|
||||
var typeRef = module.ImportReference(type);
|
||||
if (typeRef is null)
|
||||
return null;
|
||||
return module.ImportReference(typeRef.MakeArrayType());
|
||||
var typeKey = "${type}[]";
|
||||
if (!TypeRefCache.TryGetValue((module, typeKey), out var typeRef))
|
||||
TypeRefCache.Add((module, typeKey), typeRef = module.ImportReference(module.ImportReference(type).MakeArrayType()));
|
||||
return typeRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, TypeReference type, int paramCount, TypeReference[] classArguments = null, Func<MethodDefinition, bool> predicate = null)
|
||||
static Dictionary<(ModuleDefinition module, string methodRefKey), MethodReference> MethodRefCache = new Dictionary<(ModuleDefinition module, string methodRefKey), MethodReference>();
|
||||
static MethodReference ImportCtorReference(this ModuleDefinition module, TypeReference type, TypeReference[] classArguments, Func<MethodDefinition, bool> predicate)
|
||||
{
|
||||
var ctor = module
|
||||
.ImportReference(type)
|
||||
.ResolveCached()
|
||||
.Methods
|
||||
.FirstOrDefault(md =>
|
||||
md.IsConstructor
|
||||
&& md.Parameters.Count == paramCount
|
||||
&& (predicate?.Invoke(md) ?? true));
|
||||
var ctor = module.ImportReference(type).ResolveCached().Methods.FirstOrDefault(md => !md.IsPrivate && !md.IsStatic && md.IsConstructor && (predicate?.Invoke(md) ?? true));
|
||||
if (ctor is null)
|
||||
return null;
|
||||
var ctorRef = module.ImportReference(ctor);
|
||||
|
@ -42,22 +45,90 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return module.ImportReference(ctorRef.ResolveGenericParameters(type.MakeGenericInstanceType(classArguments), module));
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, int paramCount, (string assemblyName, string clrNamespace, string typeName)[] classArguments, Func<MethodDefinition, bool> predicate = null)
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, TypeReference type, TypeReference[] parameterTypes)
|
||||
{
|
||||
return module.ImportCtorReference(module.GetTypeDefinition(type), paramCount, classArguments?.Select(gp => module.GetTypeDefinition((gp.assemblyName, gp.clrNamespace, gp.typeName))).ToArray(), predicate);
|
||||
var ctorKey = $"{type}.ctor({(parameterTypes == null ? "" : string.Join(",", parameterTypes.Select(tr => (tr.Scope.Name, tr.Namespace, tr.Name))))})";
|
||||
if (MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
return ctorRef;
|
||||
ctorRef = module.ImportCtorReference(type, classArguments: null, predicate: md => {
|
||||
if (md.Parameters.Count != (parameterTypes?.Length ?? 0))
|
||||
return false;
|
||||
for (var i = 0; i < md.Parameters.Count; i++)
|
||||
if (!TypeRefComparer.Default.Equals(md.Parameters[i].ParameterType, module.ImportReference(parameterTypes[i])))
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef);
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, int paramCount, TypeReference[] classArguments, Func<MethodDefinition, bool> predicate = null)
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, int paramCount)
|
||||
{
|
||||
return module.ImportCtorReference(module.GetTypeDefinition(type), paramCount, classArguments, predicate);
|
||||
var ctorKey = $"{type}.ctor({(string.Join(",", Enumerable.Repeat("_", paramCount)))})";
|
||||
if (!MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef = module.ImportCtorReference(module.GetTypeDefinition(type), null, md => md.Parameters.Count == paramCount));
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, int paramCount, Func<MethodDefinition, bool> predicate = null)
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, TypeReference type, int paramCount)
|
||||
{
|
||||
return module.ImportCtorReference(module.GetTypeDefinition(type), paramCount, null, predicate);
|
||||
var ctorKey = $"{type}.ctor({(string.Join(",", Enumerable.Repeat("_", paramCount)))})";
|
||||
if (!MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef = module.ImportCtorReference(type, null, md => md.Parameters.Count == paramCount));
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportPropertyGetterReference(this ModuleDefinition module, TypeReference type, string propertyName, Func<PropertyDefinition, bool> predicate = null, bool flatten = false)
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, int paramCount, (string assemblyName, string clrNamespace, string typeName)[] classArguments)
|
||||
{
|
||||
var ctorKey = $"{type}<{(string.Join(",", classArguments))}>.ctor({(string.Join(",", Enumerable.Repeat("_", paramCount)))})";
|
||||
if (!MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef = module.ImportCtorReference(module.GetTypeDefinition(type), classArguments.Select(module.GetTypeDefinition).ToArray(), md=>md.Parameters.Count==paramCount));
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, int paramCount, TypeReference[] classArguments)
|
||||
{
|
||||
var ctorKey = $"{type}<{(string.Join(",", classArguments.Select(tr => (tr.Scope.Name, tr.Namespace, tr.Name))))}>.ctor({(string.Join(",", Enumerable.Repeat("_", paramCount)))})";
|
||||
if (!MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef = module.ImportCtorReference(module.GetTypeDefinition(type), classArguments, predicate: md => md.Parameters.Count == paramCount));
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, (string assemblyName, string clrNamespace, string typeName)[] parameterTypes, (string assemblyName, string clrNamespace, string typeName)[] classArguments)
|
||||
{
|
||||
var ctorKey = $"{type}<{(string.Join(",", classArguments))}>.ctor({(parameterTypes == null ? "" : string.Join(",", parameterTypes))})";
|
||||
if (MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
return ctorRef;
|
||||
ctorRef = module.ImportCtorReference(module.GetTypeDefinition(type), classArguments.Select(module.GetTypeDefinition).ToArray(), md => {
|
||||
if (md.Parameters.Count != (parameterTypes?.Length ?? 0))
|
||||
return false;
|
||||
for (var i = 0; i < md.Parameters.Count; i++)
|
||||
if (!TypeRefComparer.Default.Equals(md.Parameters[i].ParameterType, module.ImportReference(parameterTypes[i])))
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef);
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
public static MethodReference ImportCtorReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, (string assemblyName, string clrNamespace, string typeName)[] parameterTypes)
|
||||
{
|
||||
var ctorKey = $"{type}.ctor({(parameterTypes == null ? "" : string.Join(",", parameterTypes))})";
|
||||
if (MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
return ctorRef;
|
||||
ctorRef = module.ImportCtorReference(module.GetTypeDefinition(type), classArguments: null, predicate: md => {
|
||||
if (md.Parameters.Count != (parameterTypes?.Length ?? 0))
|
||||
return false;
|
||||
for (var i = 0; i < md.Parameters.Count; i++)
|
||||
if (!TypeRefComparer.Default.Equals(md.Parameters[i].ParameterType, module.ImportReference(parameterTypes[i])))
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef);
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
static MethodReference ImportPropertyGetterReference(this ModuleDefinition module, TypeReference type, string propertyName, Func<PropertyDefinition, bool> predicate = null, bool flatten = false)
|
||||
{
|
||||
var properties = module.ImportReference(type).Resolve().Properties;
|
||||
var getter = module
|
||||
|
@ -66,17 +137,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
.Properties(flatten)
|
||||
.FirstOrDefault(pd =>
|
||||
pd.Name == propertyName
|
||||
&& !pd.GetMethod.IsPrivate
|
||||
&& (predicate?.Invoke(pd) ?? true))
|
||||
?.GetMethod;
|
||||
return getter == null ? null : module.ImportReference(getter);
|
||||
}
|
||||
|
||||
public static MethodReference ImportPropertyGetterReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, string propertyName, Func<PropertyDefinition, bool> predicate = null, bool flatten = false)
|
||||
public static MethodReference ImportPropertyGetterReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, string propertyName, bool isStatic = false, bool flatten = false)
|
||||
{
|
||||
return module.ImportPropertyGetterReference(module.GetTypeDefinition(type), propertyName, predicate, flatten);
|
||||
var getterKey = $"{(isStatic ? "static " : "")}{type}.get_{propertyName}{(flatten ? "*" : "")}";
|
||||
if (!MethodRefCache.TryGetValue((module, getterKey), out var methodReference))
|
||||
MethodRefCache.Add((module, getterKey), methodReference = module.ImportPropertyGetterReference(module.GetTypeDefinition(type), propertyName, pd => pd.GetMethod.IsStatic == isStatic, flatten));
|
||||
return methodReference;
|
||||
}
|
||||
|
||||
public static MethodReference ImportPropertySetterReference(this ModuleDefinition module, TypeReference type, string propertyName, Func<PropertyDefinition, bool> predicate = null)
|
||||
static MethodReference ImportPropertySetterReference(this ModuleDefinition module, TypeReference type, string propertyName, Func<PropertyDefinition, bool> predicate = null)
|
||||
{
|
||||
var setter = module
|
||||
.ImportReference(type)
|
||||
|
@ -84,34 +159,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
.Properties
|
||||
.FirstOrDefault(pd =>
|
||||
pd.Name == propertyName
|
||||
&& !pd.SetMethod.IsPrivate
|
||||
&& (predicate?.Invoke(pd) ?? true))
|
||||
?.SetMethod;
|
||||
return setter == null ? null : module.ImportReference(setter);
|
||||
}
|
||||
|
||||
public static MethodReference ImportPropertySetterReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, string propertyName, Func<PropertyDefinition, bool> predicate = null)
|
||||
public static MethodReference ImportPropertySetterReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, string propertyName, bool isStatic = false)
|
||||
{
|
||||
return module.ImportPropertySetterReference(module.GetTypeDefinition(type), propertyName, predicate);
|
||||
var setterKey = $"{(isStatic ? "static " : "")}{type}.set{propertyName}";
|
||||
if (!MethodRefCache.TryGetValue((module, setterKey), out var methodReference))
|
||||
MethodRefCache.Add((module,setterKey), methodReference = module.ImportPropertySetterReference(module.GetTypeDefinition(type), propertyName, pd => pd.SetMethod.IsStatic == isStatic));
|
||||
return methodReference;
|
||||
}
|
||||
|
||||
public static FieldReference ImportFieldReference(this ModuleDefinition module, TypeReference type, string fieldName, Func<FieldDefinition, bool> predicate = null)
|
||||
{
|
||||
var field = module
|
||||
.ImportReference(type)
|
||||
.ResolveCached()
|
||||
.Fields
|
||||
.FirstOrDefault(fd =>
|
||||
fd.Name == fieldName
|
||||
&& (predicate?.Invoke(fd) ?? true));
|
||||
return field == null ? null : module.ImportReference(field);
|
||||
}
|
||||
|
||||
public static FieldReference ImportFieldReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, string fieldName, Func<FieldDefinition, bool> predicate = null)
|
||||
{
|
||||
return module.ImportFieldReference(module.GetTypeDefinition(type), fieldName: fieldName, predicate: predicate);
|
||||
}
|
||||
|
||||
public static MethodReference ImportMethodReference(this ModuleDefinition module, TypeReference type, string methodName, int paramCount, Func<MethodDefinition, bool> predicate = null, TypeReference[] classArguments = null)
|
||||
static MethodReference ImportMethodReference(this ModuleDefinition module, TypeReference type, string methodName, Func<MethodDefinition, bool> predicate = null, TypeReference[] classArguments = null)
|
||||
{
|
||||
var method = module
|
||||
.ImportReference(type)
|
||||
|
@ -119,8 +181,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
.Methods
|
||||
.FirstOrDefault(md =>
|
||||
!md.IsConstructor
|
||||
&& !md.IsPrivate
|
||||
&& md.Name == methodName
|
||||
&& md.Parameters.Count == paramCount
|
||||
&& (predicate?.Invoke(md) ?? true));
|
||||
if (method is null)
|
||||
return null;
|
||||
|
@ -132,11 +194,74 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
public static MethodReference ImportMethodReference(this ModuleDefinition module,
|
||||
(string assemblyName, string clrNamespace, string typeName) type,
|
||||
string methodName, int paramCount, Func<MethodDefinition, bool> predicate = null,
|
||||
(string assemblyName, string clrNamespace, string typeName)[] classArguments = null)
|
||||
string methodName,
|
||||
(string assemblyName, string clrNamespace, string typeName)[] parameterTypes,
|
||||
(string assemblyName, string clrNamespace, string typeName)[] classArguments = null,
|
||||
bool isStatic = false)
|
||||
{
|
||||
return module.ImportMethodReference(module.GetTypeDefinition(type), methodName, paramCount, predicate,
|
||||
classArguments?.Select(gp => module.GetTypeDefinition((gp.assemblyName, gp.clrNamespace, gp.typeName))).ToArray());
|
||||
var methodKey = $"{(isStatic ? "static " : "")}{type}<{(classArguments == null ? "" : string.Join(",", classArguments))}>.({(parameterTypes == null ? "" : string.Join(",", parameterTypes))})";
|
||||
if (MethodRefCache.TryGetValue((module, methodKey), out var methodReference))
|
||||
return methodReference;
|
||||
methodReference = module.ImportMethodReference(module.GetTypeDefinition(type),
|
||||
methodName: methodName,
|
||||
predicate: md => {
|
||||
if (md.IsStatic != isStatic)
|
||||
return false;
|
||||
if (md.Parameters.Count != (parameterTypes?.Length ?? 0))
|
||||
return false;
|
||||
for (var i = 0; i < md.Parameters.Count; i++)
|
||||
if (!TypeRefComparer.Default.Equals(md.Parameters[i].ParameterType, module.ImportReference(parameterTypes[i])))
|
||||
return false;
|
||||
return true;
|
||||
},
|
||||
classArguments: classArguments?.Select(gp => module.GetTypeDefinition((gp.assemblyName, gp.clrNamespace, gp.typeName))).ToArray());
|
||||
MethodRefCache.Add((module, methodKey), methodReference);
|
||||
return methodReference;
|
||||
}
|
||||
|
||||
public static MethodReference ImportMethodReference(this ModuleDefinition module,
|
||||
(string assemblyName, string clrNamespace, string typeName) type,
|
||||
string methodName,
|
||||
int paramCount,
|
||||
(string assemblyName, string clrNamespace, string typeName)[] classArguments = null,
|
||||
bool isStatic = false)
|
||||
{
|
||||
var methodKey = $"{(isStatic ? "static " : "")}{type}<{(classArguments == null ? "" : string.Join(",", classArguments))}>.({(string.Join(",", Enumerable.Repeat("_", paramCount)))})";
|
||||
if (MethodRefCache.TryGetValue((module, methodKey), out var methodReference))
|
||||
return methodReference;
|
||||
methodReference = module.ImportMethodReference(module.GetTypeDefinition(type),
|
||||
methodName: methodName,
|
||||
predicate: md => {
|
||||
if (md.IsStatic != isStatic)
|
||||
return false;
|
||||
if (md.Parameters.Count != paramCount)
|
||||
return false;
|
||||
return true;
|
||||
},
|
||||
classArguments: classArguments?.Select(gp => module.GetTypeDefinition((gp.assemblyName, gp.clrNamespace, gp.typeName))).ToArray());
|
||||
MethodRefCache.Add((module, methodKey), methodReference);
|
||||
return methodReference;
|
||||
}
|
||||
|
||||
static Dictionary<(ModuleDefinition module, string fieldRefKey), FieldReference> FieldRefCache = new Dictionary<(ModuleDefinition module, string fieldRefKey), FieldReference>();
|
||||
static FieldReference ImportFieldReference(this ModuleDefinition module, TypeReference type, string fieldName, Func<FieldDefinition, bool> predicate = null)
|
||||
{
|
||||
var field = module
|
||||
.ImportReference(type)
|
||||
.ResolveCached()
|
||||
.Fields
|
||||
.FirstOrDefault(fd =>
|
||||
fd.Name == fieldName
|
||||
&& (predicate?.Invoke(fd) ?? true));
|
||||
return field == null ? null : module.ImportReference(field);
|
||||
}
|
||||
|
||||
public static FieldReference ImportFieldReference(this ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) type, string fieldName, bool isStatic = false)
|
||||
{
|
||||
var fieldKey = $"{(isStatic ? "static " : "")}{type}.{fieldName}";
|
||||
if (!FieldRefCache.TryGetValue((module, fieldKey), out var fieldReference))
|
||||
FieldRefCache.Add((module, fieldKey), fieldReference = module.ImportFieldReference(module.GetTypeDefinition(type), fieldName: fieldName, predicate: fd => fd.IsStatic == isStatic));
|
||||
return fieldReference;
|
||||
}
|
||||
|
||||
static Dictionary<(ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName)), TypeDefinition> typeDefCache
|
||||
|
|
|
@ -116,7 +116,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (typeConverter != null)
|
||||
{
|
||||
var isExtendedConverter = typeConverter.ImplementsInterface(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "IExtendedTypeConverter")));
|
||||
var typeConverterCtorRef = module.ImportCtorReference(typeConverter, paramCount: 0, predicate: md => !md.IsStatic);
|
||||
var typeConverterCtorRef = module.ImportCtorReference(typeConverter, paramCount: 0);
|
||||
var convertFromInvariantStringDefinition = isExtendedConverter
|
||||
? module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "IExtendedTypeConverter"))
|
||||
.ResolveCached()
|
||||
|
@ -190,17 +190,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
} else if (targetTypeRef.FullName == "System.TimeSpan") {
|
||||
var ts = TimeSpan.Parse(str, CultureInfo.InvariantCulture);
|
||||
var ticks = ts.Ticks;
|
||||
var timeSpanCtorRef = module.ImportCtorReference(("mscorlib", "System", "TimeSpan"), paramCount: 1);
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldc_I8, ticks);
|
||||
yield return Instruction.Create(OpCodes.Newobj, timeSpanCtorRef);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("mscorlib", "System", "TimeSpan"), parameterTypes: new[] { ("mscorlib", "System", "Int64") }));
|
||||
} else if (targetTypeRef.FullName == "System.DateTime") {
|
||||
var dt = DateTime.Parse(str, CultureInfo.InvariantCulture);
|
||||
var ticks = dt.Ticks;
|
||||
var dateTimeCtorRef = module.ImportCtorReference(("mscorlib", "System", "DateTime"), paramCount: 1);
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldc_I8, ticks);
|
||||
yield return Instruction.Create(OpCodes.Newobj, dateTimeCtorRef);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("mscorlib", "System", "DateTime"), parameterTypes: new[] { ("mscorlib", "System", "Int64") }));
|
||||
} else if (targetTypeRef.FullName == "System.String" && str.StartsWith("{}", StringComparison.Ordinal))
|
||||
yield return Instruction.Create(OpCodes.Ldstr, str.Substring(2));
|
||||
else if (targetTypeRef.FullName == "System.String")
|
||||
|
@ -219,35 +215,36 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
// IL_000f: ldloca.s 0
|
||||
// IL_0011: call bool valuetype [mscorlib]System.Decimal::TryParse(string, valuetype [mscorlib]System.Globalization.NumberStyles, class [mscorlib]System.IFormatProvider, [out] valuetype [mscorlib]System.Decimal&)
|
||||
// IL_0016: pop
|
||||
yield return Instruction.Create(OpCodes.Ldstr, str);
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, 0x6f); //NumberStyles.Number
|
||||
var getInvariant = module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
propertyName: "InvariantCulture");
|
||||
yield return Instruction.Create(OpCodes.Call, getInvariant);
|
||||
yield return Instruction.Create(OpCodes.Ldloca, vardef);
|
||||
var tryParse = module.ImportMethodReference(("mscorlib", "System", "Decimal"),
|
||||
methodName: "TryParse",
|
||||
paramCount: 4);
|
||||
yield return Instruction.Create(OpCodes.Call, tryParse);
|
||||
yield return Instruction.Create(OpCodes.Pop);
|
||||
yield return Instruction.Create(OpCodes.Ldloc, vardef);
|
||||
yield return Create(Ldstr, str);
|
||||
yield return Create(Ldc_I4, 0x6f); //NumberStyles.Number
|
||||
yield return Create(Call, module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
propertyName: "InvariantCulture", isStatic: true));
|
||||
yield return Create(Ldloca, vardef);
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Decimal"),
|
||||
methodName: "TryParse",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System.Globalization", "NumberStyles"),
|
||||
("mscorlib", "System", "IFormatProvider"),
|
||||
("mscorlib", "System", "Decimal"),
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
} else {
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4_0);
|
||||
var decimalctor = module.ImportCtorReference(("mscorlib", "System", "Decimal"),
|
||||
paramCount: 1,
|
||||
predicate: md => md.Parameters[0].ParameterType.FullName == "System.Int32");
|
||||
yield return Instruction.Create(OpCodes.Newobj, decimalctor);
|
||||
yield return Create(Ldc_I4_0);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Decimal"), parameterTypes: new[] { ("mscorlib", "System", "Int32") }));
|
||||
}
|
||||
} else if (implicitOperator != null) {
|
||||
yield return Instruction.Create(OpCodes.Ldstr, node.Value as string);
|
||||
yield return Instruction.Create(OpCodes.Call, module.ImportReference(implicitOperator));
|
||||
yield return Create(Ldstr, node.Value as string);
|
||||
yield return Create(Call, module.ImportReference(implicitOperator));
|
||||
} else
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Create(Ldnull);
|
||||
|
||||
if (isNullable)
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportReference(nullableCtor));
|
||||
yield return Create(Newobj, module.ImportReference(nullableCtor));
|
||||
if (originalTypeRef.IsValueType && boxValueTypes)
|
||||
yield return Instruction.Create(OpCodes.Box, module.ImportReference(originalTypeRef));
|
||||
yield return Create(Box, module.ImportReference(originalTypeRef));
|
||||
}
|
||||
|
||||
static Instruction PushParsedEnum(TypeReference enumRef, string value, IXmlLineInfo lineInfo)
|
||||
|
@ -346,10 +343,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (xmlLineInfo.HasLineInfo()) {
|
||||
yield return Create(Ldc_I4, xmlLineInfo.LineNumber);
|
||||
yield return Create(Ldc_I4, xmlLineInfo.LinePosition);
|
||||
ctor = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "XmlLineInfo"), paramCount: 2);
|
||||
ctor = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "XmlLineInfo"), parameterTypes: new[] {
|
||||
("mscorlib", "System", "Int32"),
|
||||
("mscorlib", "System", "Int32"),
|
||||
});
|
||||
}
|
||||
else
|
||||
ctor = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "XmlLineInfo"), paramCount: 0);
|
||||
ctor = module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "XmlLineInfo"), parameterTypes: null);
|
||||
yield return Create(Newobj, ctor);
|
||||
}
|
||||
|
||||
|
@ -406,17 +406,22 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
//Copy original array to final
|
||||
if (context.ParentContextValues != null)
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Ldarg_0);
|
||||
yield return Instruction.Create(OpCodes.Ldfld, context.ParentContextValues); //sourceArray
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4_0); //sourceIndex
|
||||
yield return Instruction.Create(OpCodes.Ldloc, finalArray); //destinationArray
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, nodes.Count); //destinationIndex
|
||||
yield return Instruction.Create(OpCodes.Ldloc, parentObjectLength); //length
|
||||
var arrayCopy = module.ImportMethodReference(("mscorlib", "System", "Array"),
|
||||
methodName: "Copy",
|
||||
paramCount: 5,
|
||||
predicate: md => md.Parameters[1].ParameterType.FullName == "System.Int32");
|
||||
yield return Instruction.Create(OpCodes.Call, arrayCopy);
|
||||
yield return Create(Ldarg_0);
|
||||
yield return Create(Ldfld, context.ParentContextValues); //sourceArray
|
||||
yield return Create(Ldc_I4_0); //sourceIndex
|
||||
yield return Create(Ldloc, finalArray); //destinationArray
|
||||
yield return Create(Ldc_I4, nodes.Count); //destinationIndex
|
||||
yield return Create(Ldloc, parentObjectLength); //length
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Array"),
|
||||
methodName: "Copy",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "Array"),
|
||||
("mscorlib", "System", "Int32"),
|
||||
("mscorlib", "System", "Array"),
|
||||
("mscorlib", "System", "Int32"),
|
||||
("mscorlib", "System", "Int32"),
|
||||
},
|
||||
isStatic: true));
|
||||
}
|
||||
|
||||
//Add nodes to array
|
||||
|
@ -444,9 +449,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
if (propertyRef != null) {
|
||||
yield return Create(Ldtoken, module.ImportReference(declaringTypeReference ?? propertyRef.DeclaringType));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Ldstr, propertyRef.Name);
|
||||
yield return Create(Call, module.ImportMethodReference(("System.Reflection.Extensions", "System.Reflection", "RuntimeReflectionExtensions"), methodName: "GetRuntimeProperty", paramCount: 2));
|
||||
yield return Create(Call, module.ImportMethodReference(("System.Reflection.Extensions", "System.Reflection", "RuntimeReflectionExtensions"),
|
||||
methodName: "GetRuntimeProperty",
|
||||
parameterTypes: new[]{
|
||||
("mscorlib", "System", "Type"),
|
||||
("mscorlib", "System", "String"),
|
||||
},
|
||||
isStatic: true));
|
||||
yield break;
|
||||
}
|
||||
yield return Create(Ldnull);
|
||||
|
@ -462,17 +473,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield break;
|
||||
#endif
|
||||
|
||||
var addService = module.ImportMethodReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlServiceProvider"), methodName: "Add", paramCount: 2);
|
||||
var getTypeFromHandle = module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic);
|
||||
var addService = module.ImportMethodReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlServiceProvider"),
|
||||
methodName: "Add",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "Type"),
|
||||
("mscorlib", "System", "Object"),
|
||||
});
|
||||
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlServiceProvider"), paramCount: 0));
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlServiceProvider"), parameterTypes: null));
|
||||
|
||||
//Add a SimpleValueTargetProvider
|
||||
var pushParentIl = node.PushParentObjectsArray(context).ToList();
|
||||
if (pushParentIl[pushParentIl.Count - 1].OpCode != Ldnull) {
|
||||
yield return Create(Dup); //Keep the serviceProvider on the stack
|
||||
yield return Create(Ldtoken, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IProvideValueTarget")));
|
||||
yield return Create(Call, getTypeFromHandle);
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
|
||||
foreach (var instruction in pushParentIl)
|
||||
yield return instruction;
|
||||
|
@ -486,10 +501,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
//Add a NamescopeProvider
|
||||
if (context.Scopes.ContainsKey(node)) {
|
||||
yield return Create(Dup); //Dupicate the serviceProvider
|
||||
yield return Create(Dup); //Duplicate the serviceProvider
|
||||
yield return Create(Ldtoken, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml.Internals", "INameScopeProvider")));
|
||||
yield return Create(Call, getTypeFromHandle);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "NameScopeProvider"), paramCount: 0));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "NameScopeProvider"), parameterTypes: null));
|
||||
yield return Create(Dup); //Duplicate the namescopeProvider
|
||||
yield return Create(Ldloc, context.Scopes[node].Item1);
|
||||
yield return Create(Callvirt, module.ImportPropertySetterReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "NameScopeProvider"), propertyName: "NameScope"));
|
||||
|
@ -498,31 +513,36 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
//Add a XamlTypeResolver
|
||||
if (node.NamespaceResolver != null) {
|
||||
yield return Create(Dup); //Dupicate the serviceProvider
|
||||
yield return Create(Dup); //Duplicate the serviceProvider
|
||||
yield return Create(Ldtoken, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IXamlTypeResolver")));
|
||||
yield return Create(Call, getTypeFromHandle);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XmlNamespaceResolver"), paramCount: 0));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XmlNamespaceResolver"), parameterTypes: null));
|
||||
foreach (var kvp in node.NamespaceResolver.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml)) {
|
||||
yield return Create(Dup); //dup the resolver
|
||||
yield return Create(Ldstr, kvp.Key);
|
||||
yield return Create(Ldstr, kvp.Value);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XmlNamespaceResolver"), methodName: "Add", paramCount: 2));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XmlNamespaceResolver"),
|
||||
methodName: "Add",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System", "String"),
|
||||
}));
|
||||
}
|
||||
yield return Create(Ldtoken, context.Body.Method.DeclaringType);
|
||||
yield return Create(Call, getTypeFromHandle);
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", paramCount: 1, predicate: md => md.IsStatic));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", parameterTypes: new[] { ("mscorlib", "System", "Type") }, isStatic: true));
|
||||
yield return Create(Callvirt, module.ImportPropertyGetterReference(("mscorlib", "System.Reflection", "TypeInfo"), propertyName: "Assembly", flatten: true));
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlTypeResolver"), paramCount: 2));
|
||||
yield return Create(Callvirt, addService);
|
||||
}
|
||||
|
||||
if (node is IXmlLineInfo) {
|
||||
yield return Create(Dup); //Dupicate the serviceProvider
|
||||
yield return Create(Dup); //Duplicate the serviceProvider
|
||||
yield return Create(Ldtoken, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IXmlLineInfoProvider")));
|
||||
yield return Create(Call, getTypeFromHandle);
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
foreach (var instruction in node.PushXmlLineInfo(context))
|
||||
yield return instruction;
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XmlLineInfoProvider"), paramCount: 1));
|
||||
yield return Create(Newobj, module.ImportCtorReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XmlLineInfoProvider"), parameterTypes: new[] { ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") }));
|
||||
yield return Create(Callvirt, addService);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,7 +102,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var module = Context.Body.Method.Module;
|
||||
var vardef = new VariableDefinition(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "NameScope")));
|
||||
Context.Body.Variables.Add(vardef);
|
||||
Context.IL.Emit(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "NameScope"), paramCount: 0));
|
||||
Context.IL.Emit(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "NameScope"), parameterTypes: null));
|
||||
Context.IL.Emit(OpCodes.Stloc, vardef);
|
||||
return vardef;
|
||||
}
|
||||
|
@ -114,8 +114,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Context.IL.Emit(OpCodes.Ldloc, ns);
|
||||
Context.IL.Emit(OpCodes.Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "NameScope"),
|
||||
methodName: "SetNameScope",
|
||||
paramCount: 2,
|
||||
predicate: md => md.IsStatic));
|
||||
parameterTypes: new[] {
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"),
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "INameScope"),
|
||||
},
|
||||
isStatic: true));
|
||||
}
|
||||
|
||||
void RegisterName(string str, VariableDefinition namescopeVarDef, IList<string> namesInNamescope, VariableDefinition element, INode node)
|
||||
|
@ -130,7 +133,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Context.IL.Emit(OpCodes.Ldloc, element);
|
||||
Context.IL.Emit(OpCodes.Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "INameScope"),
|
||||
methodName: "RegisterName",
|
||||
paramCount: 2));
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System", "Object"),
|
||||
}));
|
||||
}
|
||||
|
||||
void SetStyleId(string str, VariableDefinition element)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
@ -301,14 +300,16 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var acceptEmptyServiceProvider = context.Variables[node].VariableType.GetCustomAttribute(module, ("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "AcceptEmptyServiceProviderAttribute")) != null;
|
||||
vardefref.VariableDefinition = new VariableDefinition(module.TypeSystem.Object);
|
||||
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[node]);
|
||||
yield return Create(Ldloc, context.Variables[node]);
|
||||
if (acceptEmptyServiceProvider)
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Create(Ldnull);
|
||||
else
|
||||
foreach (var instruction in node.PushServiceProvider(context, bpRef, propertyRef, propertyDeclaringTypeRef))
|
||||
yield return instruction;
|
||||
yield return Instruction.Create(OpCodes.Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IMarkupExtension"), methodName: "ProvideValue", paramCount: 1));
|
||||
yield return Instruction.Create(OpCodes.Stloc, vardefref.VariableDefinition);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IMarkupExtension"),
|
||||
methodName: "ProvideValue",
|
||||
parameterTypes: new[] { ("System.ComponentModel", "System", "IServiceProvider") }));
|
||||
yield return Create(Stloc, vardefref.VariableDefinition);
|
||||
}
|
||||
else if (context.Variables[node].VariableType.ImplementsInterface(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IValueProvider"))))
|
||||
{
|
||||
|
@ -331,16 +332,16 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
|
||||
vardefref.VariableDefinition = new VariableDefinition(module.TypeSystem.Object);
|
||||
yield return Instruction.Create(OpCodes.Ldloc, context.Variables[node]);
|
||||
yield return Create(Ldloc, context.Variables[node]);
|
||||
if (acceptEmptyServiceProvider)
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield return Create(Ldnull);
|
||||
else
|
||||
foreach (var instruction in node.PushServiceProvider(context, bpRef, propertyRef, propertyDeclaringTypeRef))
|
||||
yield return instruction;
|
||||
yield return Instruction.Create(OpCodes.Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IValueProvider"),
|
||||
methodName: "ProvideValue",
|
||||
paramCount: 1));
|
||||
yield return Instruction.Create(OpCodes.Stloc, vardefref.VariableDefinition);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IValueProvider"),
|
||||
methodName: "ProvideValue",
|
||||
parameterTypes: new[] { ("System.ComponentModel", "System", "IServiceProvider") }));
|
||||
yield return Create(Stloc, vardefref.VariableDefinition);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -475,7 +476,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
new ParameterDefinition(tSourceRef)
|
||||
},
|
||||
CustomAttributes = {
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), paramCount: 0))
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null))
|
||||
}
|
||||
};
|
||||
getter.Body.InitLocals = true;
|
||||
|
@ -550,7 +551,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
new ParameterDefinition(tPropertyRef)
|
||||
},
|
||||
CustomAttributes = {
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), paramCount: 0))
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null))
|
||||
}
|
||||
};
|
||||
setter.Body.InitLocals = true;
|
||||
|
@ -652,7 +653,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
new ParameterDefinition(tSourceRef)
|
||||
},
|
||||
CustomAttributes = {
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), paramCount: 0))
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null))
|
||||
}
|
||||
};
|
||||
partGetter.Body.InitLocals = true;
|
||||
|
@ -893,7 +894,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return Create(Ldsfld, bpRef);
|
||||
yield return Create(Ldloc, context.Variables[elementNode]);
|
||||
yield return Create(Callvirt, module.ImportPropertyGetterReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "DynamicResource"), propertyName: "Key"));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "IDynamicResourceHandler"), methodName: "SetDynamicResource", paramCount: 2));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "IDynamicResourceHandler"),
|
||||
methodName: "SetDynamicResource",
|
||||
parameterTypes: new[] {
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "BindableProperty"),
|
||||
("mscorlib", "System", "String"),
|
||||
}));
|
||||
}
|
||||
|
||||
static bool CanSetBinding(FieldReference bpRef, INode valueNode, ILContext context)
|
||||
|
@ -929,7 +935,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (implicitOperator != null)
|
||||
// IL_000f: call !0 class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1<BindingBase>::op_Implicit(class [Xamarin.Forms.Core]Xamarin.Forms.OnPlatform`1<!0>)
|
||||
yield return Create(Call, module.ImportReference(implicitOperator));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"), methodName: "SetBinding", paramCount: 2));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"),
|
||||
methodName: "SetBinding",
|
||||
parameterTypes: new[] {
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "BindableProperty"),
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "BindingBase"),
|
||||
}));
|
||||
}
|
||||
|
||||
static bool CanSetValue(FieldReference bpRef, bool attached, INode node, IXmlLineInfo iXmlLineInfo, ILContext context)
|
||||
|
@ -1012,7 +1023,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (varType.IsValueType)
|
||||
yield return Create(Box, varType);
|
||||
}
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"), methodName: "SetValue", paramCount: 2));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"),
|
||||
methodName: "SetValue",
|
||||
parameterTypes: new[] {
|
||||
("Xamarin.Forms.Core", "Xamarin.Forms", "BindableProperty"),
|
||||
("mscorlib", "System", "Object"),
|
||||
}));
|
||||
}
|
||||
|
||||
static IEnumerable<Instruction> GetValue(VariableDefinition parent, FieldReference bpRef, IXmlLineInfo iXmlLineInfo, ILContext context, out TypeReference propertyType)
|
||||
|
@ -1023,7 +1039,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return new[] {
|
||||
Create(Ldloc, parent),
|
||||
Create(Ldsfld, bpRef),
|
||||
Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"), methodName: "GetValue", paramCount: 1)),
|
||||
Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"),
|
||||
methodName: "GetValue",
|
||||
parameterTypes: new[] { ("Xamarin.Forms.Core", "Xamarin.Forms", "BindableProperty")})),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1192,8 +1210,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var module = context.Body.Method.Module;
|
||||
if (module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "ResourceDictionary"),
|
||||
methodName: "Add",
|
||||
paramCount: 1,
|
||||
predicate: md => TypeRefComparer.Default.Equals(md.Parameters[0].ParameterType, nodeTypeRef)) != null)
|
||||
parameterTypes: new[] { (nodeTypeRef.Scope.Name, nodeTypeRef.Namespace, nodeTypeRef.Name) }) != null)
|
||||
return true;
|
||||
|
||||
throw new XamlParseException("resources in ResourceDictionary require a x:Key attribute", lineInfo);
|
||||
|
@ -1245,15 +1262,19 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (varDef.VariableType.IsValueType)
|
||||
yield return Create(Box, module.ImportReference(varDef.VariableType));
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "ResourceDictionary"),
|
||||
methodName: "Add", paramCount: 2));
|
||||
methodName: "Add",
|
||||
parameterTypes: new[] {
|
||||
("mscorlib", "System", "String"),
|
||||
("mscorlib", "System", "Object"),
|
||||
}));
|
||||
yield break;
|
||||
}
|
||||
|
||||
var nodeTypeRef = context.Variables[node].VariableType;
|
||||
yield return Create(Ldloc, context.Variables[node]);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "ResourceDictionary"),
|
||||
methodName: "Add", paramCount: 1,
|
||||
predicate: md => TypeRefComparer.Default.Equals(md.Parameters[0].ParameterType, nodeTypeRef)));
|
||||
methodName: "Add",
|
||||
parameterTypes: new[] { (nodeTypeRef.Scope.Name, nodeTypeRef.Namespace, nodeTypeRef.Name) }));
|
||||
yield break;
|
||||
}
|
||||
|
||||
|
@ -1300,7 +1321,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
TypeAttributes.NestedPrivate) {
|
||||
BaseType = module.TypeSystem.Object,
|
||||
CustomAttributes = {
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), paramCount: 0)),
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null)),
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1366,8 +1387,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
//SetDataTemplate
|
||||
parentIl.Emit(Ldftn, loadTemplate);
|
||||
parentIl.Emit(Newobj, module.ImportCtorReference(("mscorlib", "System", "Func`1"),
|
||||
paramCount: 2,
|
||||
classArguments: new[] { ("mscorlib", "System", "Object") }));
|
||||
classArguments: new[] { ("mscorlib", "System", "Object") },
|
||||
paramCount: 2));
|
||||
|
||||
parentContext.IL.Emit(OpCodes.Callvirt, module.ImportPropertySetterReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "IDataTemplate"), propertyName: "LoadTemplate"));
|
||||
|
||||
|
|
|
@ -27,8 +27,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
MethodAttributes.SpecialName |
|
||||
MethodAttributes.RTSpecialName;
|
||||
|
||||
var parentctor = module.ImportCtorReference(parentType, paramCount: 0, predicate: md => (!md.IsPrivate && !md.IsStatic))
|
||||
?? module.ImportCtorReference(("mscorlib", "System", "Object"), paramCount: 0);
|
||||
var parentctor = module.ImportCtorReference(parentType, paramCount: 0) ?? module.ImportCtorReference(("mscorlib", "System", "Object"), parameterTypes: null);
|
||||
|
||||
var ctor = new MethodDefinition(".ctor", methodAttributes, voidType)
|
||||
{
|
||||
|
|
|
@ -25,18 +25,26 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return y == null;
|
||||
if (y == null)
|
||||
return x == null;
|
||||
if (x.FullName != y.FullName)
|
||||
|
||||
//strip the leading `&` as byref typered fullnames have a `&`
|
||||
var xname = x.FullName.EndsWith("&", StringComparison.InvariantCulture) ? x.FullName.Substring(0, x.FullName.Length - 1) : x.FullName;
|
||||
var yname = y.FullName.EndsWith("&", StringComparison.InvariantCulture) ? y.FullName.Substring(0, y.FullName.Length - 1) : y.FullName;
|
||||
if (xname != yname)
|
||||
return false;
|
||||
var xasm = GetAssembly(x);
|
||||
var yasm = GetAssembly(y);
|
||||
|
||||
//standard types comes from either mscorlib. System.Runtime or netstandard. Assume they are equivalent
|
||||
if ( (xasm.StartsWith("System.Runtime", StringComparison.Ordinal)
|
||||
if (( xasm.StartsWith("System.Runtime", StringComparison.Ordinal)
|
||||
|| xasm.StartsWith("System", StringComparison.Ordinal)
|
||||
|| xasm.StartsWith("mscorlib", StringComparison.Ordinal)
|
||||
|| xasm.StartsWith("netstandard", StringComparison.Ordinal))
|
||||
&& (yasm.StartsWith("System.Runtime", StringComparison.Ordinal)
|
||||
|| xasm.StartsWith("netstandard", StringComparison.Ordinal)
|
||||
|| xasm.StartsWith("System.Xml", StringComparison.Ordinal))
|
||||
&& ( yasm.StartsWith("System.Runtime", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("System", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("mscorlib", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("netstandard", StringComparison.Ordinal)))
|
||||
|| yasm.StartsWith("netstandard", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("System.Xml", StringComparison.Ordinal)))
|
||||
return true;
|
||||
return xasm == yasm;
|
||||
}
|
||||
|
@ -215,7 +223,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
public static CustomAttribute GetCustomAttribute(this TypeReference typeRef, ModuleDefinition module, (string assemblyName, string clrNamespace, string typeName) attributeType)
|
||||
{
|
||||
return typeRef.GetCustomAttribute(module.ImportReference(module.GetTypeDefinition(attributeType)));
|
||||
return typeRef.GetCustomAttribute(module.ImportReference(attributeType));
|
||||
}
|
||||
|
||||
[Obsolete]
|
||||
|
|
|
@ -272,16 +272,16 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
//First using the ResourceLoader
|
||||
var nop = Instruction.Create(Nop);
|
||||
var getResourceProvider = module.ImportPropertyGetterReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "ResourceLoader"), "ResourceProvider");
|
||||
var getResourceProvider = module.ImportPropertyGetterReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "ResourceLoader"), "ResourceProvider", isStatic: true);
|
||||
il.Emit(Call, getResourceProvider);
|
||||
il.Emit(Brfalse, nop);
|
||||
il.Emit(Call, getResourceProvider);
|
||||
|
||||
il.Emit(Ldtoken, module.ImportReference(initComp.DeclaringType));
|
||||
il.Emit(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", paramCount: 1, predicate: md => md.IsStatic));
|
||||
il.Emit(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", paramCount: 1, predicate: md => md.IsStatic));
|
||||
il.Emit(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
il.Emit(Call, module.ImportMethodReference(("mscorlib", "System.Reflection", "IntrospectionExtensions"), methodName: "GetTypeInfo", parameterTypes: new[] { ("mscorlib", "System", "Type") }, isStatic: true));
|
||||
il.Emit(Callvirt, module.ImportPropertyGetterReference(("mscorlib", "System.Reflection", "TypeInfo"), propertyName: "Assembly", flatten: true));
|
||||
il.Emit(Callvirt, module.ImportMethodReference(("mscorlib", "System.Reflection", "Assembly"), methodName: "GetName", paramCount: 0)); //assemblyName
|
||||
il.Emit(Callvirt, module.ImportMethodReference(("mscorlib", "System.Reflection", "Assembly"), methodName: "GetName", parameterTypes: null)); //assemblyName
|
||||
|
||||
il.Emit(Ldstr, resourcePath); //resourcePath
|
||||
il.Emit(Callvirt, module.ImportMethodReference(("mscorlib", "System", "Func`3"),
|
||||
|
@ -297,12 +297,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
//Or using the deprecated XamlLoader
|
||||
nop = Instruction.Create(Nop);
|
||||
|
||||
var getXamlFileProvider = module.ImportPropertyGetterReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlLoader"), propertyName: "XamlFileProvider");
|
||||
var getXamlFileProvider = module.ImportPropertyGetterReference(("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml.Internals", "XamlLoader"), propertyName: "XamlFileProvider", isStatic: true);
|
||||
il.Emit(Call, getXamlFileProvider);
|
||||
il.Emit(Brfalse, nop);
|
||||
il.Emit(Call, getXamlFileProvider);
|
||||
il.Emit(Ldarg_0);
|
||||
il.Emit(Call, module.ImportMethodReference(("mscorlib", "System", "Object"), methodName: "GetType", paramCount: 0));
|
||||
il.Emit(Call, module.ImportMethodReference(("mscorlib", "System", "Object"), methodName: "GetType", parameterTypes: null));
|
||||
il.Emit(Callvirt, module.ImportMethodReference(("mscorlib", "System", "Func`2"),
|
||||
methodName: "Invoke",
|
||||
paramCount: 1,
|
||||
|
|
Загрузка…
Ссылка в новой задаче