Merge branch '5.0.0' into main
This commit is contained in:
Коммит
94255cdf9a
|
@ -8,7 +8,7 @@ root = true
|
|||
# A newline ending every file
|
||||
# Use 4 spaces as indentation
|
||||
[*]
|
||||
insert_final_newline = false
|
||||
# insert_final_newline = false
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: InternalsVisibleTo ("Xamarin.Forms.Core")]
|
||||
[assembly: ComVisible (false)]
|
||||
[assembly: InternalsVisibleTo("Xamarin.Forms.Core")]
|
||||
[assembly: ComVisible(false)]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
[assembly: InternalsVisibleTo ("Xamarin.Forms.Core")]
|
||||
[assembly: ComVisible (false)]
|
||||
[assembly: InternalsVisibleTo("Xamarin.Forms.Core")]
|
||||
[assembly: ComVisible(false)]
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid ("d3f9fea6-cce8-4c30-b0d2-197b40c50757")]
|
||||
[assembly: Guid("d3f9fea6-cce8-4c30-b0d2-197b40c50757")]
|
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms.Platform
|
|||
{
|
||||
internal static class Loader
|
||||
{
|
||||
internal static void Load ()
|
||||
internal static void Load()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -32,23 +32,23 @@ namespace Xamarin.Forms.Platform
|
|||
[RenderWith(typeof(EntryRenderer))]
|
||||
internal class _EntryRenderer { }
|
||||
|
||||
[RenderWith (typeof (EditorRenderer))]
|
||||
[RenderWith(typeof(EditorRenderer))]
|
||||
internal class _EditorRenderer { }
|
||||
#if __ANDROID__
|
||||
[RenderWith(typeof(Xamarin.Forms.Platform.Android.LabelRenderer))]
|
||||
#else
|
||||
[RenderWith (typeof (LabelRenderer))]
|
||||
[RenderWith(typeof(LabelRenderer))]
|
||||
#endif
|
||||
internal class _LabelRenderer { }
|
||||
|
||||
#if __ANDROID__
|
||||
[RenderWith(typeof(Xamarin.Forms.Platform.Android.ImageRenderer))]
|
||||
#else
|
||||
[RenderWith (typeof (ImageRenderer))]
|
||||
[RenderWith(typeof(ImageRenderer))]
|
||||
#endif
|
||||
internal class _ImageRenderer { }
|
||||
|
||||
[RenderWith (typeof (ButtonRenderer))]
|
||||
[RenderWith(typeof(ButtonRenderer))]
|
||||
internal class _ButtonRenderer { }
|
||||
|
||||
[RenderWith(typeof(ImageButtonRenderer))]
|
||||
|
@ -59,22 +59,22 @@ namespace Xamarin.Forms.Platform
|
|||
internal class _RadioButtonRenderer { }
|
||||
#endif
|
||||
|
||||
[RenderWith (typeof (TableViewRenderer))]
|
||||
[RenderWith(typeof(TableViewRenderer))]
|
||||
internal class _TableViewRenderer { }
|
||||
|
||||
[RenderWith (typeof (ListViewRenderer))]
|
||||
[RenderWith(typeof(ListViewRenderer))]
|
||||
internal class _ListViewRenderer { }
|
||||
#if !TIZEN4_0
|
||||
[RenderWith (typeof (CollectionViewRenderer))]
|
||||
[RenderWith(typeof(CollectionViewRenderer))]
|
||||
#else
|
||||
[RenderWith (typeof (StructuredItemsViewRenderer))]
|
||||
#endif
|
||||
internal class _CollectionViewRenderer { }
|
||||
|
||||
[RenderWith (typeof (CarouselViewRenderer))]
|
||||
[RenderWith(typeof(CarouselViewRenderer))]
|
||||
internal class _CarouselViewRenderer { }
|
||||
|
||||
[RenderWith (typeof (SliderRenderer))]
|
||||
[RenderWith(typeof(SliderRenderer))]
|
||||
internal class _SliderRenderer { }
|
||||
|
||||
#if __IOS__
|
||||
|
@ -85,34 +85,34 @@ namespace Xamarin.Forms.Platform
|
|||
internal class _WebViewRenderer { }
|
||||
#endif
|
||||
|
||||
[RenderWith (typeof (SearchBarRenderer))]
|
||||
[RenderWith(typeof(SearchBarRenderer))]
|
||||
internal class _SearchBarRenderer { }
|
||||
|
||||
[RenderWith (typeof (SwitchRenderer))]
|
||||
[RenderWith(typeof(SwitchRenderer))]
|
||||
internal class _SwitchRenderer { }
|
||||
|
||||
[RenderWith (typeof (DatePickerRenderer))]
|
||||
[RenderWith(typeof(DatePickerRenderer))]
|
||||
internal class _DatePickerRenderer { }
|
||||
|
||||
[RenderWith (typeof (TimePickerRenderer))]
|
||||
[RenderWith(typeof(TimePickerRenderer))]
|
||||
internal class _TimePickerRenderer { }
|
||||
|
||||
[RenderWith (typeof (PickerRenderer))]
|
||||
[RenderWith(typeof(PickerRenderer))]
|
||||
internal class _PickerRenderer { }
|
||||
|
||||
[RenderWith (typeof (StepperRenderer))]
|
||||
[RenderWith(typeof(StepperRenderer))]
|
||||
internal class _StepperRenderer { }
|
||||
|
||||
[RenderWith (typeof (ProgressBarRenderer))]
|
||||
[RenderWith(typeof(ProgressBarRenderer))]
|
||||
internal class _ProgressBarRenderer { }
|
||||
|
||||
[RenderWith (typeof (ScrollViewRenderer))]
|
||||
[RenderWith(typeof(ScrollViewRenderer))]
|
||||
internal class _ScrollViewRenderer { }
|
||||
|
||||
[RenderWith (typeof (ActivityIndicatorRenderer))]
|
||||
[RenderWith(typeof(ActivityIndicatorRenderer))]
|
||||
internal class _ActivityIndicatorRenderer { }
|
||||
|
||||
[RenderWith (typeof (FrameRenderer))]
|
||||
[RenderWith(typeof(FrameRenderer))]
|
||||
internal class _FrameRenderer { }
|
||||
|
||||
#if __ANDROID__
|
||||
|
@ -133,42 +133,38 @@ namespace Xamarin.Forms.Platform
|
|||
#endif
|
||||
|
||||
#if !WINDOWS_PHONE && !WINDOWS_PHONE_APP && !TIZEN4_0
|
||||
[RenderWith (typeof (OpenGLViewRenderer))]
|
||||
[RenderWith(typeof(OpenGLViewRenderer))]
|
||||
#else
|
||||
[RenderWith (null)]
|
||||
#endif
|
||||
internal class _OpenGLViewRenderer { }
|
||||
|
||||
#if !WINDOWS_PHONE && !WINDOWS_PHONE_APP && !TIZEN4_0
|
||||
[RenderWith (typeof (TabbedRenderer))]
|
||||
[RenderWith(typeof(TabbedRenderer))]
|
||||
#else
|
||||
[RenderWith (typeof (TabbedPageRenderer))]
|
||||
#endif
|
||||
internal class _TabbedPageRenderer { }
|
||||
|
||||
#if !WINDOWS_PHONE && !WINDOWS_PHONE_APP && !TIZEN4_0
|
||||
[RenderWith (typeof (NavigationRenderer))]
|
||||
[RenderWith(typeof(NavigationRenderer))]
|
||||
#else
|
||||
[RenderWith (typeof (NavigationPageRenderer))]
|
||||
#endif
|
||||
internal class _NavigationPageRenderer { }
|
||||
|
||||
[RenderWith (typeof (CarouselPageRenderer))]
|
||||
[RenderWith(typeof(CarouselPageRenderer))]
|
||||
internal class _CarouselPageRenderer { }
|
||||
|
||||
[RenderWith (typeof (PageRenderer))]
|
||||
[RenderWith(typeof(PageRenderer))]
|
||||
internal class _PageRenderer { }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if !__IOS__ && !TIZEN4_0
|
||||
#if !__IOS__
|
||||
[RenderWith(typeof(FlyoutPageRenderer))]
|
||||
#elif TIZEN4_0
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
[RenderWith (typeof(MasterDetailPageRenderer))]
|
||||
#pragma warning restore CS0618 // Type or member is obsolete
|
||||
#else
|
||||
[RenderWith (typeof (PhoneFlyoutPageRenderer))]
|
||||
#endif
|
||||
|
@ -196,7 +192,7 @@ namespace Xamarin.Forms.Platform
|
|||
#if !TIZEN4_0
|
||||
[RenderWith(typeof(PathRenderer))]
|
||||
internal class _PathRenderer { }
|
||||
|
||||
|
||||
[RenderWith(typeof(EllipseRenderer))]
|
||||
internal class _EllipseRenderer { }
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (staticGetter != null && staticGetter.ReturnType.ResolveGenericParameters(bpRef.DeclaringType).ResolveCached().HasCustomAttributes)
|
||||
attributes.AddRange(staticGetter.ReturnType.ResolveGenericParameters(bpRef.DeclaringType).ResolveCached().CustomAttributes);
|
||||
|
||||
return attributes.FirstOrDefault(cad => TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName))?.ConstructorArguments [0].Value as TypeReference;
|
||||
return attributes.FirstOrDefault(cad => TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName))?.ConstructorArguments[0].Value as TypeReference;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using System.Xml;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
{
|
||||
|
@ -20,7 +20,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
Code = code;
|
||||
XmlInfo = xmlInfo;
|
||||
MessageArgs = args?.Select(a=>a?.ToString()).ToArray();
|
||||
MessageArgs = args?.Select(a => a?.ToString()).ToArray();
|
||||
}
|
||||
|
||||
protected BuildException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
|
||||
|
@ -41,51 +41,51 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
class BuildExceptionCode
|
||||
{
|
||||
//Assemblies, Types, Members
|
||||
public static BuildExceptionCode TypeResolution = new BuildExceptionCode("XFC0000", nameof(TypeResolution), "");
|
||||
public static BuildExceptionCode PropertyResolution = new BuildExceptionCode("XFC0001", nameof(PropertyResolution), "");
|
||||
public static BuildExceptionCode MissingEventHandler = new BuildExceptionCode("XFC0002", nameof(MissingEventHandler), "");
|
||||
public static BuildExceptionCode PropertyMissing = new BuildExceptionCode("XFC0003", nameof(PropertyMissing), "");
|
||||
public static BuildExceptionCode TypeResolution = new BuildExceptionCode("XFC0000", nameof(TypeResolution), "");
|
||||
public static BuildExceptionCode PropertyResolution = new BuildExceptionCode("XFC0001", nameof(PropertyResolution), "");
|
||||
public static BuildExceptionCode MissingEventHandler = new BuildExceptionCode("XFC0002", nameof(MissingEventHandler), "");
|
||||
public static BuildExceptionCode PropertyMissing = new BuildExceptionCode("XFC0003", nameof(PropertyMissing), "");
|
||||
public static BuildExceptionCode ConstructorDefaultMissing = new BuildExceptionCode("XFC0004", nameof(ConstructorDefaultMissing), "");
|
||||
public static BuildExceptionCode ConstructorXArgsMissing = new BuildExceptionCode("XFC0005", nameof(ConstructorXArgsMissing), "");
|
||||
public static BuildExceptionCode MethodStaticMissing = new BuildExceptionCode("XFC0006", nameof(MethodStaticMissing), "");
|
||||
public static BuildExceptionCode EnumValueMissing = new BuildExceptionCode("XFC0007", nameof(EnumValueMissing), "");
|
||||
public static BuildExceptionCode AdderMissing = new BuildExceptionCode("XFC0008", nameof(AdderMissing), "");
|
||||
public static BuildExceptionCode MemberResolution = new BuildExceptionCode("XFC0009", nameof(MemberResolution), "");
|
||||
public static BuildExceptionCode MethodStaticMissing = new BuildExceptionCode("XFC0006", nameof(MethodStaticMissing), "");
|
||||
public static BuildExceptionCode EnumValueMissing = new BuildExceptionCode("XFC0007", nameof(EnumValueMissing), "");
|
||||
public static BuildExceptionCode AdderMissing = new BuildExceptionCode("XFC0008", nameof(AdderMissing), "");
|
||||
public static BuildExceptionCode MemberResolution = new BuildExceptionCode("XFC0009", nameof(MemberResolution), "");
|
||||
|
||||
|
||||
|
||||
//BP,BO
|
||||
public static BuildExceptionCode BPName = new BuildExceptionCode("XFC0020", nameof(BPName), "");
|
||||
public static BuildExceptionCode BPMissingGetter = new BuildExceptionCode("XFC0021", nameof(BPMissingGetter), "");
|
||||
public static BuildExceptionCode BPName = new BuildExceptionCode("XFC0020", nameof(BPName), "");
|
||||
public static BuildExceptionCode BPMissingGetter = new BuildExceptionCode("XFC0021", nameof(BPMissingGetter), "");
|
||||
|
||||
//Bindings, conversions
|
||||
public static BuildExceptionCode Conversion = new BuildExceptionCode("XFC0040", nameof(Conversion), "");
|
||||
public static BuildExceptionCode Conversion = new BuildExceptionCode("XFC0040", nameof(Conversion), "");
|
||||
public static BuildExceptionCode BindingIndexerNotClosed = new BuildExceptionCode("XFC0041", nameof(BindingIndexerNotClosed), "");
|
||||
public static BuildExceptionCode BindingIndexerEmpty = new BuildExceptionCode("XFC0042", nameof(BindingIndexerEmpty), "");
|
||||
public static BuildExceptionCode BindingIndexerEmpty = new BuildExceptionCode("XFC0042", nameof(BindingIndexerEmpty), "");
|
||||
public static BuildExceptionCode BindingIndexerTypeUnsupported = new BuildExceptionCode("XFC0043", nameof(BindingIndexerTypeUnsupported), "");
|
||||
public static BuildExceptionCode BindingIndexerParse = new BuildExceptionCode("XFC0044", nameof(BindingIndexerParse), "");
|
||||
public static BuildExceptionCode BindingIndexerParse = new BuildExceptionCode("XFC0044", nameof(BindingIndexerParse), "");
|
||||
public static BuildExceptionCode BindingPropertyNotFound = new BuildExceptionCode("XFC0045", nameof(BindingPropertyNotFound), "");
|
||||
|
||||
//XAML issues
|
||||
public static BuildExceptionCode MarkupNotClosed = new BuildExceptionCode("XFC0060", nameof(MarkupNotClosed), "");
|
||||
public static BuildExceptionCode MarkupParsingFailed = new BuildExceptionCode("XFC0061", nameof(MarkupParsingFailed), "");
|
||||
public static BuildExceptionCode XmlnsUndeclared = new BuildExceptionCode("XFC0062", nameof(XmlnsUndeclared), "");
|
||||
public static BuildExceptionCode SByteEnums = new BuildExceptionCode("XFC0063", nameof(SByteEnums), "");
|
||||
public static BuildExceptionCode NamescopeDuplicate = new BuildExceptionCode("XFC0064", nameof(NamescopeDuplicate), "");
|
||||
public static BuildExceptionCode MarkupNotClosed = new BuildExceptionCode("XFC0060", nameof(MarkupNotClosed), "");
|
||||
public static BuildExceptionCode MarkupParsingFailed = new BuildExceptionCode("XFC0061", nameof(MarkupParsingFailed), "");
|
||||
public static BuildExceptionCode XmlnsUndeclared = new BuildExceptionCode("XFC0062", nameof(XmlnsUndeclared), "");
|
||||
public static BuildExceptionCode SByteEnums = new BuildExceptionCode("XFC0063", nameof(SByteEnums), "");
|
||||
public static BuildExceptionCode NamescopeDuplicate = new BuildExceptionCode("XFC0064", nameof(NamescopeDuplicate), "");
|
||||
public static BuildExceptionCode ContentPropertyAttributeMissing = new BuildExceptionCode("XFC0065", nameof(ContentPropertyAttributeMissing), "");
|
||||
public static BuildExceptionCode InvalidXaml = new BuildExceptionCode("XFC0066", nameof(InvalidXaml), "");
|
||||
public static BuildExceptionCode InvalidXaml = new BuildExceptionCode("XFC0066", nameof(InvalidXaml), "");
|
||||
|
||||
|
||||
//Extensions
|
||||
public static BuildExceptionCode XStaticSyntax = new BuildExceptionCode("XFC0100", nameof(XStaticSyntax), "");
|
||||
public static BuildExceptionCode XStaticResolution = new BuildExceptionCode("XFC0101", nameof(XStaticResolution), "");
|
||||
public static BuildExceptionCode XDataTypeSyntax = new BuildExceptionCode("XFC0102", nameof(XDataTypeSyntax), "");
|
||||
public static BuildExceptionCode XStaticSyntax = new BuildExceptionCode("XFC0100", nameof(XStaticSyntax), "");
|
||||
public static BuildExceptionCode XStaticResolution = new BuildExceptionCode("XFC0101", nameof(XStaticResolution), "");
|
||||
public static BuildExceptionCode XDataTypeSyntax = new BuildExceptionCode("XFC0102", nameof(XDataTypeSyntax), "");
|
||||
|
||||
//Style, StyleSheets, Resources
|
||||
public static BuildExceptionCode StyleSheetSourceOrContent = new BuildExceptionCode("XFC0120", nameof(StyleSheetSourceOrContent), "");
|
||||
public static BuildExceptionCode StyleSheetNoSourceOrContent = new BuildExceptionCode("XFC0121", nameof(StyleSheetNoSourceOrContent), "");
|
||||
public static BuildExceptionCode StyleSheetStyleNotALiteral = new BuildExceptionCode("XFC0122", nameof(StyleSheetStyleNotALiteral), "");
|
||||
public static BuildExceptionCode StyleSheetSourceNotALiteral = new BuildExceptionCode("XFC0123", nameof(StyleSheetSourceNotALiteral), "");
|
||||
public static BuildExceptionCode ResourceMissing = new BuildExceptionCode("XFC0124", nameof(ResourceMissing), "");
|
||||
public static BuildExceptionCode ResourceMissing = new BuildExceptionCode("XFC0124", nameof(ResourceMissing), "");
|
||||
public static BuildExceptionCode ResourceDictDuplicateKey = new BuildExceptionCode("XFC0125", nameof(ResourceDictDuplicateKey), "");
|
||||
public static BuildExceptionCode ResourceDictMissingKey = new BuildExceptionCode("XFC0126", nameof(ResourceDictMissingKey), "");
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
if (IsNullOrEmpty(value)) {
|
||||
if (IsNullOrEmpty(value))
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Ldnull);
|
||||
yield break;
|
||||
}
|
||||
|
@ -90,8 +91,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
throw new XamlParseException($"Expected {nameof(VisualStateGroup)} but found {parent.Parent}", lineInfo);
|
||||
|
||||
//3. if the VSG is in a VSGL, skip that as it could be implicit
|
||||
if ( target.Parent is ListNode
|
||||
|| ( (target.Parent as IElementNode)?.XmlType.NamespaceUri == XamlParser.XFUri
|
||||
if (target.Parent is ListNode
|
||||
|| ((target.Parent as IElementNode)?.XmlType.NamespaceUri == XamlParser.XFUri
|
||||
&& (target.Parent as IElementNode)?.XmlType.Name == nameof(VisualStateGroupList)))
|
||||
target = target.Parent.Parent as IElementNode;
|
||||
else
|
||||
|
@ -108,7 +109,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) {
|
||||
if (bpRef != null)
|
||||
{
|
||||
bpRef = module.ImportReference(bpRef.ResolveGenericParameters(declaringTypeReference));
|
||||
bpRef.FieldType = module.ImportReference(bpRef.FieldType);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using static System.String;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using static System.String;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
|
|
@ -2,12 +2,10 @@ using System;
|
|||
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 Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
@ -27,22 +25,25 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
if (xywh.Length != 2 && xywh.Length != 4)
|
||||
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Rectangle));
|
||||
|
||||
hasX = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh [0], NumberStyles.Number, CultureInfo.InvariantCulture, out x);
|
||||
hasY = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh [1], NumberStyles.Number, CultureInfo.InvariantCulture, out y);
|
||||
hasW = xywh.Length == 4 && double.TryParse(xywh [2], NumberStyles.Number, CultureInfo.InvariantCulture, out w);
|
||||
hasH = xywh.Length == 4 && double.TryParse(xywh [3], NumberStyles.Number, CultureInfo.InvariantCulture, out h);
|
||||
hasX = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x);
|
||||
hasY = (xywh.Length == 2 || xywh.Length == 4) && double.TryParse(xywh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y);
|
||||
hasW = xywh.Length == 4 && double.TryParse(xywh[2], NumberStyles.Number, CultureInfo.InvariantCulture, out w);
|
||||
hasH = xywh.Length == 4 && double.TryParse(xywh[3], NumberStyles.Number, CultureInfo.InvariantCulture, out h);
|
||||
|
||||
if (!hasW && xywh.Length == 4 && string.Compare("AutoSize", xywh [2].Trim(), StringComparison.OrdinalIgnoreCase) == 0) {
|
||||
if (!hasW && xywh.Length == 4 && string.Compare("AutoSize", xywh[2].Trim(), StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
hasW = true;
|
||||
w = AbsoluteLayout.AutoSize;
|
||||
}
|
||||
|
||||
if (!hasH && xywh.Length == 4 && string.Compare("AutoSize", xywh [3].Trim(), StringComparison.OrdinalIgnoreCase) == 0) {
|
||||
if (!hasH && xywh.Length == 4 && string.Compare("AutoSize", xywh[3].Trim(), StringComparison.OrdinalIgnoreCase) == 0)
|
||||
{
|
||||
hasH = true;
|
||||
h = AbsoluteLayout.AutoSize;
|
||||
}
|
||||
|
||||
if (hasX && hasY && xywh.Length == 2) {
|
||||
if (hasX && hasY && xywh.Length == 2)
|
||||
{
|
||||
hasW = true;
|
||||
w = AbsoluteLayout.AutoSize;
|
||||
hasH = true;
|
||||
|
@ -57,11 +58,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
|
||||
IEnumerable<Instruction> GenerateIL(double x, double y, double w, double h, ModuleDefinition module)
|
||||
{
|
||||
// IL_0000: ldc.r8 3.1000000000000001
|
||||
// IL_0009: ldc.r8 4.2000000000000002
|
||||
// IL_0012: ldc.r8 5.2999999999999998
|
||||
// IL_001b: ldc.r8 6.4000000000000004
|
||||
// IL_0024: newobj instance void valuetype Test.Rectangle::'.ctor'(float64, float64, float64, float64)
|
||||
// IL_0000: ldc.r8 3.1000000000000001
|
||||
// IL_0009: ldc.r8 4.2000000000000002
|
||||
// IL_0012: ldc.r8 5.2999999999999998
|
||||
// IL_001b: ldc.r8 6.4000000000000004
|
||||
// IL_0024: newobj instance void valuetype Test.Rectangle::'.ctor'(float64, float64, float64, float64)
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, x);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, y);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
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 Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
@ -16,13 +14,15 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
break;
|
||||
|
||||
value = value.Trim();
|
||||
|
||||
if (value.StartsWith("#", StringComparison.Ordinal)) {
|
||||
if (value.StartsWith("#", StringComparison.Ordinal))
|
||||
{
|
||||
var color = Color.FromHex(value);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, color.R);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, color.G);
|
||||
|
@ -37,15 +37,17 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield break;
|
||||
}
|
||||
var parts = value.Split('.');
|
||||
if (parts.Length == 1 || (parts.Length == 2 && parts [0] == "Color")) {
|
||||
var color = parts [parts.Length - 1];
|
||||
if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "Color"))
|
||||
{
|
||||
var color = parts[parts.Length - 1];
|
||||
if (color == "lightgrey")
|
||||
color = "lightgray";
|
||||
var fieldReference = module.ImportFieldReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Color"),
|
||||
color,
|
||||
isStatic: true,
|
||||
caseSensitive: false);
|
||||
if (fieldReference != null) {
|
||||
if (fieldReference != null)
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Ldsfld, fieldReference);
|
||||
yield break;
|
||||
}
|
||||
|
@ -53,7 +55,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
color,
|
||||
isStatic: true,
|
||||
caseSensitive: false);
|
||||
if (propertyGetterReference != null) {
|
||||
if (propertyGetterReference != null)
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Call, propertyGetterReference);
|
||||
yield break;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using Mono.Cecil.Cil;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
|
@ -23,7 +23,7 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
value = parts[parts.Length - 1];
|
||||
|
||||
var assemblyTypeInfo = ("Xamarin.Forms.Core", "Xamarin.Forms", nameof(Easing));
|
||||
|
||||
|
||||
var module = context.Body.Method.Module;
|
||||
var fieldReference = module.ImportFieldReference(assemblyTypeInfo, value, isStatic: true, caseSensitive: false);
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Xaml
|
||||
{
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
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 Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
@ -16,20 +14,23 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
break;
|
||||
|
||||
value = value.Trim();
|
||||
|
||||
var parts = value.Split('.');
|
||||
if (parts.Length == 1 || (parts.Length == 2 && parts [0] == "LayoutOptions")) {
|
||||
var options = parts [parts.Length - 1];
|
||||
if (parts.Length == 1 || (parts.Length == 2 && parts[0] == "LayoutOptions"))
|
||||
{
|
||||
var options = parts[parts.Length - 1];
|
||||
|
||||
var fieldReference = module.ImportFieldReference(("Xamarin.Forms.Core", "Xamarin.Forms", "LayoutOptions"),
|
||||
fieldName: options,
|
||||
isStatic: true);
|
||||
if (fieldReference != null) {
|
||||
if (fieldReference != null)
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Ldsfld, fieldReference);
|
||||
yield break;
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
|
@ -18,7 +15,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
if (value == null) {
|
||||
if (value == null)
|
||||
{
|
||||
yield return Create(Ldnull);
|
||||
yield break;
|
||||
}
|
||||
|
@ -28,7 +26,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
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) {
|
||||
foreach (var part in parts)
|
||||
{
|
||||
yield return Create(Dup);
|
||||
yield return Create(Ldstr, part);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("mscorlib", "System.Collections.Generic", "ICollection`1"),
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -58,15 +55,16 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
foreach (var instruction in node.PushXmlLineInfo(context))
|
||||
yield return instruction; //lineinfo
|
||||
yield return Create(Callvirt, module.ImportMethodReference(resourceDictionaryType,
|
||||
methodName: "SetAndLoadSource",
|
||||
parameterTypes: new[] { ("System", "System", "Uri"), ("mscorlib", "System", "String"), ("mscorlib", "System.Reflection", "Assembly"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") }));
|
||||
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);
|
||||
}
|
||||
|
||||
internal static string GetPathForType(ModuleDefinition module, TypeReference type)
|
||||
{
|
||||
foreach (var ca in type.Module.GetCustomAttributes()) {
|
||||
foreach (var ca in type.Module.GetCustomAttributes())
|
||||
{
|
||||
if (!TypeRefComparer.Default.Equals(ca.AttributeType, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "XamlResourceIdAttribute"))))
|
||||
continue;
|
||||
if (!TypeRefComparer.Default.Equals(ca.ConstructorArguments[2].Value as TypeReference, type))
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
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 Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
@ -21,10 +19,10 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
double x, y, w, h;
|
||||
var xywh = value.Split(',');
|
||||
if (xywh.Length != 4 ||
|
||||
!double.TryParse(xywh [0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) ||
|
||||
!double.TryParse(xywh [1], NumberStyles.Number, CultureInfo.InvariantCulture, out y) ||
|
||||
!double.TryParse(xywh [2], NumberStyles.Number, CultureInfo.InvariantCulture, out w) ||
|
||||
!double.TryParse(xywh [3], NumberStyles.Number, CultureInfo.InvariantCulture, out h))
|
||||
!double.TryParse(xywh[0], NumberStyles.Number, CultureInfo.InvariantCulture, out x) ||
|
||||
!double.TryParse(xywh[1], NumberStyles.Number, CultureInfo.InvariantCulture, out y) ||
|
||||
!double.TryParse(xywh[2], NumberStyles.Number, CultureInfo.InvariantCulture, out w) ||
|
||||
!double.TryParse(xywh[3], NumberStyles.Number, CultureInfo.InvariantCulture, out h))
|
||||
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Rectangle));
|
||||
|
||||
return GenerateIL(x, y, w, h, module);
|
||||
|
@ -32,11 +30,11 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
|
||||
IEnumerable<Instruction> GenerateIL(double x, double y, double w, double h, ModuleDefinition module)
|
||||
{
|
||||
// IL_0000: ldc.r8 3.1000000000000001
|
||||
// IL_0009: ldc.r8 4.2000000000000002
|
||||
// IL_0012: ldc.r8 5.2999999999999998
|
||||
// IL_001b: ldc.r8 6.4000000000000004
|
||||
// IL_0024: newobj instance void valuetype Test.Rectangle::'.ctor'(float64, float64, float64, float64)
|
||||
// IL_0000: ldc.r8 3.1000000000000001
|
||||
// IL_0009: ldc.r8 4.2000000000000002
|
||||
// IL_0012: ldc.r8 5.2999999999999998
|
||||
// IL_001b: ldc.r8 6.4000000000000004
|
||||
// IL_0024: newobj instance void valuetype Test.Rectangle::'.ctor'(float64, float64, float64, float64)
|
||||
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, x);
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, y);
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
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 Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
@ -16,26 +14,28 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
if (!string.IsNullOrEmpty(value)) {
|
||||
if (!string.IsNullOrEmpty(value))
|
||||
{
|
||||
double l, t, r, b;
|
||||
var thickness = value.Split(',');
|
||||
switch (thickness.Length) {
|
||||
case 1:
|
||||
if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l))
|
||||
return GenerateIL(module, l);
|
||||
break;
|
||||
case 2:
|
||||
if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&
|
||||
double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t))
|
||||
return GenerateIL(module, l, t);
|
||||
break;
|
||||
case 4:
|
||||
if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&
|
||||
double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t) &&
|
||||
double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out r) &&
|
||||
double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out b))
|
||||
return GenerateIL(module, l, t, r, b);
|
||||
break;
|
||||
switch (thickness.Length)
|
||||
{
|
||||
case 1:
|
||||
if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l))
|
||||
return GenerateIL(module, l);
|
||||
break;
|
||||
case 2:
|
||||
if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&
|
||||
double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t))
|
||||
return GenerateIL(module, l, t);
|
||||
break;
|
||||
case 4:
|
||||
if (double.TryParse(thickness[0], NumberStyles.Number, CultureInfo.InvariantCulture, out l) &&
|
||||
double.TryParse(thickness[1], NumberStyles.Number, CultureInfo.InvariantCulture, out t) &&
|
||||
double.TryParse(thickness[2], NumberStyles.Number, CultureInfo.InvariantCulture, out r) &&
|
||||
double.TryParse(thickness[3], NumberStyles.Number, CultureInfo.InvariantCulture, out b))
|
||||
return GenerateIL(module, l, t, r, b);
|
||||
break;
|
||||
}
|
||||
}
|
||||
throw new BuildException(BuildExceptionCode.Conversion, node, null, value, typeof(Thickness));
|
||||
|
@ -48,5 +48,5 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("Xamarin.Forms.Core", "Xamarin.Forms", "Thickness"), parameterTypes: args.Select(a => ("mscorlib", "System", "Double")).ToArray()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,16 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
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;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
class UriTypeConverter : ICompiledTypeConverter
|
||||
|
@ -19,7 +16,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
if (string.IsNullOrWhiteSpace(value)) {
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
yield return Create(Ldnull);
|
||||
yield break;
|
||||
}
|
||||
|
|
|
@ -24,16 +24,20 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return Instruction.Create(OpCodes.Ldc_I4, n);
|
||||
yield return Instruction.Create(OpCodes.Newarr, typeTypeRef);
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
for (var i = 0; i < n; i++)
|
||||
{
|
||||
var vardef = context.Variables[items[i] as IElementNode];
|
||||
if (typeTypeRef.IsValueType) {
|
||||
if (typeTypeRef.IsValueType)
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Dup);
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, i);
|
||||
yield return Instruction.Create(OpCodes.Ldelema, typeTypeRef);
|
||||
foreach (var instruction in vardef.LoadAs(typeTypeRef, module))
|
||||
yield return instruction;
|
||||
yield return Instruction.Create(OpCodes.Stobj, typeTypeRef);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return Instruction.Create(OpCodes.Dup);
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, i);
|
||||
foreach (var instruction in vardef.LoadAs(typeTypeRef, module))
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
using static Mono.Cecil.Cil.Instruction;
|
||||
using static Mono.Cecil.Cil.OpCodes;
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Mono.Cecil;
|
||||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
|
|
|
@ -35,7 +35,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
throw new BuildException(BuildExceptionCode.XStaticResolution, node as IXmlLineInfo, null, membername, typename);
|
||||
|
||||
var fieldDef = fieldRef?.Resolve();
|
||||
if (fieldRef != null) {
|
||||
if (fieldRef != null)
|
||||
{
|
||||
memberRef = fieldRef.FieldType;
|
||||
if (!fieldDef.HasConstant)
|
||||
return new[] { Instruction.Create(OpCodes.Ldsfld, fieldRef) };
|
||||
|
@ -63,7 +64,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return new[] { Instruction.Create(OpCodes.Ldc_I8, (ulong)fieldDef.Constant) };
|
||||
|
||||
//enum values
|
||||
if (memberRef.ResolveCached().IsEnum) {
|
||||
if (memberRef.ResolveCached().IsEnum)
|
||||
{
|
||||
if (fieldDef.Constant is long)
|
||||
return new[] { Instruction.Create(OpCodes.Ldc_I8, (long)fieldDef.Constant) };
|
||||
if (fieldDef.Constant is ulong)
|
||||
|
@ -85,7 +87,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
FieldReference fRef = typeRef.GetField(fd => fd.Name == fieldName
|
||||
&& fd.IsStatic
|
||||
&& IsPublicOrVisibleInternal(fd, module), out TypeReference declaringTypeReference);
|
||||
if (fRef != null) {
|
||||
if (fRef != null)
|
||||
{
|
||||
fRef = module.ImportReference(fRef.ResolveGenericParameters(declaringTypeReference));
|
||||
fRef.FieldType = module.ImportReference(fRef.FieldType);
|
||||
}
|
||||
|
@ -96,10 +99,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
if (fd.IsPublic)
|
||||
return true;
|
||||
if (fd.IsAssembly) {
|
||||
if (fd.IsAssembly)
|
||||
{
|
||||
if (fd.Module == module)
|
||||
return true;
|
||||
if (fd.Module.GetCustomAttributes().Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute"
|
||||
if (fd.Module.GetCustomAttributes().Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute"
|
||||
&& ca.HasConstructorArguments
|
||||
&& (ca.ConstructorArguments[0].Value as string) != null
|
||||
&& (ca.ConstructorArguments[0].Value as string).StartsWith(module.Assembly.Name.Name, System.StringComparison.InvariantCulture)))
|
||||
|
@ -120,7 +124,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
if (md.IsPublic)
|
||||
return true;
|
||||
if (md.IsAssembly) {
|
||||
if (md.IsAssembly)
|
||||
{
|
||||
if (md.Module == module)
|
||||
return true;
|
||||
if (md.Module.GetCustomAttributes().Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.InternalsVisibleToAttribute"
|
||||
|
|
|
@ -25,7 +25,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (!(typeNameNode is ValueNode valueNode))
|
||||
throw new BuildException(BuildExceptionCode.PropertyMissing, node as IXmlLineInfo, null, "TypeName", typeof(Xamarin.Forms.Xaml.TypeExtension));
|
||||
|
||||
if (!node.Properties.ContainsKey(name)) {
|
||||
if (!node.Properties.ContainsKey(name))
|
||||
{
|
||||
node.Properties[name] = typeNameNode;
|
||||
node.CollectionItems.Clear();
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
using System.Xml;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Build.Tasks;
|
||||
using System.Xml;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Core.XamlC
|
||||
{
|
||||
|
@ -15,7 +13,7 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
{
|
||||
INode valueNode = null;
|
||||
if (!((IElementNode)node).Properties.TryGetValue(new XmlName("", "Value"), out valueNode) &&
|
||||
!((IElementNode)node).Properties.TryGetValue(new XmlName(XamlParser.XFUri, "Value"), out valueNode) &&
|
||||
!((IElementNode)node).Properties.TryGetValue(new XmlName(XamlParser.XFUri, "Value"), out valueNode) &&
|
||||
((IElementNode)node).CollectionItems.Count == 1)
|
||||
valueNode = ((IElementNode)node).CollectionItems[0];
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
if (sourceNode != null && !(sourceNode is ValueNode))
|
||||
throw new BuildException(BuildExceptionCode.StyleSheetSourceNotALiteral, node, null);
|
||||
|
||||
if (styleNode != null) {
|
||||
if (styleNode != null)
|
||||
{
|
||||
var style = (styleNode as ValueNode).Value as string;
|
||||
yield return Create(Ldstr, style);
|
||||
yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.StyleSheets", "StyleSheet"),
|
||||
|
@ -47,7 +48,8 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
parameterTypes: new[] { ("mscorlib", "System", "String") },
|
||||
isStatic: true));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
var source = (sourceNode as ValueNode)?.Value as string;
|
||||
INode rootNode = node;
|
||||
while (!(rootNode is ILRootNode))
|
||||
|
@ -73,7 +75,7 @@ namespace Xamarin.Forms.Core.XamlC
|
|||
|
||||
yield return Create(Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.StyleSheets", "StyleSheet"),
|
||||
methodName: "FromResource",
|
||||
parameterTypes: new[] { ("mscorlib", "System", "String"), ("mscorlib", "System.Reflection", "Assembly"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") },
|
||||
parameterTypes: new[] { ("mscorlib", "System", "String"), ("mscorlib", "System.Reflection", "Assembly"), ("System.Xml.ReaderWriter", "System.Xml", "IXmlLineInfo") },
|
||||
isStatic: true));
|
||||
}
|
||||
|
||||
|
|
|
@ -2,11 +2,10 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
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;
|
||||
|
||||
|
@ -52,9 +51,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var typeref = Module.ImportReference(node.XmlType.GetTypeReference(Module, node));
|
||||
TypeDefinition typedef = typeref.ResolveCached();
|
||||
|
||||
if (IsXaml2009LanguagePrimitive(node)) {
|
||||
if (IsXaml2009LanguagePrimitive(node))
|
||||
{
|
||||
var vardef = new VariableDefinition(typeref);
|
||||
Context.Variables [node] = vardef;
|
||||
Context.Variables[node] = vardef;
|
||||
Context.Body.Variables.Add(vardef);
|
||||
|
||||
Context.IL.Append(PushValueFromLanguagePrimitive(typedef, node));
|
||||
|
@ -70,7 +70,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
ICompiledMarkupExtension markupProvider;
|
||||
if (compiledMarkupExtensionName != null &&
|
||||
(compiledMarkupExtensionType = Type.GetType(compiledMarkupExtensionName)) != null &&
|
||||
(markupProvider = Activator.CreateInstance(compiledMarkupExtensionType) as ICompiledMarkupExtension) != null) {
|
||||
(markupProvider = Activator.CreateInstance(compiledMarkupExtensionType) as ICompiledMarkupExtension) != null)
|
||||
{
|
||||
|
||||
var il = markupProvider.ProvideValue(node, Module, Context, out typeref);
|
||||
typeref = Module.ImportReference(typeref);
|
||||
|
@ -97,7 +98,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
MethodDefinition parameterizedCtorInfo = null;
|
||||
MethodDefinition ctorInfo = null;
|
||||
|
||||
if (node.Properties.ContainsKey(XmlName.xArguments) && !node.Properties.ContainsKey(XmlName.xFactoryMethod)) {
|
||||
if (node.Properties.ContainsKey(XmlName.xArguments) && !node.Properties.ContainsKey(XmlName.xFactoryMethod))
|
||||
{
|
||||
factoryCtorInfo = typedef.AllMethods().FirstOrDefault(md => md.methodDef.IsConstructor &&
|
||||
!md.methodDef.IsStatic &&
|
||||
md.methodDef.HasParameters &&
|
||||
|
@ -105,18 +107,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
ctorInfo = factoryCtorInfo ?? throw new BuildException(BuildExceptionCode.ConstructorXArgsMissing, node, null, typedef.FullName);
|
||||
if (!typedef.IsValueType) //for ctor'ing typedefs, we first have to ldloca before the params
|
||||
Context.IL.Append(PushCtorXArguments(factoryCtorInfo.ResolveGenericParameters(typeref, Module), node));
|
||||
} else if (node.Properties.ContainsKey(XmlName.xFactoryMethod)) {
|
||||
var factoryMethod = (string)(node.Properties [XmlName.xFactoryMethod] as ValueNode).Value;
|
||||
}
|
||||
else if (node.Properties.ContainsKey(XmlName.xFactoryMethod))
|
||||
{
|
||||
var factoryMethod = (string)(node.Properties[XmlName.xFactoryMethod] as ValueNode).Value;
|
||||
factoryMethodInfo = typedef.AllMethods().FirstOrDefault(md => !md.methodDef.IsConstructor &&
|
||||
md.methodDef.Name == factoryMethod &&
|
||||
md.methodDef.IsStatic &&
|
||||
md.methodDef.MatchXArguments(node, typeref, Module, Context)).methodDef;
|
||||
if (factoryMethodInfo == null)
|
||||
throw new BuildException(BuildExceptionCode.MethodStaticMissing, node, null, typedef.FullName, factoryMethod, null);
|
||||
|
||||
|
||||
Context.IL.Append(PushCtorXArguments(factoryMethodInfo.ResolveGenericParameters(typeref, Module), node));
|
||||
}
|
||||
if (ctorInfo == null && factoryMethodInfo == null) {
|
||||
if (ctorInfo == null && factoryMethodInfo == null)
|
||||
{
|
||||
parameterizedCtorInfo = typedef.Methods.FirstOrDefault(md => md.IsConstructor &&
|
||||
!md.IsStatic &&
|
||||
md.HasParameters &&
|
||||
|
@ -128,9 +133,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
"Xamarin.Forms.ParameterAttribute")));
|
||||
}
|
||||
string missingCtorParameter = null;
|
||||
if (parameterizedCtorInfo != null && ValidateCtorArguments(parameterizedCtorInfo, node, out missingCtorParameter)) {
|
||||
if (parameterizedCtorInfo != null && ValidateCtorArguments(parameterizedCtorInfo, node, out missingCtorParameter))
|
||||
{
|
||||
ctorInfo = parameterizedCtorInfo;
|
||||
// IL_0000: ldstr "foo"
|
||||
// IL_0000: ldstr "foo"
|
||||
Context.IL.Append(PushCtorArguments(parameterizedCtorInfo.ResolveGenericParameters(typeref, Module), node));
|
||||
}
|
||||
ctorInfo = ctorInfo ?? typedef.Methods.FirstOrDefault(md => md.IsConstructor && !md.HasParameters && !md.IsStatic);
|
||||
|
@ -143,57 +149,70 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
md.IsPublic &&
|
||||
md.IsStatic &&
|
||||
md.IsSpecialName &&
|
||||
md.Name == "op_Implicit" && md.Parameters [0].ParameterType.FullName == "System.String");
|
||||
md.Name == "op_Implicit" && md.Parameters[0].ParameterType.FullName == "System.String");
|
||||
|
||||
if (!typedef.IsValueType && ctorInfo == null && factoryMethodInfo == null)
|
||||
throw new BuildException(BuildExceptionCode.ConstructorDefaultMissing, node, null, typedef.FullName);
|
||||
|
||||
if (ctorinforef != null || factorymethodinforef != null || typedef.IsValueType) {
|
||||
if (ctorinforef != null || factorymethodinforef != null || typedef.IsValueType)
|
||||
{
|
||||
VariableDefinition vardef = new VariableDefinition(typeref);
|
||||
Context.Variables [node] = vardef;
|
||||
Context.Variables[node] = vardef;
|
||||
Context.Body.Variables.Add(vardef);
|
||||
|
||||
ValueNode vnode = null;
|
||||
if (node.CollectionItems.Count == 1 && (vnode = node.CollectionItems.First() as ValueNode) != null &&
|
||||
vardef.VariableType.IsValueType) {
|
||||
vardef.VariableType.IsValueType)
|
||||
{
|
||||
//<Color>Purple</Color>
|
||||
Context.IL.Append(vnode.PushConvertedValue(Context, typeref, new ICustomAttributeProvider [] { typedef },
|
||||
Context.IL.Append(vnode.PushConvertedValue(Context, typeref, new ICustomAttributeProvider[] { typedef },
|
||||
node.PushServiceProvider(Context), false, true));
|
||||
Context.IL.Emit(OpCodes.Stloc, vardef);
|
||||
} else if (node.CollectionItems.Count == 1 && (vnode = node.CollectionItems.First() as ValueNode) != null &&
|
||||
implicitOperatorref != null) {
|
||||
}
|
||||
else if (node.CollectionItems.Count == 1 && (vnode = node.CollectionItems.First() as ValueNode) != null &&
|
||||
implicitOperatorref != null)
|
||||
{
|
||||
//<FileImageSource>path.png</FileImageSource>
|
||||
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) {
|
||||
}
|
||||
else if (factorymethodinforef != null)
|
||||
{
|
||||
Context.IL.Emit(OpCodes.Call, Module.ImportReference(factorymethodinforef));
|
||||
Context.IL.Emit(OpCodes.Stloc, vardef);
|
||||
} else if (!typedef.IsValueType) {
|
||||
}
|
||||
else if (!typedef.IsValueType)
|
||||
{
|
||||
var ctor = Module.ImportReference(ctorinforef);
|
||||
// IL_0001: newobj instance void class [Xamarin.Forms.Core]Xamarin.Forms.Button::'.ctor'()
|
||||
// IL_0006: stloc.0
|
||||
// IL_0001: newobj instance void class [Xamarin.Forms.Core]Xamarin.Forms.Button::'.ctor'()
|
||||
// IL_0006: stloc.0
|
||||
Context.IL.Emit(OpCodes.Newobj, ctor);
|
||||
Context.IL.Emit(OpCodes.Stloc, vardef);
|
||||
} else if (ctorInfo != null && node.Properties.ContainsKey(XmlName.xArguments) &&
|
||||
!node.Properties.ContainsKey(XmlName.xFactoryMethod) && ctorInfo.MatchXArguments(node, typeref, Module, Context)) {
|
||||
// IL_0008: ldloca.s 1
|
||||
// IL_000a: ldc.i4.1
|
||||
// IL_000b: call instance void valuetype Test/Foo::'.ctor'(bool)
|
||||
}
|
||||
else if (ctorInfo != null && node.Properties.ContainsKey(XmlName.xArguments) &&
|
||||
!node.Properties.ContainsKey(XmlName.xFactoryMethod) && ctorInfo.MatchXArguments(node, typeref, Module, Context))
|
||||
{
|
||||
// IL_0008: ldloca.s 1
|
||||
// IL_000a: ldc.i4.1
|
||||
// IL_000b: call instance void valuetype Test/Foo::'.ctor'(bool)
|
||||
|
||||
var ctor = Module.ImportReference(ctorinforef);
|
||||
Context.IL.Emit(OpCodes.Ldloca, vardef);
|
||||
Context.IL.Append(PushCtorXArguments(ctor, node));
|
||||
Context.IL.Emit(OpCodes.Call, ctor);
|
||||
} else {
|
||||
// IL_0000: ldloca.s 0
|
||||
// IL_0002: initobj Test/Foo
|
||||
}
|
||||
else
|
||||
{
|
||||
// IL_0000: ldloca.s 0
|
||||
// IL_0002: initobj Test/Foo
|
||||
Context.IL.Emit(OpCodes.Ldloca, vardef);
|
||||
Context.IL.Emit(OpCodes.Initobj, Module.ImportReference(typedef));
|
||||
}
|
||||
|
||||
if (typeref.FullName == "Xamarin.Forms.Xaml.ArrayExtension") {
|
||||
if (typeref.FullName == "Xamarin.Forms.Xaml.ArrayExtension")
|
||||
{
|
||||
var visitor = new SetPropertiesVisitor(Context);
|
||||
foreach (var cnode in node.Properties.Values.ToList())
|
||||
cnode.Accept(visitor, node);
|
||||
|
@ -226,8 +245,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
public void Visit(RootNode node, INode parentNode)
|
||||
{
|
||||
// IL_0013: ldarg.0
|
||||
// IL_0014: stloc.3
|
||||
// IL_0013: ldarg.0
|
||||
// IL_0014: stloc.3
|
||||
|
||||
var ilnode = (ILRootNode)node;
|
||||
var typeref = ilnode.TypeReference;
|
||||
|
@ -256,7 +275,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
parameter.CustomAttributes.First(ca => ca.AttributeType.FullName == "Xamarin.Forms.ParameterAttribute")
|
||||
.ConstructorArguments.First()
|
||||
.Value as string;
|
||||
if (!enode.Properties.ContainsKey(new XmlName("", propname))) {
|
||||
if (!enode.Properties.ContainsKey(new XmlName("", propname)))
|
||||
{
|
||||
firstMissingProperty = propname;
|
||||
return false;
|
||||
}
|
||||
|
@ -331,8 +351,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static bool IsXaml2009LanguagePrimitive(IElementNode node)
|
||||
{
|
||||
if (node.NamespaceURI == XamlParser.X2009Uri) {
|
||||
var n = node.XmlType.Name.Split(':') [1];
|
||||
if (node.NamespaceURI == XamlParser.X2009Uri)
|
||||
{
|
||||
var n = node.XmlType.Name.Split(':')[1];
|
||||
return n != "Array";
|
||||
}
|
||||
if (node.NamespaceURI != "clr-namespace:System;assembly=mscorlib")
|
||||
|
@ -362,179 +383,189 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var module = Context.Body.Method.Module;
|
||||
var hasValue = node.CollectionItems.Count == 1 && node.CollectionItems[0] is ValueNode &&
|
||||
((ValueNode)node.CollectionItems[0]).Value is string;
|
||||
((ValueNode)node.CollectionItems[0]).Value is string;
|
||||
var valueString = hasValue ? ((ValueNode)node.CollectionItems[0]).Value as string : string.Empty;
|
||||
switch (typedef.FullName) {
|
||||
case "System.SByte":
|
||||
if (hasValue && sbyte.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out sbyte outsbyte))
|
||||
yield return Create(Ldc_I4, (int)outsbyte);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Int16":
|
||||
if (hasValue && short.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out short outshort))
|
||||
yield return Create(Ldc_I4, outshort);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Int32":
|
||||
if (hasValue && int.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out int outint))
|
||||
yield return Create(Ldc_I4, outint);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Int64":
|
||||
if (hasValue && long.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out long outlong))
|
||||
yield return Create(Ldc_I8, outlong);
|
||||
else
|
||||
yield return Create(Ldc_I8, 0L);
|
||||
break;
|
||||
case "System.Byte":
|
||||
if (hasValue && byte.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out byte outbyte))
|
||||
yield return Create(Ldc_I4, (int)outbyte);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.UInt16":
|
||||
if (hasValue && short.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out short outushort))
|
||||
yield return Create(Ldc_I4, outushort);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.UInt32":
|
||||
if (hasValue && int.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out int outuint))
|
||||
yield return Create(Ldc_I4, outuint);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.UInt64":
|
||||
if (hasValue && long.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out long outulong))
|
||||
yield return Create(Ldc_I8, outulong);
|
||||
else
|
||||
yield return Create(Ldc_I8, 0L);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
if (hasValue && bool.TryParse(valueString, out bool outbool))
|
||||
yield return Create(outbool ? Ldc_I4_1 : Ldc_I4_0);
|
||||
else
|
||||
yield return Create(Ldc_I4_0);
|
||||
break;
|
||||
case "System.String":
|
||||
yield return Create(Ldstr, valueString);
|
||||
break;
|
||||
case "System.Object":
|
||||
var ctorinfo =
|
||||
module.TypeSystem.Object.ResolveCached()
|
||||
.Methods.FirstOrDefault(md => md.IsConstructor && !md.HasParameters);
|
||||
var ctor = module.ImportReference(ctorinfo);
|
||||
yield return Create(Newobj, ctor);
|
||||
break;
|
||||
case "System.Char":
|
||||
if (hasValue && char.TryParse(valueString, out char outchar))
|
||||
yield return Create(Ldc_I4, outchar);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Decimal":
|
||||
decimal outdecimal;
|
||||
if (hasValue && decimal.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out outdecimal)) {
|
||||
var vardef = new VariableDefinition(module.ImportReference(("mscorlib", "System", "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"
|
||||
// IL_0008: ldc.i4.s 0x6f
|
||||
// IL_000a: call class [mscorlib]System.Globalization.CultureInfo class [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture()
|
||||
// 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
|
||||
switch (typedef.FullName)
|
||||
{
|
||||
case "System.SByte":
|
||||
if (hasValue && sbyte.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out sbyte outsbyte))
|
||||
yield return Create(Ldc_I4, (int)outsbyte);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Int16":
|
||||
if (hasValue && short.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out short outshort))
|
||||
yield return Create(Ldc_I4, outshort);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Int32":
|
||||
if (hasValue && int.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out int outint))
|
||||
yield return Create(Ldc_I4, outint);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Int64":
|
||||
if (hasValue && long.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out long outlong))
|
||||
yield return Create(Ldc_I8, outlong);
|
||||
else
|
||||
yield return Create(Ldc_I8, 0L);
|
||||
break;
|
||||
case "System.Byte":
|
||||
if (hasValue && byte.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out byte outbyte))
|
||||
yield return Create(Ldc_I4, (int)outbyte);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.UInt16":
|
||||
if (hasValue && short.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out short outushort))
|
||||
yield return Create(Ldc_I4, outushort);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.UInt32":
|
||||
if (hasValue && int.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out int outuint))
|
||||
yield return Create(Ldc_I4, outuint);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.UInt64":
|
||||
if (hasValue && long.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out long outulong))
|
||||
yield return Create(Ldc_I8, outulong);
|
||||
else
|
||||
yield return Create(Ldc_I8, 0L);
|
||||
break;
|
||||
case "System.Boolean":
|
||||
if (hasValue && bool.TryParse(valueString, out bool outbool))
|
||||
yield return Create(outbool ? Ldc_I4_1 : Ldc_I4_0);
|
||||
else
|
||||
yield return Create(Ldc_I4_0);
|
||||
break;
|
||||
case "System.String":
|
||||
yield return Create(Ldstr, valueString);
|
||||
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[] {
|
||||
break;
|
||||
case "System.Object":
|
||||
var ctorinfo =
|
||||
module.TypeSystem.Object.ResolveCached()
|
||||
.Methods.FirstOrDefault(md => md.IsConstructor && !md.HasParameters);
|
||||
var ctor = module.ImportReference(ctorinfo);
|
||||
yield return Create(Newobj, ctor);
|
||||
break;
|
||||
case "System.Char":
|
||||
if (hasValue && char.TryParse(valueString, out char outchar))
|
||||
yield return Create(Ldc_I4, outchar);
|
||||
else
|
||||
yield return Create(Ldc_I4, 0x00);
|
||||
break;
|
||||
case "System.Decimal":
|
||||
decimal outdecimal;
|
||||
if (hasValue && decimal.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out outdecimal))
|
||||
{
|
||||
var vardef = new VariableDefinition(module.ImportReference(("mscorlib", "System", "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"
|
||||
// IL_0008: ldc.i4.s 0x6f
|
||||
// IL_000a: call class [mscorlib]System.Globalization.CultureInfo class [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture()
|
||||
// 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 Create(Ldstr, valueString);
|
||||
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 Create(Ldc_I4_0);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Decimal"), parameterTypes: new[] { ("mscorlib", "System", "Int32") }));
|
||||
}
|
||||
break;
|
||||
case "System.Single":
|
||||
if (hasValue && float.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out float outfloat))
|
||||
yield return Create(Ldc_R4, outfloat);
|
||||
else
|
||||
yield return Create(Ldc_R4, 0f);
|
||||
break;
|
||||
case "System.Double":
|
||||
if (hasValue && double.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out double outdouble))
|
||||
yield return Create(Ldc_R8, outdouble);
|
||||
else
|
||||
yield return Create(Ldc_R8, 0d);
|
||||
break;
|
||||
case "System.TimeSpan":
|
||||
if (hasValue && TimeSpan.TryParse(valueString, CultureInfo.InvariantCulture, out TimeSpan outspan)) {
|
||||
var vardef = new VariableDefinition(module.ImportReference(("mscorlib", "System", "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 Create(Ldstr, valueString);
|
||||
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", "TimeSpan"),
|
||||
methodName: "TryParse",
|
||||
parameterTypes: new[] {
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return Create(Ldc_I4_0);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Decimal"), parameterTypes: new[] { ("mscorlib", "System", "Int32") }));
|
||||
}
|
||||
break;
|
||||
case "System.Single":
|
||||
if (hasValue && float.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out float outfloat))
|
||||
yield return Create(Ldc_R4, outfloat);
|
||||
else
|
||||
yield return Create(Ldc_R4, 0f);
|
||||
break;
|
||||
case "System.Double":
|
||||
if (hasValue && double.TryParse(valueString, NumberStyles.Number, CultureInfo.InvariantCulture, out double outdouble))
|
||||
yield return Create(Ldc_R8, outdouble);
|
||||
else
|
||||
yield return Create(Ldc_R8, 0d);
|
||||
break;
|
||||
case "System.TimeSpan":
|
||||
if (hasValue && TimeSpan.TryParse(valueString, CultureInfo.InvariantCulture, out TimeSpan outspan))
|
||||
{
|
||||
var vardef = new VariableDefinition(module.ImportReference(("mscorlib", "System", "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 Create(Ldstr, valueString);
|
||||
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", "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);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "TimeSpan"), parameterTypes: new[] { ("mscorlib", "System", "Int64") }));
|
||||
}
|
||||
break;
|
||||
case "System.Uri":
|
||||
if (hasValue && Uri.TryCreate(valueString, UriKind.RelativeOrAbsolute, out _)) {
|
||||
var vardef = new VariableDefinition(module.ImportReference(("System", "System", "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 Create(Ldstr, valueString);
|
||||
yield return Create(Ldc_I4, (int)UriKind.RelativeOrAbsolute);
|
||||
yield return Create(Ldloca, vardef);
|
||||
yield return Create(Call, module.ImportMethodReference(("System", "System", "Uri"),
|
||||
methodName: "TryCreate",
|
||||
parameterTypes: new[] {
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return Create(Ldc_I8, 0L);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "TimeSpan"), parameterTypes: new[] { ("mscorlib", "System", "Int64") }));
|
||||
}
|
||||
break;
|
||||
case "System.Uri":
|
||||
if (hasValue && Uri.TryCreate(valueString, UriKind.RelativeOrAbsolute, out _))
|
||||
{
|
||||
var vardef = new VariableDefinition(module.ImportReference(("System", "System", "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 Create(Ldstr, valueString);
|
||||
yield return Create(Ldc_I4, (int)UriKind.RelativeOrAbsolute);
|
||||
yield return Create(Ldloca, vardef);
|
||||
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, parameterTypes: null);
|
||||
if (defaultCtor != null)
|
||||
yield return Create(Newobj, defaultCtor);
|
||||
else {
|
||||
//should never happen. but if it does, this prevents corrupting the IL stack
|
||||
yield return Create(Ldnull);
|
||||
}
|
||||
break;
|
||||
},
|
||||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
}
|
||||
else
|
||||
yield return Create(Ldnull);
|
||||
break;
|
||||
default:
|
||||
var defaultCtor = module.ImportCtorReference(typedef, parameterTypes: null);
|
||||
if (defaultCtor != null)
|
||||
yield return Create(Newobj, defaultCtor);
|
||||
else
|
||||
{
|
||||
//should never happen. but if it does, this prevents corrupting the IL stack
|
||||
yield return Create(Ldnull);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
public ITaskItem[] CSSFiles { get; set; }
|
||||
|
||||
[Required]
|
||||
public ITaskItem[] OutputFiles { get; set; }
|
||||
public ITaskItem[] OutputFiles { get; set; }
|
||||
|
||||
public string Language { get; set; }
|
||||
public string AssemblyName { get; set; }
|
||||
|
@ -23,33 +23,40 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
bool success = true;
|
||||
Log.LogMessage(MessageImportance.Normal, "Generating assembly attributes for CSS files");
|
||||
if (CSSFiles == null || OutputFiles == null) {
|
||||
if (CSSFiles == null || OutputFiles == null)
|
||||
{
|
||||
Log.LogMessage(MessageImportance.Low, "Skipping CssG");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (CSSFiles.Length != OutputFiles.Length) {
|
||||
if (CSSFiles.Length != OutputFiles.Length)
|
||||
{
|
||||
Log.LogError("\"{2}\" refers to {0} item(s), and \"{3}\" refers to {1} item(s). They must have the same number of items.", CSSFiles.Length, OutputFiles.Length, "CSSFiles", "OutputFiles");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (var i = 0; i < CSSFiles.Length;i++) {
|
||||
for (var i = 0; i < CSSFiles.Length; i++)
|
||||
{
|
||||
var cssFile = CSSFiles[i];
|
||||
var outputFile = OutputFiles[i].ItemSpec;
|
||||
|
||||
var generator = new CssGenerator(cssFile, Language, AssemblyName, outputFile, Log);
|
||||
try {
|
||||
if (!generator.Execute()) {
|
||||
try
|
||||
{
|
||||
if (!generator.Execute())
|
||||
{
|
||||
//If Execute() fails, the file still needs to exist because it is added to the <Compile/> ItemGroup
|
||||
File.WriteAllText(outputFile, string.Empty);
|
||||
}
|
||||
}
|
||||
catch (XmlException xe) {
|
||||
catch (XmlException xe)
|
||||
{
|
||||
Log.LogError(null, null, null, cssFile.ItemSpec, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);
|
||||
|
||||
success = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.LogError(null, null, null, cssFile.ItemSpec, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source);
|
||||
success = false;
|
||||
}
|
||||
|
|
|
@ -17,9 +17,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
LoggingHelper.LogMessage(Normal, $"{new string(' ', 0)}Preparing debug code for xamlc, assembly: {Assembly}");
|
||||
|
||||
var resolver = new DefaultAssemblyResolver();
|
||||
if (ReferencePath != null) {
|
||||
if (ReferencePath != null)
|
||||
{
|
||||
var paths = ReferencePath.Select(p => IOPath.GetDirectoryName(p.Replace("//", "/"))).Distinct();
|
||||
foreach (var searchpath in paths) {
|
||||
foreach (var searchpath in paths)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {searchpath}");
|
||||
resolver.AddSearchDirectory(searchpath);
|
||||
}
|
||||
|
@ -27,32 +29,40 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
var debug = DebugSymbols || (!string.IsNullOrEmpty(DebugType) && DebugType.ToLowerInvariant() != "none");
|
||||
|
||||
using (var assemblyDefinition = AssemblyDefinition.ReadAssembly(Assembly, new ReaderParameters {
|
||||
using (var assemblyDefinition = AssemblyDefinition.ReadAssembly(Assembly, new ReaderParameters
|
||||
{
|
||||
ReadWrite = true,
|
||||
ReadSymbols = debug,
|
||||
AssemblyResolver = resolver
|
||||
})) {
|
||||
foreach (var module in assemblyDefinition.Modules) {
|
||||
}))
|
||||
{
|
||||
foreach (var module in assemblyDefinition.Modules)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Module: {module.Name}");
|
||||
foreach (var resource in module.Resources.OfType<EmbeddedResource>()) {
|
||||
foreach (var resource in module.Resources.OfType<EmbeddedResource>())
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 4)}Resource: {resource.Name}");
|
||||
if (!resource.IsXaml(module, out var classname)) {
|
||||
if (!resource.IsXaml(module, out var classname))
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}skipped.");
|
||||
continue;
|
||||
}
|
||||
TypeDefinition typeDef = module.GetType(classname);
|
||||
if (typeDef == null) {
|
||||
if (typeDef == null)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}no type found... skipped.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var initComp = typeDef.Methods.FirstOrDefault(md => md.Name == "InitializeComponent");
|
||||
if (initComp == null) {
|
||||
if (initComp == null)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}no InitializeComponent found... skipped.");
|
||||
continue;
|
||||
}
|
||||
var initCompRuntime = typeDef.Methods.FirstOrDefault(md => md.Name == "__InitComponentRuntime");
|
||||
if (initCompRuntime == null) {
|
||||
if (initCompRuntime == null)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Creating empty {typeDef.Name}.__InitComponentRuntime");
|
||||
initCompRuntime = new MethodDefinition("__InitComponentRuntime", initComp.Attributes, initComp.ReturnType);
|
||||
initCompRuntime.Body.InitLocals = true;
|
||||
|
@ -68,28 +78,29 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done.");
|
||||
}
|
||||
|
||||
// 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_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_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_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
|
||||
|
||||
var altCtor = typeDef.Methods.FirstOrDefault(md => md.IsConstructor
|
||||
&& md.Parameters.Count == 1
|
||||
&& md.Parameters[0].ParameterType == module.TypeSystem.Boolean);
|
||||
&& md.Parameters.Count == 1
|
||||
&& md.Parameters[0].ParameterType == module.TypeSystem.Boolean);
|
||||
if (altCtor != null)
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing body of {typeDef.Name}.{typeDef.Name} (bool {altCtor.Parameters[0].Name})");
|
||||
else {
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Adding {typeDef.Name}.{typeDef.Name} (bool useCompiledXaml)");
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing body of {typeDef.Name}.{typeDef.Name} (bool {altCtor.Parameters[0].Name})");
|
||||
else
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Adding {typeDef.Name}.{typeDef.Name} (bool useCompiledXaml)");
|
||||
altCtor = new MethodDefinition(".ctor",
|
||||
MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName |
|
||||
MethodAttributes.RTSpecialName, module.TypeSystem.Void);
|
||||
|
@ -97,7 +108,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
module.TypeSystem.Boolean));
|
||||
}
|
||||
|
||||
var body = new MethodBody(altCtor) {
|
||||
var body = new MethodBody(altCtor)
|
||||
{
|
||||
InitLocals = true
|
||||
};
|
||||
var il = body.GetILProcessor();
|
||||
|
@ -105,12 +117,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var ret = Instruction.Create(OpCodes.Ret);
|
||||
il.Emit(OpCodes.Ldarg_0);
|
||||
MethodReference baseCtor;
|
||||
if (typeDef.BaseType.Resolve().GetConstructors().FirstOrDefault(c => c.HasParameters && c.Parameters.Count == 1 && c.Parameters[0].Name == "useCompiledXaml") is MethodDefinition baseCtorDef) {
|
||||
if (typeDef.BaseType.Resolve().GetConstructors().FirstOrDefault(c => c.HasParameters && c.Parameters.Count == 1 && c.Parameters[0].Name == "useCompiledXaml") is MethodDefinition baseCtorDef)
|
||||
{
|
||||
baseCtor = module.ImportReference(baseCtorDef);
|
||||
baseCtor = module.ImportReference(baseCtor.ResolveGenericParameters(typeDef.BaseType, module));
|
||||
il.Emit(OpCodes.Ldarg_1);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
baseCtor = module.ImportReference(typeDef.BaseType.Resolve().GetConstructors().First(c => c.HasParameters == false));
|
||||
baseCtor = module.ImportReference(baseCtor.ResolveGenericParameters(typeDef.BaseType, module));
|
||||
}
|
||||
|
@ -136,7 +150,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
}
|
||||
LoggingHelper.LogMessage(Normal, $"{new string(' ', 0)}Writing the assembly.");
|
||||
assemblyDefinition.Write(new WriterParameters {
|
||||
assemblyDefinition.Write(new WriterParameters
|
||||
{
|
||||
WriteSymbols = debug
|
||||
});
|
||||
}
|
||||
|
|
|
@ -43,10 +43,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return;
|
||||
if (_skips.Contains(propertyName))
|
||||
return;
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains (propertyName))
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains(propertyName))
|
||||
return;
|
||||
var markupString = markupnode.MarkupString;
|
||||
if (ParseExpression(ref markupString, Context, markupnode.NamespaceResolver, markupnode) is IElementNode node) {
|
||||
if (ParseExpression(ref markupString, Context, markupnode.NamespaceResolver, markupnode) is IElementNode node)
|
||||
{
|
||||
((IElementNode)parentNode).Properties[propertyName] = node;
|
||||
node.Accept(new XamlNodeVisitor((n, parent) => n.Parent = parent), parentNode);
|
||||
}
|
||||
|
@ -69,7 +70,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
name = default(XmlName);
|
||||
if (!(parentNode is IElementNode parentElement))
|
||||
return false;
|
||||
foreach (var kvp in parentElement.Properties) {
|
||||
foreach (var kvp in parentElement.Properties)
|
||||
{
|
||||
if (kvp.Value != node)
|
||||
continue;
|
||||
name = kvp.Key;
|
||||
|
@ -94,9 +96,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
throw new BuildException(BuildExceptionCode.MarkupNotClosed, xmlLineInfo, null);
|
||||
|
||||
var provider = new XamlServiceProvider(null, null);
|
||||
provider.Add(typeof (ILContextProvider), new ILContextProvider(context));
|
||||
provider.Add(typeof (IXmlNamespaceResolver), nsResolver);
|
||||
provider.Add(typeof (IXmlLineInfoProvider), new XmlLineInfoProvider(xmlLineInfo));
|
||||
provider.Add(typeof(ILContextProvider), new ILContextProvider(context));
|
||||
provider.Add(typeof(IXmlNamespaceResolver), nsResolver);
|
||||
provider.Add(typeof(IXmlLineInfoProvider), new XmlLineInfoProvider(xmlLineInfo));
|
||||
|
||||
return new MarkupExpansionParser().Parse(match, ref expression, provider);
|
||||
}
|
||||
|
@ -121,7 +123,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
IXmlLineInfo xmlLineInfo = null;
|
||||
if (serviceProvider.GetService(typeof(IXmlLineInfoProvider)) is IXmlLineInfoProvider xmlLineInfoProvider)
|
||||
xmlLineInfo = xmlLineInfoProvider.XmlLineInfo;
|
||||
var contextProvider = serviceProvider.GetService(typeof (ILContextProvider)) as ILContextProvider;
|
||||
var contextProvider = serviceProvider.GetService(typeof(ILContextProvider)) as ILContextProvider;
|
||||
|
||||
var split = match.Split(':');
|
||||
if (split.Length > 2)
|
||||
|
@ -146,9 +148,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Property parsed;
|
||||
do
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
parsed = ParseProperty(serviceProvider, ref remaining);
|
||||
} catch (XamlParseException xpe) {
|
||||
}
|
||||
catch (XamlParseException xpe)
|
||||
{
|
||||
throw new BuildException(BuildExceptionCode.MarkupParsingFailed, xmlLineInfo, xpe);
|
||||
}
|
||||
XmlName childname;
|
||||
|
@ -195,12 +200,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
? new ElementNode(type, "", nsResolver)
|
||||
: new ElementNode(type, "", nsResolver, xmlLineInfo.LineNumber, xmlLineInfo.LinePosition);
|
||||
|
||||
foreach (var (childname, childnode) in childnodes) {
|
||||
if (childname == contentname) {
|
||||
foreach (var (childname, childnode) in childnodes)
|
||||
{
|
||||
if (childname == contentname)
|
||||
{
|
||||
//ContentProperty
|
||||
_node.CollectionItems.Add(childnode);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
_node.Properties[childname] = childnode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Rocks;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
{
|
||||
|
@ -28,7 +28,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
//this can be removed if/when https://github.com/jbevain/cecil/pull/307 is released in a nuget we consume
|
||||
static void OptimizeLongs(this MethodBody self)
|
||||
{
|
||||
for (var i = 0; i < self.Instructions.Count; i++) {
|
||||
for (var i = 0; i < self.Instructions.Count; i++)
|
||||
{
|
||||
var instruction = self.Instructions[i];
|
||||
if (instruction.OpCode.Code != Code.Ldc_I8)
|
||||
continue;
|
||||
|
@ -43,7 +44,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
static void OptimizeStLdLoc(this MethodBody self)
|
||||
{
|
||||
var method = self.Method;
|
||||
for (var i = 0; i < self.Instructions.Count; i++) {
|
||||
for (var i = 0; i < self.Instructions.Count; i++)
|
||||
{
|
||||
var instruction = self.Instructions[i];
|
||||
if (instruction.OpCode.Code != Code.Stloc)
|
||||
continue;
|
||||
|
@ -63,7 +65,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
//Count ldloc for each variable
|
||||
var ldlocUsed = new List<VariableDefinition>();
|
||||
foreach (var instruction in self.Instructions) {
|
||||
foreach (var instruction in self.Instructions)
|
||||
{
|
||||
if (instruction.OpCode.Code != Code.Ldloc)
|
||||
continue;
|
||||
var varDef = (VariableDefinition)instruction.Operand;
|
||||
|
@ -71,7 +74,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
ldlocUsed.Add(varDef);
|
||||
}
|
||||
|
||||
foreach (var varDef in self.Variables.ToArray()) {
|
||||
foreach (var varDef in self.Variables.ToArray())
|
||||
{
|
||||
if (ldlocUsed.Contains(varDef))
|
||||
continue;
|
||||
|
||||
|
|
|
@ -28,11 +28,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var paramType = methodDef.Parameters[i].ParameterType;
|
||||
var genParam = paramType as GenericParameter;
|
||||
if (genParam != null) {
|
||||
if (genParam != null)
|
||||
{
|
||||
var index = genParam.DeclaringType.GenericParameters.IndexOf(genParam);
|
||||
paramType = (declaringTypeRef as GenericInstanceType).GenericArguments[index];
|
||||
}
|
||||
var argType = context.Variables [arguments [i] as IElementNode].VariableType;
|
||||
var argType = context.Variables[arguments[i] as IElementNode].VariableType;
|
||||
if (!argType.InheritsFromOrImplements(paramType))
|
||||
return false;
|
||||
}
|
||||
|
@ -56,7 +57,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
if (!self.HasCustomAttributes)
|
||||
return false;
|
||||
foreach (var arg in self.CustomAttributes) {
|
||||
foreach (var arg in self.CustomAttributes)
|
||||
{
|
||||
if (TypeRefComparer.Default.Equals(arg.AttributeType, attribute))
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
CallingConvention = self.CallingConvention
|
||||
};
|
||||
|
||||
foreach (var parameter in self.Parameters) {
|
||||
foreach (var parameter in self.Parameters)
|
||||
{
|
||||
var definition = new ParameterDefinition(ImportUnresolvedType(parameter.ParameterType, module));
|
||||
|
||||
foreach (var attribute in parameter.CustomAttributes)
|
||||
|
@ -62,9 +63,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
self.Parameters[i].ParameterType = module.ImportReference(self.Parameters[i].ParameterType);
|
||||
}
|
||||
|
||||
public static MethodReference MakeGeneric(this MethodReference self, TypeReference declaringType, params TypeReference [] arguments)
|
||||
public static MethodReference MakeGeneric(this MethodReference self, TypeReference declaringType, params TypeReference[] arguments)
|
||||
{
|
||||
var reference = new MethodReference(self.Name, self.ReturnType) {
|
||||
var reference = new MethodReference(self.Name, self.ReturnType)
|
||||
{
|
||||
DeclaringType = declaringType,
|
||||
HasThis = self.HasThis,
|
||||
ExplicitThis = self.ExplicitThis,
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
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)}>";
|
||||
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;
|
||||
|
@ -50,7 +50,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var ctorKey = $"{type}.ctor({(parameterTypes == null ? "" : string.Join(",", parameterTypes.Select(SerializeTypeReference)))})";
|
||||
if (MethodRefCache.TryGetValue((module, ctorKey), out var ctorRef))
|
||||
return ctorRef;
|
||||
ctorRef = module.ImportCtorReference(type, classArguments: null, predicate: md => {
|
||||
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++)
|
||||
|
@ -82,7 +83,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
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));
|
||||
MethodRefCache.Add((module, ctorKey), ctorRef = module.ImportCtorReference(module.GetTypeDefinition(type), classArguments.Select(module.GetTypeDefinition).ToArray(), md => md.Parameters.Count == paramCount));
|
||||
return ctorRef;
|
||||
}
|
||||
|
||||
|
@ -99,7 +100,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
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 => {
|
||||
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++)
|
||||
|
@ -116,7 +118,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
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 => {
|
||||
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++)
|
||||
|
@ -159,7 +162,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
.Properties
|
||||
.FirstOrDefault(pd =>
|
||||
pd.Name == propertyName
|
||||
&& !pd.SetMethod.IsPrivate
|
||||
&& !pd.SetMethod.IsPrivate
|
||||
&& (predicate?.Invoke(pd) ?? true))
|
||||
?.SetMethod;
|
||||
return setter == null ? null : module.ImportReference(setter);
|
||||
|
@ -169,7 +172,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
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));
|
||||
MethodRefCache.Add((module, setterKey), methodReference = module.ImportPropertySetterReference(module.GetTypeDefinition(type), propertyName, pd => pd.SetMethod.IsStatic == isStatic));
|
||||
return methodReference;
|
||||
}
|
||||
|
||||
|
@ -181,7 +184,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
.Methods
|
||||
.FirstOrDefault(md =>
|
||||
!md.IsConstructor
|
||||
&& !md.IsPrivate
|
||||
&& !md.IsPrivate
|
||||
&& md.Name == methodName
|
||||
&& (predicate?.Invoke(md) ?? true));
|
||||
if (method is null)
|
||||
|
@ -201,7 +204,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
return module.ImportMethodReference(type,
|
||||
methodName: methodName,
|
||||
predicate: md => {
|
||||
predicate: md =>
|
||||
{
|
||||
if (md.IsStatic != isStatic)
|
||||
return false;
|
||||
if (md.Parameters.Count != (parameterTypes?.Length ?? 0))
|
||||
|
@ -226,10 +230,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return methodReference;
|
||||
methodReference = module.ImportMethodReference(module.GetTypeDefinition(type),
|
||||
methodName: methodName,
|
||||
predicate: md => {
|
||||
predicate: md =>
|
||||
{
|
||||
if (md.IsStatic != isStatic)
|
||||
return false;
|
||||
if (md.Parameters.Count != (parameterTypes?.Length ?? 0))
|
||||
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])))
|
||||
|
@ -253,7 +258,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return methodReference;
|
||||
methodReference = module.ImportMethodReference(module.GetTypeDefinition(type),
|
||||
methodName: methodName,
|
||||
predicate: md => {
|
||||
predicate: md =>
|
||||
{
|
||||
if (md.IsStatic != isStatic)
|
||||
return false;
|
||||
if (md.Parameters.Count != paramCount)
|
||||
|
@ -298,13 +304,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
? module.Assembly
|
||||
: module.AssemblyResolver.Resolve(AssemblyNameReference.Parse(type.assemblyName));
|
||||
var typeDef = asm.MainModule.GetType($"{type.clrNamespace}.{type.typeName}");
|
||||
if (typeDef != null) {
|
||||
if (typeDef != null)
|
||||
{
|
||||
typeDefCache.Add((module, type), typeDef);
|
||||
return typeDef;
|
||||
}
|
||||
var exportedType = asm.MainModule.ExportedTypes.FirstOrDefault(
|
||||
arg => arg.IsForwarder && arg.Namespace == type.clrNamespace && arg.Name == type.typeName);
|
||||
if (exportedType != null) {
|
||||
if (exportedType != null)
|
||||
{
|
||||
typeDef = exportedType.Resolve();
|
||||
typeDefCache.Add((module, type), typeDef);
|
||||
return typeDef;
|
||||
|
|
|
@ -18,12 +18,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
public static bool CanConvertValue(this ValueNode node, ILContext context, TypeReference targetTypeRef, IEnumerable<ICustomAttributeProvider> attributeProviders)
|
||||
{
|
||||
TypeReference typeConverter = null;
|
||||
foreach (var attributeProvider in attributeProviders) {
|
||||
foreach (var attributeProvider in attributeProviders)
|
||||
{
|
||||
CustomAttribute typeConverterAttribute;
|
||||
if (
|
||||
(typeConverterAttribute =
|
||||
attributeProvider.CustomAttributes.FirstOrDefault(
|
||||
cad => TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName))) != null) {
|
||||
cad => TypeConverterAttribute.TypeConvertersType.Contains(cad.AttributeType.FullName))) != null)
|
||||
{
|
||||
typeConverter = typeConverterAttribute.ConstructorArguments[0].Value as TypeReference;
|
||||
break;
|
||||
}
|
||||
|
@ -46,7 +48,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var module = context.Body.Method.Module;
|
||||
|
||||
//If there's a [TypeConverter], use it
|
||||
if (typeConverter != null && str != null) {
|
||||
if (typeConverter != null && str != null)
|
||||
{
|
||||
var typeConvAttribute = typeConverter.GetCustomAttribute(module, ("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "TypeConversionAttribute"));
|
||||
if (typeConvAttribute == null) //trust the unattributed TypeConverter
|
||||
return true;
|
||||
|
@ -133,9 +136,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static T TryFormat<T>(Func<string, T> func, IXmlLineInfo lineInfo, string str)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
return func(str);
|
||||
} catch (FormatException fex) {
|
||||
}
|
||||
catch (FormatException fex)
|
||||
{
|
||||
throw new BuildException(BuildExceptionCode.Conversion, lineInfo, fex, str, typeof(T));
|
||||
}
|
||||
}
|
||||
|
@ -147,14 +153,18 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var str = (string)node.Value;
|
||||
//If the TypeConverter has a ProvideCompiledAttribute that can be resolved, shortcut this
|
||||
Type compiledConverterType;
|
||||
if (typeConverter?.GetCustomAttribute(module, ("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "ProvideCompiledAttribute"))?.ConstructorArguments?.First().Value is string compiledConverterName && (compiledConverterType = Type.GetType (compiledConverterName)) != null) {
|
||||
var compiledConverter = Activator.CreateInstance (compiledConverterType);
|
||||
var converter = typeof(ICompiledTypeConverter).GetMethods ().FirstOrDefault (md => md.Name == "ConvertFromString");
|
||||
if (typeConverter?.GetCustomAttribute(module, ("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "ProvideCompiledAttribute"))?.ConstructorArguments?.First().Value is string compiledConverterName && (compiledConverterType = Type.GetType(compiledConverterName)) != null)
|
||||
{
|
||||
var compiledConverter = Activator.CreateInstance(compiledConverterType);
|
||||
var converter = typeof(ICompiledTypeConverter).GetMethods().FirstOrDefault(md => md.Name == "ConvertFromString");
|
||||
IEnumerable<Instruction> instructions;
|
||||
try {
|
||||
try
|
||||
{
|
||||
instructions = (IEnumerable<Instruction>)converter.Invoke(compiledConverter, new object[] {
|
||||
node.Value as string, context, node as BaseNode});
|
||||
} catch (System.Reflection.TargetInvocationException tie) when (tie.InnerException is XamlParseException) {
|
||||
}
|
||||
catch (System.Reflection.TargetInvocationException tie) when (tie.InnerException is XamlParseException)
|
||||
{
|
||||
throw tie.InnerException;
|
||||
}
|
||||
catch (System.Reflection.TargetInvocationException tie) when (tie.InnerException is BuildException)
|
||||
|
@ -164,12 +174,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
foreach (var i in instructions)
|
||||
yield return i;
|
||||
if (targetTypeRef.IsValueType && boxValueTypes)
|
||||
yield return Instruction.Create (OpCodes.Box, module.ImportReference (targetTypeRef));
|
||||
yield return Instruction.Create(OpCodes.Box, module.ImportReference(targetTypeRef));
|
||||
yield break;
|
||||
}
|
||||
|
||||
//If there's a [TypeConverter], use it
|
||||
if (typeConverter != null) {
|
||||
if (typeConverter != null)
|
||||
{
|
||||
var isExtendedConverter = typeConverter.ImplementsInterface(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "IExtendedTypeConverter")));
|
||||
var typeConverterCtorRef = module.ImportCtorReference(typeConverter, paramCount: 0);
|
||||
var convertFromInvariantStringDefinition = isExtendedConverter
|
||||
|
@ -218,7 +229,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
else if (targetTypeRef.FullName == "System.Char")
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, unchecked((int)TryFormat(Char.Parse, node, str)));
|
||||
else if (targetTypeRef.FullName == "System.SByte")
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, unchecked((int)TryFormat(s => SByte.Parse(s,CultureInfo.InvariantCulture), node, str)));
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, unchecked((int)TryFormat(s => SByte.Parse(s, CultureInfo.InvariantCulture), node, str)));
|
||||
else if (targetTypeRef.FullName == "System.Int16")
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4, unchecked((int)TryFormat(s => Int16.Parse(s, CultureInfo.InvariantCulture), node, str)));
|
||||
else if (targetTypeRef.FullName == "System.Int32")
|
||||
|
@ -237,39 +248,47 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return Instruction.Create(OpCodes.Ldc_R4, TryFormat(s => Single.Parse(str, CultureInfo.InvariantCulture), node, str));
|
||||
else if (targetTypeRef.FullName == "System.Double")
|
||||
yield return Instruction.Create(OpCodes.Ldc_R8, TryFormat(s => Double.Parse(str, CultureInfo.InvariantCulture), node, str));
|
||||
else if (targetTypeRef.FullName == "System.Boolean") {
|
||||
else if (targetTypeRef.FullName == "System.Boolean")
|
||||
{
|
||||
if (TryFormat(Boolean.Parse, node, str))
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4_1);
|
||||
else
|
||||
yield return Instruction.Create(OpCodes.Ldc_I4_0);
|
||||
} else if (targetTypeRef.FullName == "System.TimeSpan") {
|
||||
}
|
||||
else if (targetTypeRef.FullName == "System.TimeSpan")
|
||||
{
|
||||
var ts = TryFormat(s => TimeSpan.Parse(s, CultureInfo.InvariantCulture), node, str);
|
||||
var ticks = ts.Ticks;
|
||||
yield return Instruction.Create(OpCodes.Ldc_I8, ticks);
|
||||
yield return Instruction.Create(OpCodes.Newobj, module.ImportCtorReference(("mscorlib", "System", "TimeSpan"), parameterTypes: new[] { ("mscorlib", "System", "Int64") }));
|
||||
} else if (targetTypeRef.FullName == "System.DateTime") {
|
||||
}
|
||||
else if (targetTypeRef.FullName == "System.DateTime")
|
||||
{
|
||||
var dt = TryFormat(s => DateTime.Parse(s, CultureInfo.InvariantCulture), node, str);
|
||||
var ticks = dt.Ticks;
|
||||
yield return Instruction.Create(OpCodes.Ldc_I8, ticks);
|
||||
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))
|
||||
}
|
||||
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")
|
||||
yield return Instruction.Create(OpCodes.Ldstr, str);
|
||||
else if (targetTypeRef.FullName == "System.Object")
|
||||
yield return Instruction.Create(OpCodes.Ldstr, str);
|
||||
else if (targetTypeRef.FullName == "System.Decimal") {
|
||||
else if (targetTypeRef.FullName == "System.Decimal")
|
||||
{
|
||||
decimal outdecimal;
|
||||
if (decimal.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out outdecimal)) {
|
||||
if (decimal.TryParse(str, NumberStyles.Number, CultureInfo.InvariantCulture, out outdecimal))
|
||||
{
|
||||
var vardef = new VariableDefinition(module.ImportReference(("mscorlib", "System", "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"
|
||||
// IL_0008: ldc.i4.s 0x6f
|
||||
// IL_000a: call class [mscorlib]System.Globalization.CultureInfo class [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture()
|
||||
// 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
|
||||
// IL_0003: ldstr "adecimal"
|
||||
// IL_0008: ldc.i4.s 0x6f
|
||||
// IL_000a: call class [mscorlib]System.Globalization.CultureInfo class [mscorlib]System.Globalization.CultureInfo::get_InvariantCulture()
|
||||
// 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 Create(Ldstr, str);
|
||||
yield return Create(Ldc_I4, 0x6f); //NumberStyles.Number
|
||||
yield return Create(Call, module.ImportPropertyGetterReference(("mscorlib", "System.Globalization", "CultureInfo"),
|
||||
|
@ -286,14 +305,19 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
isStatic: true));
|
||||
yield return Create(Pop);
|
||||
yield return Create(Ldloc, vardef);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
yield return Create(Ldc_I4_0);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Decimal"), parameterTypes: new[] { ("mscorlib", "System", "Int32") }));
|
||||
}
|
||||
} else if (implicitOperator != null) {
|
||||
}
|
||||
else if (implicitOperator != null)
|
||||
{
|
||||
yield return Create(Ldstr, node.Value as string);
|
||||
yield return Create(Call, module.ImportReference(implicitOperator));
|
||||
} else
|
||||
}
|
||||
else
|
||||
yield return Create(Ldnull);
|
||||
|
||||
if (isNullable)
|
||||
|
@ -310,8 +334,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
// The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong.
|
||||
// https://msdn.microsoft.com/en-us/library/sbbt4032.aspx
|
||||
byte b = 0; sbyte sb = 0; short s = 0; ushort us = 0;
|
||||
int i = 0; uint ui = 0; long l = 0; ulong ul = 0;
|
||||
byte b = 0;
|
||||
sbyte sb = 0;
|
||||
short s = 0;
|
||||
ushort us = 0;
|
||||
int i = 0;
|
||||
uint ui = 0;
|
||||
long l = 0;
|
||||
ulong ul = 0;
|
||||
bool found = false;
|
||||
TypeReference typeRef = null;
|
||||
|
||||
|
@ -322,37 +352,42 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (typeRef == null)
|
||||
throw new ArgumentException();
|
||||
|
||||
foreach (var v in value.Split(',')) {
|
||||
foreach (var field in enumDef.Fields) {
|
||||
foreach (var v in value.Split(','))
|
||||
{
|
||||
foreach (var field in enumDef.Fields)
|
||||
{
|
||||
if (field.Name == "value__")
|
||||
continue;
|
||||
if (field.Name == v.Trim()) {
|
||||
switch (typeRef.FullName) {
|
||||
case "System.Byte":
|
||||
b |= (byte)field.Constant;
|
||||
break;
|
||||
case "System.SByte":
|
||||
if (found) throw new BuildException(BuildExceptionCode.SByteEnums, lineInfo, null);
|
||||
sb = (sbyte)field.Constant;
|
||||
break;
|
||||
case "System.Int16":
|
||||
s |= (short)field.Constant;
|
||||
break;
|
||||
case "System.UInt16":
|
||||
us |= (ushort)field.Constant;
|
||||
break;
|
||||
case "System.Int32":
|
||||
i |= (int)field.Constant;
|
||||
break;
|
||||
case "System.UInt32":
|
||||
ui |= (uint)field.Constant;
|
||||
break;
|
||||
case "System.Int64":
|
||||
l |= (long)field.Constant;
|
||||
break;
|
||||
case "System.UInt64":
|
||||
ul |= (ulong)field.Constant;
|
||||
break;
|
||||
if (field.Name == v.Trim())
|
||||
{
|
||||
switch (typeRef.FullName)
|
||||
{
|
||||
case "System.Byte":
|
||||
b |= (byte)field.Constant;
|
||||
break;
|
||||
case "System.SByte":
|
||||
if (found)
|
||||
throw new BuildException(BuildExceptionCode.SByteEnums, lineInfo, null);
|
||||
sb = (sbyte)field.Constant;
|
||||
break;
|
||||
case "System.Int16":
|
||||
s |= (short)field.Constant;
|
||||
break;
|
||||
case "System.UInt16":
|
||||
us |= (ushort)field.Constant;
|
||||
break;
|
||||
case "System.Int32":
|
||||
i |= (int)field.Constant;
|
||||
break;
|
||||
case "System.UInt32":
|
||||
ui |= (uint)field.Constant;
|
||||
break;
|
||||
case "System.Int64":
|
||||
l |= (long)field.Constant;
|
||||
break;
|
||||
case "System.UInt64":
|
||||
ul |= (ulong)field.Constant;
|
||||
break;
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
|
@ -362,25 +397,26 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (!found)
|
||||
throw new BuildException(BuildExceptionCode.EnumValueMissing, lineInfo, null, value);
|
||||
|
||||
switch (typeRef.FullName) {
|
||||
case "System.Byte":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)b);
|
||||
case "System.SByte":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)sb);
|
||||
case "System.Int16":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)s);
|
||||
case "System.UInt16":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)us);
|
||||
case "System.Int32":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)i);
|
||||
case "System.UInt32":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (uint)ui);
|
||||
case "System.Int64":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (long)l);
|
||||
case "System.UInt64":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (ulong)ul);
|
||||
default:
|
||||
throw new BuildException(BuildExceptionCode.EnumValueMissing, lineInfo, null, value);
|
||||
switch (typeRef.FullName)
|
||||
{
|
||||
case "System.Byte":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)b);
|
||||
case "System.SByte":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)sb);
|
||||
case "System.Int16":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)s);
|
||||
case "System.UInt16":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)us);
|
||||
case "System.Int32":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (int)i);
|
||||
case "System.UInt32":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (uint)ui);
|
||||
case "System.Int64":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (long)l);
|
||||
case "System.UInt64":
|
||||
return Instruction.Create(OpCodes.Ldc_I4, (ulong)ul);
|
||||
default:
|
||||
throw new BuildException(BuildExceptionCode.EnumValueMissing, lineInfo, null, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -389,12 +425,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var module = context.Body.Method.Module;
|
||||
|
||||
var xmlLineInfo = node as IXmlLineInfo;
|
||||
if (xmlLineInfo == null) {
|
||||
if (xmlLineInfo == null)
|
||||
{
|
||||
yield return Create(Ldnull);
|
||||
yield break;
|
||||
}
|
||||
MethodReference ctor;
|
||||
if (xmlLineInfo.HasLineInfo()) {
|
||||
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"), parameterTypes: new[] {
|
||||
|
@ -496,11 +534,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static IEnumerable<Instruction> PushTargetProperty(FieldReference bpRef, PropertyReference propertyRef, TypeReference declaringTypeReference, ModuleDefinition module)
|
||||
{
|
||||
if (bpRef != null) {
|
||||
if (bpRef != null)
|
||||
{
|
||||
yield return Create(Ldsfld, bpRef);
|
||||
yield break;
|
||||
}
|
||||
if (propertyRef != null) {
|
||||
if (propertyRef != null)
|
||||
{
|
||||
yield return Create(Ldtoken, module.ImportReference(declaringTypeReference ?? propertyRef.DeclaringType));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
yield return Create(Ldstr, propertyRef.Name);
|
||||
|
@ -537,7 +577,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
//Add a SimpleValueTargetProvider and register it as IProvideValueTarget and IReferenceProvider
|
||||
var pushParentIl = node.PushParentObjectsArray(context).ToList();
|
||||
if (pushParentIl[pushParentIl.Count - 1].OpCode != Ldnull) {
|
||||
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, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
|
@ -569,12 +610,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
|
||||
//Add a XamlTypeResolver
|
||||
if (node.NamespaceResolver != null) {
|
||||
if (node.NamespaceResolver != null)
|
||||
{
|
||||
yield return Create(Dup); //Duplicate the serviceProvider
|
||||
yield return Create(Ldtoken, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IXamlTypeResolver")));
|
||||
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)) {
|
||||
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);
|
||||
|
@ -593,7 +636,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return Create(Callvirt, addService);
|
||||
}
|
||||
|
||||
if (node is IXmlLineInfo) {
|
||||
if (node is IXmlLineInfo)
|
||||
{
|
||||
yield return Create(Dup); //Duplicate the serviceProvider
|
||||
yield return Create(Ldtoken, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "IXmlLineInfoProvider")));
|
||||
yield return Create(Call, module.ImportMethodReference(("mscorlib", "System", "Type"), methodName: "GetTypeFromHandle", parameterTypes: new[] { ("mscorlib", "System", "RuntimeTypeHandle") }, isStatic: true));
|
||||
|
|
|
@ -20,7 +20,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
readonly Dictionary<string, Statistic> _Statistics = new Dictionary<string, Statistic>();
|
||||
|
||||
public Dictionary<string, Statistic> Statistics {
|
||||
public Dictionary<string, Statistic> Statistics
|
||||
{
|
||||
get { return _Statistics; }
|
||||
}
|
||||
|
||||
|
@ -59,7 +60,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
public IEnumerable<string> GetStats()
|
||||
{
|
||||
yield return "ID | Call Count | Total Time | Avg Time";
|
||||
foreach (KeyValuePair<string, Statistic> kvp in Statistics.OrderBy(kvp => kvp.Key)) {
|
||||
foreach (KeyValuePair<string, Statistic> kvp in Statistics.OrderBy(kvp => kvp.Key))
|
||||
{
|
||||
string key = ShortenPath(kvp.Key);
|
||||
double total = TimeSpan.FromTicks(kvp.Value.TotalTime).TotalMilliseconds;
|
||||
double avg = total / kvp.Value.CallCount;
|
||||
|
@ -84,7 +86,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Statistic GetStat(string id)
|
||||
{
|
||||
Statistic stats;
|
||||
if (!Statistics.TryGetValue(id, out stats)) {
|
||||
if (!Statistics.TryGetValue(id, out stats))
|
||||
{
|
||||
Statistics[id] = stats = new Statistic();
|
||||
}
|
||||
return stats;
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
#if DEBUG
|
||||
[assembly:InternalsVisibleTo("Xamarin.Forms.Xaml.UnitTests")]
|
||||
[assembly: InternalsVisibleTo("Xamarin.Forms.Xaml.UnitTests")]
|
||||
#endif
|
|
@ -46,19 +46,22 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
VariableDefinition namescopeVarDef;
|
||||
IList<string> namesInNamescope;
|
||||
var setNameScope = false;
|
||||
if (parentNode == null || IsDataTemplate(node, parentNode) || IsStyle(node, parentNode) || IsVisualStateGroupList(node)) {
|
||||
if (parentNode == null || IsDataTemplate(node, parentNode) || IsStyle(node, parentNode) || IsVisualStateGroupList(node))
|
||||
{
|
||||
namescopeVarDef = CreateNamescope();
|
||||
namesInNamescope = new List<string>();
|
||||
setNameScope = true;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
namescopeVarDef = Context.Scopes[parentNode].Item1;
|
||||
namesInNamescope = Context.Scopes[parentNode].Item2;
|
||||
}
|
||||
if (setNameScope && Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.ImportReference(("Xamarin.Forms.Core","Xamarin.Forms","BindableObject"))))
|
||||
if (setNameScope && Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))))
|
||||
SetNameScope(node, namescopeVarDef);
|
||||
Context.Scopes[node] = new Tuple<VariableDefinition, IList<string>>(namescopeVarDef, namesInNamescope);
|
||||
}
|
||||
|
||||
|
||||
public void Visit(RootNode node, INode parentNode)
|
||||
{
|
||||
var namescopeVarDef = GetOrCreateNameScope(node);
|
||||
|
@ -90,7 +93,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Context.Body.Variables.Add(vardef);
|
||||
var stloc = Instruction.Create(OpCodes.Stloc, vardef);
|
||||
|
||||
if (Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject")))) {
|
||||
if (Context.Variables[node].VariableType.InheritsFromOrImplements(Context.Body.Method.Module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"))))
|
||||
{
|
||||
var namescoperef = ("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject");
|
||||
Context.IL.Append(Context.Variables[node].LoadAs(module.GetTypeDefinition(namescoperef), module));
|
||||
Context.IL.Emit(OpCodes.Call, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "NameScope"),
|
||||
|
|
|
@ -77,11 +77,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return;
|
||||
if (skips.Contains(propertyName))
|
||||
return;
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains (propertyName))
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains(propertyName))
|
||||
return;
|
||||
if (propertyName.Equals(XamlParser.McUri, "Ignorable"))
|
||||
return;
|
||||
Context.IL.Append(SetPropertyValue(Context.Variables [(IElementNode)parentNode], propertyName, node, Context, node));
|
||||
Context.IL.Append(SetPropertyValue(Context.Variables[(IElementNode)parentNode], propertyName, node, Context, node));
|
||||
}
|
||||
|
||||
public void Visit(MarkupNode node, INode parentNode)
|
||||
|
@ -94,7 +94,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
//Simplify ListNodes with single elements
|
||||
var pList = parentNode as ListNode;
|
||||
if (pList != null && pList.CollectionItems.Count == 1) {
|
||||
if (pList != null && pList.CollectionItems.Count == 1)
|
||||
{
|
||||
propertyName = pList.XmlName;
|
||||
parentNode = parentNode.Parent;
|
||||
}
|
||||
|
@ -102,7 +103,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if ((propertyName != XmlName.Empty || TryGetPropertyName(node, parentNode, out propertyName)) && skips.Contains(propertyName))
|
||||
return;
|
||||
|
||||
if (propertyName == XmlName._CreateContent) {
|
||||
if (propertyName == XmlName._CreateContent)
|
||||
{
|
||||
SetDataTemplate((IElementNode)parentNode, node, Context, node);
|
||||
return;
|
||||
}
|
||||
|
@ -115,11 +117,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
FieldReference bpRef = null;
|
||||
var _ = false;
|
||||
PropertyDefinition propertyRef = null;
|
||||
if (parentNode is IElementNode && propertyName != XmlName.Empty) {
|
||||
bpRef = GetBindablePropertyReference(Context.Variables [(IElementNode)parentNode], propertyName.NamespaceURI, ref localName, out _, Context, node);
|
||||
propertyRef = Context.Variables [(IElementNode)parentNode].VariableType.GetProperty(pd => pd.Name == localName, out declaringTypeReference);
|
||||
if (parentNode is IElementNode && propertyName != XmlName.Empty)
|
||||
{
|
||||
bpRef = GetBindablePropertyReference(Context.Variables[(IElementNode)parentNode], propertyName.NamespaceURI, ref localName, out _, Context, node);
|
||||
propertyRef = Context.Variables[(IElementNode)parentNode].VariableType.GetProperty(pd => pd.Name == localName, out declaringTypeReference);
|
||||
}
|
||||
Context.IL.Append(ProvideValue(vardefref, Context, Module, node, bpRef:bpRef, propertyRef:propertyRef, propertyDeclaringTypeRef: declaringTypeReference));
|
||||
Context.IL.Append(ProvideValue(vardefref, Context, Module, node, bpRef: bpRef, propertyRef: propertyRef, propertyDeclaringTypeRef: declaringTypeReference));
|
||||
if (vardef != vardefref.VariableDefinition)
|
||||
{
|
||||
vardef = vardefref.VariableDefinition;
|
||||
|
@ -127,15 +130,17 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Context.Variables[node] = vardef;
|
||||
}
|
||||
|
||||
if (propertyName != XmlName.Empty) {
|
||||
if (propertyName != XmlName.Empty)
|
||||
{
|
||||
if (skips.Contains(propertyName))
|
||||
return;
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains (propertyName))
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains(propertyName))
|
||||
return;
|
||||
|
||||
|
||||
Context.IL.Append(SetPropertyValue(Context.Variables[(IElementNode)parentNode], propertyName, node, Context, node));
|
||||
}
|
||||
else if (IsCollectionItem(node, parentNode) && parentNode is IElementNode) {
|
||||
else if (IsCollectionItem(node, parentNode) && parentNode is IElementNode)
|
||||
{
|
||||
var parentVar = Context.Variables[(IElementNode)parentNode];
|
||||
string contentProperty;
|
||||
|
||||
|
@ -173,17 +178,17 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
else if (IsCollectionItem(node, parentNode) && parentNode is ListNode)
|
||||
{
|
||||
// IL_000d: ldloc.2
|
||||
// IL_000e: callvirt instance class [mscorlib]System.Collections.Generic.IList`1<!0> class [Xamarin.Forms.Core]Xamarin.Forms.Layout`1<class [Xamarin.Forms.Core]Xamarin.Forms.View>::get_Children()
|
||||
// IL_0013: ldloc.0
|
||||
// IL_0014: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<class [Xamarin.Forms.Core]Xamarin.Forms.View>::Add(!0)
|
||||
// IL_000d: ldloc.2
|
||||
// IL_000e: callvirt instance class [mscorlib]System.Collections.Generic.IList`1<!0> class [Xamarin.Forms.Core]Xamarin.Forms.Layout`1<class [Xamarin.Forms.Core]Xamarin.Forms.View>::get_Children()
|
||||
// IL_0013: ldloc.0
|
||||
// IL_0014: callvirt instance void class [mscorlib]System.Collections.Generic.ICollection`1<class [Xamarin.Forms.Core]Xamarin.Forms.View>::Add(!0)
|
||||
|
||||
var parentList = (ListNode)parentNode;
|
||||
var parent = Context.Variables[((IElementNode)parentNode.Parent)];
|
||||
|
||||
if (skips.Contains(parentList.XmlName))
|
||||
return;
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains (propertyName))
|
||||
if (parentNode is IElementNode && ((IElementNode)parentNode).SkipProperties.Contains(propertyName))
|
||||
return;
|
||||
var elementType = parent.VariableType;
|
||||
var localname = parentList.XmlName.LocalName;
|
||||
|
@ -191,20 +196,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
TypeReference propertyType;
|
||||
Context.IL.Append(GetPropertyValue(parent, parentList.XmlName, Context, node, out propertyType));
|
||||
|
||||
if (CanAddToResourceDictionary(parent, propertyType, node, node, Context)) {
|
||||
if (CanAddToResourceDictionary(parent, propertyType, node, node, Context))
|
||||
{
|
||||
Context.IL.Append(AddToResourceDictionary(parent, node, node, Context));
|
||||
return;
|
||||
}
|
||||
}
|
||||
var adderTuple = propertyType.GetMethods(md => md.Name == "Add" && md.Parameters.Count == 1, Module).FirstOrDefault() ??
|
||||
throw new BuildException(BuildExceptionCode.AdderMissing, node, null, parent.VariableType, localname);
|
||||
|
||||
|
||||
var adderRef = Module.ImportReference(adderTuple.Item1);
|
||||
adderRef = Module.ImportReference(adderRef.ResolveGenericParameters(adderTuple.Item2, Module));
|
||||
|
||||
Context.IL.Append(vardef.LoadAs(adderRef.Parameters[0].ParameterType.ResolveGenericParameters(adderRef), Module));
|
||||
Context.IL.Emit(OpCodes.Callvirt, adderRef);
|
||||
if (adderRef.ReturnType.FullName != "System.Void")
|
||||
Context.IL.Emit(OpCodes.Pop);
|
||||
Context.IL.Emit(OpCodes.Pop);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,14 +258,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
|
||||
public static IEnumerable<Instruction> ProvideValue(VariableDefinitionReference vardefref, ILContext context,
|
||||
ModuleDefinition module, ElementNode node, FieldReference bpRef = null,
|
||||
PropertyReference propertyRef = null, TypeReference propertyDeclaringTypeRef = null)
|
||||
ModuleDefinition module, ElementNode node, FieldReference bpRef = null,
|
||||
PropertyReference propertyRef = null, TypeReference propertyDeclaringTypeRef = null)
|
||||
{
|
||||
GenericInstanceType markupExtension;
|
||||
IList<TypeReference> genericArguments;
|
||||
if (vardefref.VariableDefinition.VariableType.FullName == "Xamarin.Forms.Xaml.ArrayExtension" &&
|
||||
vardefref.VariableDefinition.VariableType.ImplementsGenericInterface("Xamarin.Forms.Xaml.IMarkupExtension`1",
|
||||
out markupExtension, out genericArguments))
|
||||
vardefref.VariableDefinition.VariableType.ImplementsGenericInterface("Xamarin.Forms.Xaml.IMarkupExtension`1",
|
||||
out markupExtension, out genericArguments))
|
||||
{
|
||||
var markExt = markupExtension.ResolveCached();
|
||||
var provideValueInfo = markExt.Methods.First(md => md.Name == "ProvideValue");
|
||||
|
@ -287,9 +293,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
out markupExtension, out genericArguments))
|
||||
{
|
||||
var acceptEmptyServiceProvider = vardefref.VariableDefinition.VariableType.GetCustomAttribute(module, ("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "AcceptEmptyServiceProviderAttribute")) != null;
|
||||
if ( vardefref.VariableDefinition.VariableType.FullName == "Xamarin.Forms.Xaml.BindingExtension"
|
||||
&& (node.Properties == null || !node.Properties.ContainsKey(new XmlName("", "Source"))) //do not compile bindings if Source is set
|
||||
&& bpRef != null //do not compile bindings if we're not gonna SetBinding
|
||||
if (vardefref.VariableDefinition.VariableType.FullName == "Xamarin.Forms.Xaml.BindingExtension"
|
||||
&& (node.Properties == null || !node.Properties.ContainsKey(new XmlName("", "Source"))) //do not compile bindings if Source is set
|
||||
&& bpRef != null //do not compile bindings if we're not gonna SetBinding
|
||||
)
|
||||
foreach (var instruction in CompileBindingPath(node, context, vardefref.VariableDefinition))
|
||||
yield return instruction;
|
||||
|
@ -335,7 +341,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
//If the IValueProvider has a ProvideCompiledAttribute that can be resolved, shortcut this
|
||||
var compiledValueProviderName = valueProviderType?.GetCustomAttribute(module, ("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "ProvideCompiledAttribute"))?.ConstructorArguments?[0].Value as string;
|
||||
Type compiledValueProviderType;
|
||||
if (compiledValueProviderName != null && (compiledValueProviderType = Type.GetType(compiledValueProviderName)) != null) {
|
||||
if (compiledValueProviderName != null && (compiledValueProviderType = Type.GetType(compiledValueProviderName)) != null)
|
||||
{
|
||||
var compiledValueProvider = Activator.CreateInstance(compiledValueProviderType);
|
||||
var cProvideValue = typeof(ICompiledValueProvider).GetMethods().FirstOrDefault(md => md.Name == "ProvideValue");
|
||||
var instructions = (IEnumerable<Instruction>)cProvideValue.Invoke(compiledValueProvider, new object[] {
|
||||
|
@ -373,13 +380,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (!node.Properties.TryGetValue(new XmlName("", "Path"), out INode pathNode) && node.CollectionItems.Any())
|
||||
pathNode = node.CollectionItems[0];
|
||||
var path = (pathNode as ValueNode)?.Value as string;
|
||||
if ( !node.Properties.TryGetValue(new XmlName("", "Mode"), out INode modeNode)
|
||||
if (!node.Properties.TryGetValue(new XmlName("", "Mode"), out INode modeNode)
|
||||
|| !Enum.TryParse((modeNode as ValueNode)?.Value as string, true, out BindingMode declaredmode))
|
||||
declaredmode = BindingMode.TwoWay; //meaning the mode isn't specified in the Binding extension. generate getters, setters, handlers
|
||||
|
||||
INode dataTypeNode = null;
|
||||
IElementNode n = node;
|
||||
while (n != null) {
|
||||
while (n != null)
|
||||
{
|
||||
if (n.Properties.TryGetValue(XmlName.xDataType, out dataTypeNode))
|
||||
break;
|
||||
n = n.Parent as IElementNode;
|
||||
|
@ -388,14 +396,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (dataTypeNode is null)
|
||||
yield break;
|
||||
|
||||
if ( dataTypeNode is ElementNode enode
|
||||
if (dataTypeNode is ElementNode enode
|
||||
&& enode.XmlType.NamespaceUri == XamlParser.X2009Uri
|
||||
&& enode.XmlType.Name == nameof(Xamarin.Forms.Xaml.NullExtension))
|
||||
yield break;
|
||||
|
||||
string dataType = null;
|
||||
|
||||
if ( dataTypeNode is ElementNode elementNode
|
||||
if (dataTypeNode is ElementNode elementNode
|
||||
&& elementNode.XmlType.NamespaceUri == XamlParser.X2009Uri
|
||||
&& elementNode.XmlType.Name == nameof(Xamarin.Forms.Xaml.TypeExtension)
|
||||
&& elementNode.Properties.ContainsKey(new XmlName("", nameof(Xamarin.Forms.Xaml.TypeExtension.TypeName)))
|
||||
|
@ -421,24 +429,25 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
var properties = ParsePath(path, tSourceRef, node as IXmlLineInfo, module);
|
||||
TypeReference tPropertyRef = tSourceRef;
|
||||
if (properties != null && properties.Count > 0) {
|
||||
if (properties != null && properties.Count > 0)
|
||||
{
|
||||
var lastProp = properties[properties.Count - 1];
|
||||
tPropertyRef = lastProp.property.PropertyType.ResolveGenericParameters(lastProp.propDeclTypeRef);
|
||||
}
|
||||
tPropertyRef = module.ImportReference(tPropertyRef);
|
||||
var valuetupleRef = context.Module.ImportReference(module.ImportReference(("mscorlib", "System", "ValueTuple`2")).MakeGenericInstanceType(new[] { tPropertyRef, module.TypeSystem.Boolean }));
|
||||
var funcRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new [] { tSourceRef, valuetupleRef }));
|
||||
var actionRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Action`2")).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef }));
|
||||
var funcObjRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new [] { tSourceRef, module.TypeSystem.Object }));
|
||||
var tupleRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Tuple`2")).MakeGenericInstanceType(new [] { funcObjRef, module.TypeSystem.String}));
|
||||
var typedBindingRef = module.ImportReference(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "TypedBinding`2")).MakeGenericInstanceType(new [] { tSourceRef, tPropertyRef}));
|
||||
var funcRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new[] { tSourceRef, valuetupleRef }));
|
||||
var actionRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Action`2")).MakeGenericInstanceType(new[] { tSourceRef, tPropertyRef }));
|
||||
var funcObjRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new[] { tSourceRef, module.TypeSystem.Object }));
|
||||
var tupleRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "Tuple`2")).MakeGenericInstanceType(new[] { funcObjRef, module.TypeSystem.String }));
|
||||
var typedBindingRef = module.ImportReference(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Internals", "TypedBinding`2")).MakeGenericInstanceType(new[] { tSourceRef, tPropertyRef }));
|
||||
|
||||
//FIXME: make sure the non-deprecated one is used
|
||||
var ctorInfo = module.ImportReference(typedBindingRef.ResolveCached().Methods.FirstOrDefault(md =>
|
||||
md.IsConstructor
|
||||
&& !md.IsStatic
|
||||
&& md.Parameters.Count == 3
|
||||
&& !md.HasCustomAttributes (module.ImportReference(("mscorlib", "System", "ObsoleteAttribute")))));
|
||||
var ctorInfo = module.ImportReference(typedBindingRef.ResolveCached().Methods.FirstOrDefault(md =>
|
||||
md.IsConstructor
|
||||
&& !md.IsStatic
|
||||
&& md.Parameters.Count == 3
|
||||
&& !md.HasCustomAttributes(module.ImportReference(("mscorlib", "System", "ObsoleteAttribute")))));
|
||||
var ctorinforef = ctorInfo.MakeGeneric(typedBindingRef, funcRef, actionRef, tupleRef);
|
||||
|
||||
var bindingExtensionType = ("Xamarin.Forms.Xaml", "Xamarin.Forms.Xaml", "BindingExtension");
|
||||
|
@ -447,15 +456,19 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return instruction;
|
||||
foreach (var instruction in CompiledBindingGetGetter(tSourceRef, tPropertyRef, properties, node, context))
|
||||
yield return instruction;
|
||||
if (declaredmode != BindingMode.OneTime && declaredmode != BindingMode.OneWay) { //if the mode is explicitly 1w, or 1t, no need for setters
|
||||
if (declaredmode != BindingMode.OneTime && declaredmode != BindingMode.OneWay)
|
||||
{ //if the mode is explicitly 1w, or 1t, no need for setters
|
||||
foreach (var instruction in CompiledBindingGetSetter(tSourceRef, tPropertyRef, properties, node, context))
|
||||
yield return instruction;
|
||||
} else
|
||||
}
|
||||
else
|
||||
yield return Create(Ldnull);
|
||||
if (declaredmode != BindingMode.OneTime) { //if the mode is explicitly 1t, no need for handlers
|
||||
if (declaredmode != BindingMode.OneTime)
|
||||
{ //if the mode is explicitly 1t, no need for handlers
|
||||
foreach (var instruction in CompiledBindingGetHandlers(tSourceRef, tPropertyRef, properties, node, context))
|
||||
yield return instruction;
|
||||
} else
|
||||
}
|
||||
else
|
||||
yield return Create(Ldnull);
|
||||
yield return Create(Newobj, module.ImportReference(ctorinforef));
|
||||
yield return Create(Callvirt, module.ImportPropertySetterReference(bindingExtensionType, propertyName: "TypedBinding"));
|
||||
|
@ -466,19 +479,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (string.IsNullOrWhiteSpace(path))
|
||||
return null;
|
||||
path = path.Trim(' ', '.'); //trim leading or trailing dots
|
||||
var parts = path.Split(new [] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var parts = path.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
var properties = new List<(PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg)>();
|
||||
|
||||
var previousPartTypeRef = tSourceRef;
|
||||
foreach (var part in parts) {
|
||||
foreach (var part in parts)
|
||||
{
|
||||
var p = part;
|
||||
string indexArg = null;
|
||||
var lbIndex = p.IndexOf('[');
|
||||
if (lbIndex != -1) {
|
||||
if (lbIndex != -1)
|
||||
{
|
||||
var rbIndex = p.LastIndexOf(']');
|
||||
if (rbIndex == -1)
|
||||
throw new BuildException(BuildExceptionCode.BindingIndexerNotClosed, lineInfo, null);
|
||||
|
||||
|
||||
var argLength = rbIndex - lbIndex - 1;
|
||||
if (argLength == 0)
|
||||
throw new BuildException(BuildExceptionCode.BindingIndexerEmpty, lineInfo, null);
|
||||
|
@ -491,13 +506,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
p = p.Trim();
|
||||
}
|
||||
|
||||
if (p.Length > 0) {
|
||||
if (p.Length > 0)
|
||||
{
|
||||
var property = previousPartTypeRef.GetProperty(pd => pd.Name == p && pd.GetMethod != null && pd.GetMethod.IsPublic, out var propDeclTypeRef)
|
||||
?? throw new BuildException(BuildExceptionCode.BindingPropertyNotFound, lineInfo, null, p, previousPartTypeRef);
|
||||
properties.Add((property, propDeclTypeRef, null));
|
||||
previousPartTypeRef = property.PropertyType.ResolveGenericParameters(propDeclTypeRef);
|
||||
}
|
||||
if (indexArg != null) {
|
||||
if (indexArg != null)
|
||||
{
|
||||
var defaultMemberAttribute = previousPartTypeRef.GetCustomAttribute(module, ("mscorlib", "System.Reflection", "DefaultMemberAttribute"));
|
||||
var indexerName = defaultMemberAttribute?.ConstructorArguments?.FirstOrDefault().Value as string ?? "Item";
|
||||
PropertyDefinition indexer = null;
|
||||
|
@ -530,11 +547,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var first = true;
|
||||
|
||||
foreach (var (property, propDeclTypeRef, indexArg) in properties) {
|
||||
if (!first && propDeclTypeRef.IsValueType) {
|
||||
foreach (var (property, propDeclTypeRef, indexArg) in properties)
|
||||
{
|
||||
if (!first && propDeclTypeRef.IsValueType)
|
||||
{
|
||||
var importedPropDeclTypeRef = module.ImportReference(propDeclTypeRef);
|
||||
|
||||
if (!locs.TryGetValue(importedPropDeclTypeRef, out var loc)) {
|
||||
if (!locs.TryGetValue(importedPropDeclTypeRef, out var loc))
|
||||
{
|
||||
loc = new VariableDefinition(importedPropDeclTypeRef);
|
||||
locs[importedPropDeclTypeRef] = loc;
|
||||
}
|
||||
|
@ -543,12 +563,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return Create(Ldloca, loc);
|
||||
}
|
||||
|
||||
if (fallback != null && !propDeclTypeRef.IsValueType) {
|
||||
if (fallback != null && !propDeclTypeRef.IsValueType)
|
||||
{
|
||||
yield return Create(Dup);
|
||||
yield return Create(Brfalse, fallback());
|
||||
}
|
||||
|
||||
if (indexArg != null) {
|
||||
if (indexArg != null)
|
||||
{
|
||||
var indexType = property.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(propDeclTypeRef);
|
||||
if (TypeRefComparer.Default.Equals(indexType, module.TypeSystem.String))
|
||||
yield return Create(Ldstr, indexArg);
|
||||
|
@ -571,25 +593,25 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static IEnumerable<Instruction> CompiledBindingGetGetter(TypeReference tSourceRef, TypeReference tPropertyRef, IList<(PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg)> properties, ElementNode node, ILContext context)
|
||||
{
|
||||
// .method private static hidebysig default valuetype[mscorlib] System.ValueTuple`2<string, bool> '<Main>m__0' (class ViewModel A_0) cil managed
|
||||
// {
|
||||
// .custom instance void class [mscorlib] System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: dup
|
||||
// IL_0002: ldnull
|
||||
// IL_0003: ceq
|
||||
// IL_0005: brfalse IL_0013
|
||||
// IL_000a: pop
|
||||
// IL_000b: ldnull
|
||||
// IL_000c: ldc.i4.0
|
||||
// IL_000d: newobj instance void valuetype[mscorlib]System.ValueTuple`2<string, bool>::'.ctor'(!0, !1)
|
||||
// IL_0012: ret
|
||||
// IL_0013: nop
|
||||
// IL_0014: call instance string class ViewModel::get_Text()
|
||||
// IL_0019: ldc.i4.1
|
||||
// IL_001a: newobj instance void valuetype[mscorlib]System.ValueTuple`2<string, bool>::'.ctor'(!0, !1)
|
||||
// IL_001f: ret
|
||||
// }
|
||||
// .method private static hidebysig default valuetype[mscorlib] System.ValueTuple`2<string, bool> '<Main>m__0' (class ViewModel A_0) cil managed
|
||||
// {
|
||||
// .custom instance void class [mscorlib] System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: dup
|
||||
// IL_0002: ldnull
|
||||
// IL_0003: ceq
|
||||
// IL_0005: brfalse IL_0013
|
||||
// IL_000a: pop
|
||||
// IL_000b: ldnull
|
||||
// IL_000c: ldc.i4.0
|
||||
// IL_000d: newobj instance void valuetype[mscorlib]System.ValueTuple`2<string, bool>::'.ctor'(!0, !1)
|
||||
// IL_0012: ret
|
||||
// IL_0013: nop
|
||||
// IL_0014: call instance string class ViewModel::get_Text()
|
||||
// IL_0019: ldc.i4.1
|
||||
// IL_001a: newobj instance void valuetype[mscorlib]System.ValueTuple`2<string, bool>::'.ctor'(!0, !1)
|
||||
// IL_001f: ret
|
||||
// }
|
||||
|
||||
var module = context.Module;
|
||||
var tupleRef = module.ImportReference(module.ImportReference(("mscorlib", "System", "ValueTuple`2")).MakeGenericInstanceType(new[] { tPropertyRef, module.TypeSystem.Boolean }));
|
||||
|
@ -597,21 +619,24 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
tupleCtorRef = module.ImportReference(tupleCtorRef.ResolveGenericParameters(tupleRef, module));
|
||||
var getter = new MethodDefinition($"<{context.Body.Method.Name}>typedBindingsM__{typedBindingCount++}",
|
||||
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static,
|
||||
tupleRef) {
|
||||
tupleRef)
|
||||
{
|
||||
Parameters = { new ParameterDefinition(tSourceRef) },
|
||||
CustomAttributes = { new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null)) }
|
||||
CustomAttributes = { new CustomAttribute(module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null)) }
|
||||
};
|
||||
|
||||
getter.Body.InitLocals = true;
|
||||
var il = getter.Body.GetILProcessor();
|
||||
|
||||
if (properties == null || properties.Count == 0) { //return self
|
||||
if (properties == null || properties.Count == 0)
|
||||
{ //return self
|
||||
il.Emit(Ldarg_0);
|
||||
il.Emit(Ldc_I4_1); //true
|
||||
il.Emit(Newobj, tupleCtorRef);
|
||||
il.Emit(Ret);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
var locs = new Dictionary<TypeReference, VariableDefinition>();
|
||||
|
||||
if (tSourceRef.IsValueType)
|
||||
|
@ -620,7 +645,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
il.Emit(Ldarg_0);
|
||||
|
||||
Instruction pop = null;
|
||||
il.Append(DigProperties(properties, locs, () => {
|
||||
il.Append(DigProperties(properties, locs, () =>
|
||||
{
|
||||
if (pop == null)
|
||||
pop = Create(Pop);
|
||||
|
||||
|
@ -634,8 +660,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
il.Emit(Newobj, tupleCtorRef);
|
||||
il.Emit(Ret);
|
||||
|
||||
if (pop != null) {
|
||||
if (!locs.TryGetValue(tupleRef, out var defaultValueVarDef)) {
|
||||
if (pop != null)
|
||||
{
|
||||
if (!locs.TryGetValue(tupleRef, out var defaultValueVarDef))
|
||||
{
|
||||
defaultValueVarDef = new VariableDefinition(tupleRef);
|
||||
getter.Body.Variables.Add(defaultValueVarDef);
|
||||
}
|
||||
|
@ -649,9 +677,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
context.Body.Method.DeclaringType.Methods.Add(getter);
|
||||
|
||||
// IL_02fa: ldnull
|
||||
// IL_02fb: ldftn valuetype[mscorlib]System.ValueTuple`2 <string,bool> class Test::'<Main>m__0'(class ViewModel)
|
||||
// IL_0301: newobj instance void class [mscorlib] System.Func`2<class ViewModel, valuetype[mscorlib] System.ValueTuple`2<string, bool>>::'.ctor'(object, native int)
|
||||
// IL_02fa: ldnull
|
||||
// IL_02fb: ldftn valuetype[mscorlib]System.ValueTuple`2 <string,bool> class Test::'<Main>m__0'(class ViewModel)
|
||||
// IL_0301: newobj instance void class [mscorlib] System.Func`2<class ViewModel, valuetype[mscorlib] System.ValueTuple`2<string, bool>>::'.ctor'(object, native int)
|
||||
yield return Create(Ldnull);
|
||||
yield return Create(Ldftn, getter);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Func`2"), paramCount: 2, classArguments: new[] { tSourceRef, tupleRef }));
|
||||
|
@ -659,26 +687,28 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static IEnumerable<Instruction> CompiledBindingGetSetter(TypeReference tSourceRef, TypeReference tPropertyRef, IList<(PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg)> properties, ElementNode node, ILContext context)
|
||||
{
|
||||
if (properties == null || properties.Count == 0) {
|
||||
if (properties == null || properties.Count == 0)
|
||||
{
|
||||
yield return Create(Ldnull);
|
||||
yield break;
|
||||
}
|
||||
|
||||
// .method private static hidebysig default void '<Main>m__1' (class ViewModel vm, string s) cil managed
|
||||
// {
|
||||
// .custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
//
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: callvirt instance class ViewModel class ViewModel::get_Model()
|
||||
// IL_0006: ldarg.1
|
||||
// IL_0007: callvirt instance void class ViewModel::set_Text(string)
|
||||
// IL_000c: ret
|
||||
// }
|
||||
// .method private static hidebysig default void '<Main>m__1' (class ViewModel vm, string s) cil managed
|
||||
// {
|
||||
// .custom instance void class [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
//
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: callvirt instance class ViewModel class ViewModel::get_Model()
|
||||
// IL_0006: ldarg.1
|
||||
// IL_0007: callvirt instance void class ViewModel::set_Text(string)
|
||||
// IL_000c: ret
|
||||
// }
|
||||
|
||||
var module = context.Module;
|
||||
var setter = new MethodDefinition($"<{context.Body.Method.Name}>typedBindingsM__{typedBindingCount++}",
|
||||
MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static,
|
||||
module.TypeSystem.Void) {
|
||||
module.TypeSystem.Void)
|
||||
{
|
||||
Parameters = {
|
||||
new ParameterDefinition(tSourceRef),
|
||||
new ParameterDefinition(tPropertyRef)
|
||||
|
@ -690,7 +720,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
setter.Body.InitLocals = true;
|
||||
|
||||
var il = setter.Body.GetILProcessor();
|
||||
if (!properties.Any() || properties.Last().property.SetMethod == null) {
|
||||
if (!properties.Any() || properties.Last().property.SetMethod == null)
|
||||
{
|
||||
yield return Create(Ldnull); //throw or not ?
|
||||
yield break;
|
||||
}
|
||||
|
@ -704,7 +735,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
il.Emit(Ldarg_0);
|
||||
var locs = new Dictionary<TypeReference, VariableDefinition>();
|
||||
Instruction pop = null;
|
||||
il.Append(DigProperties(properties.Take(properties.Count - 1), locs, () => {
|
||||
il.Append(DigProperties(properties.Take(properties.Count - 1), locs, () =>
|
||||
{
|
||||
if (pop == null)
|
||||
pop = Instruction.Create(Pop);
|
||||
|
||||
|
@ -715,17 +747,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
setter.Body.Variables.Add(loc);
|
||||
|
||||
(PropertyDefinition lastProperty, TypeReference lastPropDeclTypeRef, string lastIndexArg) = properties.Last();
|
||||
if (lastPropDeclTypeRef.IsValueType) {
|
||||
if (lastPropDeclTypeRef.IsValueType)
|
||||
{
|
||||
var importedPropDeclTypeRef = module.ImportReference(lastPropDeclTypeRef);
|
||||
|
||||
if (!locs.TryGetValue(importedPropDeclTypeRef, out var loc)) {
|
||||
if (!locs.TryGetValue(importedPropDeclTypeRef, out var loc))
|
||||
{
|
||||
loc = new VariableDefinition(importedPropDeclTypeRef);
|
||||
setter.Body.Variables.Add(loc);
|
||||
}
|
||||
|
||||
il.Emit(Stloc, loc);
|
||||
il.Emit(Ldloca, loc);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pop == null)
|
||||
pop = Instruction.Create(Pop);
|
||||
|
||||
|
@ -733,11 +769,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
il.Emit(Brfalse, pop);
|
||||
}
|
||||
|
||||
if (lastIndexArg != null) {
|
||||
if (lastIndexArg != null)
|
||||
{
|
||||
var indexType = lastProperty.GetMethod.Parameters[0].ParameterType.ResolveGenericParameters(lastPropDeclTypeRef);
|
||||
if (TypeRefComparer.Default.Equals(indexType, module.TypeSystem.String))
|
||||
il.Emit(Ldstr, lastIndexArg);
|
||||
else if (TypeRefComparer.Default.Equals(indexType, module.TypeSystem.Int32)) {
|
||||
else if (TypeRefComparer.Default.Equals(indexType, module.TypeSystem.Int32))
|
||||
{
|
||||
if (!int.TryParse(lastIndexArg, out int index))
|
||||
throw new BuildException(BindingIndexerParse, node as IXmlLineInfo, null, lastIndexArg, lastProperty.Name);
|
||||
il.Emit(Ldc_I4, index);
|
||||
|
@ -753,16 +791,17 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
il.Emit(Ret);
|
||||
|
||||
if (pop != null) {
|
||||
if (pop != null)
|
||||
{
|
||||
il.Append(pop);
|
||||
il.Emit(Ret);
|
||||
}
|
||||
|
||||
context.Body.Method.DeclaringType.Methods.Add(setter);
|
||||
|
||||
// IL_0024: ldnull
|
||||
// IL_0025: ldftn void class Test::'<Main>m__1'(class ViewModel, string)
|
||||
// IL_002b: newobj instance void class [mscorlib]System.Action`2<class ViewModel, string>::'.ctor'(object, native int)
|
||||
// IL_0024: ldnull
|
||||
// IL_0025: ldftn void class Test::'<Main>m__1'(class ViewModel, string)
|
||||
// IL_002b: newobj instance void class [mscorlib]System.Action`2<class ViewModel, string>::'.ctor'(object, native int)
|
||||
yield return Create(Ldnull);
|
||||
yield return Create(Ldftn, setter);
|
||||
yield return Create(Newobj, module.ImportCtorReference(("mscorlib", "System", "Action`2"),
|
||||
|
@ -773,30 +812,33 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static IEnumerable<Instruction> CompiledBindingGetHandlers(TypeReference tSourceRef, TypeReference tPropertyRef, IList<(PropertyDefinition property, TypeReference propDeclTypeRef, string indexArg)> properties, ElementNode node, ILContext context)
|
||||
{
|
||||
// .method private static hidebysig default object '<Main>m__2'(class ViewModel vm) cil managed {
|
||||
// .custom instance void class [mscorlib] System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: ret
|
||||
// } // end of method Test::<Main>m__2
|
||||
// .method private static hidebysig default object '<Main>m__2'(class ViewModel vm) cil managed {
|
||||
// .custom instance void class [mscorlib] System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: ret
|
||||
// } // end of method Test::<Main>m__2
|
||||
|
||||
// .method private static hidebysig default object '<Main>m__3' (class ViewModel vm) cil managed {
|
||||
// .custom instance void class [mscorlib] System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: callvirt instance class ViewModel class ViewModel::get_Model()
|
||||
// IL_0006: ret
|
||||
// }
|
||||
// .method private static hidebysig default object '<Main>m__3' (class ViewModel vm) cil managed {
|
||||
// .custom instance void class [mscorlib] System.Runtime.CompilerServices.CompilerGeneratedAttribute::'.ctor'() = (01 00 00 00 ) // ....
|
||||
// IL_0000: ldarg.0
|
||||
// IL_0001: callvirt instance class ViewModel class ViewModel::get_Model()
|
||||
// IL_0006: ret
|
||||
// }
|
||||
|
||||
var module = context.Module;
|
||||
|
||||
var partGetters = new List<MethodDefinition>();
|
||||
if (properties == null || properties.Count == 0) {
|
||||
if (properties == null || properties.Count == 0)
|
||||
{
|
||||
yield return Create(Ldnull);
|
||||
yield break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < properties.Count; i++) {
|
||||
var tuple = properties [i];
|
||||
var partGetter = new MethodDefinition($"<{context.Body.Method.Name}>typedBindingsM__{typedBindingCount++}", MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, module.TypeSystem.Object) {
|
||||
|
||||
for (int i = 0; i < properties.Count; i++)
|
||||
{
|
||||
var tuple = properties[i];
|
||||
var partGetter = new MethodDefinition($"<{context.Body.Method.Name}>typedBindingsM__{typedBindingCount++}", MethodAttributes.Private | MethodAttributes.HideBySig | MethodAttributes.Static, module.TypeSystem.Object)
|
||||
{
|
||||
Parameters = {
|
||||
new ParameterDefinition(tSourceRef)
|
||||
},
|
||||
|
@ -807,7 +849,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
partGetter.Body.InitLocals = true;
|
||||
var il = partGetter.Body.GetILProcessor();
|
||||
|
||||
if (i == 0) { //return self
|
||||
if (i == 0)
|
||||
{ //return self
|
||||
il.Emit(Ldarg_0);
|
||||
if (tSourceRef.IsValueType)
|
||||
il.Emit(Box, module.ImportReference(tSourceRef));
|
||||
|
@ -835,44 +878,45 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
partGetters.Add(partGetter);
|
||||
}
|
||||
|
||||
var funcObjRef = context.Module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new [] { tSourceRef, module.TypeSystem.Object }));
|
||||
var tupleRef = context.Module.ImportReference(module.ImportReference(("mscorlib", "System", "Tuple`2")).MakeGenericInstanceType(new [] { funcObjRef, module.TypeSystem.String }));
|
||||
var funcObjRef = context.Module.ImportReference(module.ImportReference(("mscorlib", "System", "Func`2")).MakeGenericInstanceType(new[] { tSourceRef, module.TypeSystem.Object }));
|
||||
var tupleRef = context.Module.ImportReference(module.ImportReference(("mscorlib", "System", "Tuple`2")).MakeGenericInstanceType(new[] { funcObjRef, module.TypeSystem.String }));
|
||||
var funcCtor = module.ImportReference(funcObjRef.ResolveCached().GetConstructors().First());
|
||||
funcCtor = funcCtor.MakeGeneric(funcObjRef, new [] { tSourceRef, module.TypeSystem.Object });
|
||||
funcCtor = funcCtor.MakeGeneric(funcObjRef, new[] { tSourceRef, module.TypeSystem.Object });
|
||||
var tupleCtor = module.ImportReference(tupleRef.ResolveCached().GetConstructors().First());
|
||||
tupleCtor = tupleCtor.MakeGeneric(tupleRef, new [] { funcObjRef, module.TypeSystem.String});
|
||||
tupleCtor = tupleCtor.MakeGeneric(tupleRef, new[] { funcObjRef, module.TypeSystem.String });
|
||||
|
||||
// IL_003a: ldc.i4.2
|
||||
// IL_003b: newarr class [mscorlib] System.Tuple`2<class [mscorlib]System.Func`2<class ViewModel,object>,string>
|
||||
// IL_003a: ldc.i4.2
|
||||
// IL_003b: newarr class [mscorlib] System.Tuple`2<class [mscorlib]System.Func`2<class ViewModel,object>,string>
|
||||
|
||||
// IL_0040: dup
|
||||
// IL_0041: ldc.i4.0
|
||||
// IL_0049: ldnull
|
||||
// IL_004a: ldftn object class Test::'<Main>m__2'(class ViewModel)
|
||||
// IL_0050: newobj instance void class [mscorlib]System.Func`2<class ViewModel, object>::'.ctor'(object, native int)
|
||||
// IL_005f: ldstr "Model"
|
||||
// IL_0064: newobj instance void class [mscorlib]System.Tuple`2<class [mscorlib]System.Func`2<class ViewModel, object>, string>::'.ctor'(!0, !1)
|
||||
// IL_0069: stelem.ref
|
||||
// IL_0040: dup
|
||||
// IL_0041: ldc.i4.0
|
||||
// IL_0049: ldnull
|
||||
// IL_004a: ldftn object class Test::'<Main>m__2'(class ViewModel)
|
||||
// IL_0050: newobj instance void class [mscorlib]System.Func`2<class ViewModel, object>::'.ctor'(object, native int)
|
||||
// IL_005f: ldstr "Model"
|
||||
// IL_0064: newobj instance void class [mscorlib]System.Tuple`2<class [mscorlib]System.Func`2<class ViewModel, object>, string>::'.ctor'(!0, !1)
|
||||
// IL_0069: stelem.ref
|
||||
|
||||
// IL_006a: dup
|
||||
// IL_006b: ldc.i4.1
|
||||
// IL_0073: ldnull
|
||||
// IL_0074: ldftn object class Test::'<Main>m__3'(class ViewModel)
|
||||
// IL_007a: newobj instance void class [mscorlib]System.Func`2<class ViewModel, object>::'.ctor'(object, native int)
|
||||
// IL_0089: ldstr "Text"
|
||||
// IL_008e: newobj instance void class [mscorlib]System.Tuple`2<class [mscorlib]System.Func`2<class ViewModel, object>, string>::'.ctor'(!0, !1)
|
||||
// IL_0093: stelem.ref
|
||||
// IL_006a: dup
|
||||
// IL_006b: ldc.i4.1
|
||||
// IL_0073: ldnull
|
||||
// IL_0074: ldftn object class Test::'<Main>m__3'(class ViewModel)
|
||||
// IL_007a: newobj instance void class [mscorlib]System.Func`2<class ViewModel, object>::'.ctor'(object, native int)
|
||||
// IL_0089: ldstr "Text"
|
||||
// IL_008e: newobj instance void class [mscorlib]System.Tuple`2<class [mscorlib]System.Func`2<class ViewModel, object>, string>::'.ctor'(!0, !1)
|
||||
// IL_0093: stelem.ref
|
||||
|
||||
yield return Create(Ldc_I4, properties.Count);
|
||||
yield return Create(Newarr, tupleRef);
|
||||
|
||||
for (var i = 0; i < properties.Count; i++) {
|
||||
for (var i = 0; i < properties.Count; i++)
|
||||
{
|
||||
yield return Create(Dup);
|
||||
yield return Create(Ldc_I4, i);
|
||||
yield return Create(Ldnull);
|
||||
yield return Create(Ldftn, partGetters [i]);
|
||||
yield return Create(Ldftn, partGetters[i]);
|
||||
yield return Create(Newobj, module.ImportReference(funcCtor));
|
||||
yield return Create(Ldstr, properties [i].Item1.Name);
|
||||
yield return Create(Ldstr, properties[i].Item1.Name);
|
||||
yield return Create(Newobj, module.ImportReference(tupleCtor));
|
||||
yield return Create(Stelem_Ref);
|
||||
}
|
||||
|
@ -940,7 +984,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
FieldReference bpRef = bpOwnerType.GetField(fd => fd.Name == name &&
|
||||
fd.IsStatic &&
|
||||
(fd.IsPublic || fd.IsAssembly), out declaringTypeReference);
|
||||
if (bpRef != null) {
|
||||
if (bpRef != null)
|
||||
{
|
||||
bpRef = module.ImportReference(bpRef.ResolveGenericParameters(declaringTypeReference));
|
||||
bpRef.FieldType = module.ImportReference(bpRef.FieldType);
|
||||
}
|
||||
|
@ -961,16 +1006,16 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var adder = module.ImportReference(eventinfo.AddMethod);
|
||||
adder = adder.ResolveGenericParameters(eventDeclaringTypeRef, module);
|
||||
|
||||
// IL_0007: ldloc.0
|
||||
// IL_0008: ldarg.0
|
||||
//
|
||||
// IL_0009: ldftn instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::OnButtonClicked(object, class [mscorlib]System.EventArgs)
|
||||
//OR, if the handler is virtual
|
||||
// IL_000x: ldarg.0
|
||||
// IL_0009: ldvirtftn instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::OnButtonClicked(object, class [mscorlib]System.EventArgs)
|
||||
//
|
||||
// IL_000f: newobj instance void class [mscorlib]System.EventHandler::'.ctor'(object, native int)
|
||||
// IL_0014: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.Button::add_Clicked(class [mscorlib]System.EventHandler)
|
||||
// IL_0007: ldloc.0
|
||||
// IL_0008: ldarg.0
|
||||
//
|
||||
// IL_0009: ldftn instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::OnButtonClicked(object, class [mscorlib]System.EventArgs)
|
||||
//OR, if the handler is virtual
|
||||
// IL_000x: ldarg.0
|
||||
// IL_0009: ldvirtftn instance void class Xamarin.Forms.Xaml.XamlcTests.MyPage::OnButtonClicked(object, class [mscorlib]System.EventArgs)
|
||||
//
|
||||
// IL_000f: newobj instance void class [mscorlib]System.EventHandler::'.ctor'(object, native int)
|
||||
// IL_0014: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.Button::add_Clicked(class [mscorlib]System.EventHandler)
|
||||
|
||||
var value = ((ValueNode)valueNode).Value;
|
||||
|
||||
|
@ -978,7 +1023,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var declaringType = context.Body.Method.DeclaringType;
|
||||
while (declaringType.IsNested)
|
||||
declaringType = declaringType.DeclaringType;
|
||||
var handler = declaringType.AllMethods().FirstOrDefault(md => {
|
||||
var handler = declaringType.AllMethods().FirstOrDefault(md =>
|
||||
{
|
||||
if (md.methodDef.Name != value as string)
|
||||
return false;
|
||||
|
||||
|
@ -989,7 +1035,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return false;
|
||||
|
||||
if (!invoke.ContainsGenericParameter)
|
||||
for (var i = 0; i < invoke.Parameters.Count;i++)
|
||||
for (var i = 0; i < invoke.Parameters.Count; i++)
|
||||
if (!invoke.Parameters[i].ParameterType.InheritsFromOrImplements(md.methodDef.Parameters[i].ParameterType))
|
||||
return false;
|
||||
//TODO check generic parameters if any
|
||||
|
@ -1006,23 +1052,30 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var ctor = module.ImportReference(eventinfo.EventType.ResolveCached().GetConstructors().First());
|
||||
ctor = ctor.ResolveGenericParameters(eventinfo.EventType, module);
|
||||
|
||||
if (handler.methodDef.IsStatic) {
|
||||
if (handler.methodDef.IsStatic)
|
||||
{
|
||||
yield return Create(Ldnull);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
if (context.Root is VariableDefinition)
|
||||
foreach (var instruction in (context.Root as VariableDefinition).LoadAs(ctor.Parameters[0].ParameterType.ResolveGenericParameters(ctor), module))
|
||||
yield return instruction;
|
||||
else if (context.Root is FieldDefinition) {
|
||||
else if (context.Root is FieldDefinition)
|
||||
{
|
||||
yield return Create(Ldarg_0);
|
||||
yield return Create(Ldfld, context.Root as FieldDefinition);
|
||||
} else
|
||||
}
|
||||
else
|
||||
throw new InvalidProgramException();
|
||||
}
|
||||
|
||||
if (handler.methodDef.IsVirtual) {
|
||||
if (handler.methodDef.IsVirtual)
|
||||
{
|
||||
yield return Create(Ldarg_0);
|
||||
yield return Create(Ldvirtftn, handlerRef);
|
||||
} else
|
||||
}
|
||||
else
|
||||
yield return Create(Ldftn, handlerRef);
|
||||
|
||||
yield return Create(Newobj, module.ImportReference(ctor));
|
||||
|
@ -1037,7 +1090,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var elementNode = valueNode as IElementNode;
|
||||
if (elementNode == null)
|
||||
return false;
|
||||
|
||||
|
||||
VariableDefinition varValue;
|
||||
if (!context.Variables.TryGetValue(valueNode as IElementNode, out varValue))
|
||||
return false;
|
||||
|
@ -1075,7 +1128,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
if (!context.Variables.TryGetValue(valueNode as IElementNode, out VariableDefinition varValue))
|
||||
return false;
|
||||
var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(module.ImportReference(("Xamarin.Forms.Core","Xamarin.Forms","BindingBase")), module);
|
||||
var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindingBase")), module);
|
||||
if (implicitOperator != null)
|
||||
return true;
|
||||
|
||||
|
@ -1095,7 +1148,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
foreach (var instruction in parent.LoadAs(module.GetTypeDefinition(bindableObjectType), module))
|
||||
yield return instruction;
|
||||
yield return Create(Ldsfld, bpRef);
|
||||
foreach (var instruction in context.Variables [elementNode].LoadAs(module.GetTypeDefinition(parameterTypes[1]), module))
|
||||
foreach (var instruction in context.Variables[elementNode].LoadAs(module.GetTypeDefinition(parameterTypes[1]), module))
|
||||
yield return instruction;
|
||||
yield return Create(Callvirt, module.ImportMethodReference(("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject"),
|
||||
methodName: "SetBinding",
|
||||
|
@ -1108,7 +1161,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
if (bpRef == null)
|
||||
return false;
|
||||
|
||||
|
||||
if (node is ValueNode valueNode && valueNode.CanConvertValue(context, bpRef))
|
||||
return true;
|
||||
|
||||
|
@ -1121,7 +1174,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var bpTypeRef = bpRef.GetBindablePropertyType(iXmlLineInfo, module);
|
||||
// If it's an attached BP, there's no second chance to handle IMarkupExtensions, so we try here.
|
||||
// Worst case scenario ? InvalidCastException at runtime
|
||||
if (attached && varValue.VariableType.FullName == "System.Object")
|
||||
if (attached && varValue.VariableType.FullName == "System.Object")
|
||||
return true;
|
||||
var implicitOperator = varValue.VariableType.GetImplicitOperatorTo(bpTypeRef, module);
|
||||
if (implicitOperator != null)
|
||||
|
@ -1156,20 +1209,23 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var module = context.Body.Method.Module;
|
||||
var bindableObjectType = ("Xamarin.Forms.Core", "Xamarin.Forms", "BindableObject");
|
||||
|
||||
// IL_0007: ldloc.0
|
||||
// IL_0008: ldsfld class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.Label::TextProperty
|
||||
// IL_000d: ldstr "foo"
|
||||
// IL_0012: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue(class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty, object)
|
||||
// IL_0007: ldloc.0
|
||||
// IL_0008: ldsfld class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty [Xamarin.Forms.Core]Xamarin.Forms.Label::TextProperty
|
||||
// IL_000d: ldstr "foo"
|
||||
// IL_0012: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.BindableObject::SetValue(class [Xamarin.Forms.Core]Xamarin.Forms.BindableProperty, object)
|
||||
|
||||
foreach (var instruction in parent.LoadAs(module.GetTypeDefinition(bindableObjectType), module))
|
||||
yield return instruction;
|
||||
|
||||
yield return Create(Ldsfld, bpRef);
|
||||
|
||||
if (valueNode != null) {
|
||||
foreach (var instruction in valueNode.PushConvertedValue(context, bpRef, valueNode.PushServiceProvider(context, bpRef:bpRef), true, false))
|
||||
if (valueNode != null)
|
||||
{
|
||||
foreach (var instruction in valueNode.PushConvertedValue(context, bpRef, valueNode.PushServiceProvider(context, bpRef: bpRef), true, false))
|
||||
yield return instruction;
|
||||
} else if (elementNode != null) {
|
||||
}
|
||||
else if (elementNode != null)
|
||||
{
|
||||
var bpTypeRef = bpRef.GetBindablePropertyType(iXmlLineInfo, module);
|
||||
foreach (var instruction in context.Variables[elementNode].LoadAs(bpTypeRef, module))
|
||||
yield return instruction;
|
||||
|
@ -1199,9 +1255,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
yield return instruction;
|
||||
|
||||
yield return Create(Ldsfld, bpRef);
|
||||
yield return Create(Callvirt, module.ImportMethodReference(bindableObjectType,
|
||||
yield return Create(Callvirt, module.ImportMethodReference(bindableObjectType,
|
||||
methodName: "GetValue",
|
||||
parameterTypes: new[] { ("Xamarin.Forms.Core", "Xamarin.Forms", "BindableProperty")}));
|
||||
parameterTypes: new[] { ("Xamarin.Forms.Core", "Xamarin.Forms", "BindableProperty") }));
|
||||
}
|
||||
|
||||
static bool CanSet(VariableDefinition parent, string localName, INode node, ILContext context)
|
||||
|
@ -1217,14 +1273,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return false;
|
||||
|
||||
var valueNode = node as ValueNode;
|
||||
if (valueNode != null && valueNode.CanConvertValue(context, propertyType, new ICustomAttributeProvider[] { property, propertyType.ResolveCached()}))
|
||||
if (valueNode != null && valueNode.CanConvertValue(context, propertyType, new ICustomAttributeProvider[] { property, propertyType.ResolveCached() }))
|
||||
return true;
|
||||
|
||||
var elementNode = node as IElementNode;
|
||||
if (elementNode == null)
|
||||
return false;
|
||||
|
||||
var vardef = context.Variables [elementNode];
|
||||
var vardef = context.Variables[elementNode];
|
||||
var implicitOperator = vardef.VariableType.GetImplicitOperatorTo(propertyType, module);
|
||||
|
||||
if (vardef.VariableType.InheritsFromOrImplements(propertyType))
|
||||
|
@ -1268,9 +1324,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var property = parent.VariableType.GetProperty(pd => pd.Name == localName, out declaringTypeReference);
|
||||
var propertySetter = property.SetMethod;
|
||||
|
||||
// IL_0007: ldloc.0
|
||||
// IL_0008: ldstr "foo"
|
||||
// IL_000d: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.Label::set_Text(string)
|
||||
// IL_0007: ldloc.0
|
||||
// IL_0008: ldstr "foo"
|
||||
// IL_000d: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.Label::set_Text(string)
|
||||
|
||||
module.ImportReference(parent.VariableType.ResolveCached());
|
||||
var propertySetterRef = module.ImportReference(module.ImportReference(propertySetter).ResolveGenericParameters(declaringTypeReference, module));
|
||||
|
@ -1285,15 +1341,18 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
else
|
||||
yield return Instruction.Create(OpCodes.Ldloc, parent);
|
||||
|
||||
if (valueNode != null) {
|
||||
foreach (var instruction in valueNode.PushConvertedValue(context, propertyType, new ICustomAttributeProvider [] { property, propertyType.ResolveCached() }, valueNode.PushServiceProvider(context, propertyRef:property), false, true))
|
||||
if (valueNode != null)
|
||||
{
|
||||
foreach (var instruction in valueNode.PushConvertedValue(context, propertyType, new ICustomAttributeProvider[] { property, propertyType.ResolveCached() }, valueNode.PushServiceProvider(context, propertyRef: property), false, true))
|
||||
yield return instruction;
|
||||
if (parent.VariableType.IsValueType)
|
||||
yield return Instruction.Create(OpCodes.Call, propertySetterRef);
|
||||
else
|
||||
yield return Instruction.Create(OpCodes.Callvirt, propertySetterRef);
|
||||
} else if (elementNode != null) {
|
||||
foreach (var instruction in context.Variables [elementNode].LoadAs(propertyType, module))
|
||||
}
|
||||
else if (elementNode != null)
|
||||
{
|
||||
foreach (var instruction in context.Variables[elementNode].LoadAs(propertyType, module))
|
||||
yield return instruction;
|
||||
if (parent.VariableType.IsValueType)
|
||||
yield return Instruction.Create(OpCodes.Call, propertySetterRef);
|
||||
|
@ -1334,7 +1393,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (!(valueNode is IElementNode elementNode))
|
||||
return false;
|
||||
|
||||
if ( !CanGetValue(parent, bpRef, attached, null, context, out TypeReference propertyType)
|
||||
if (!CanGetValue(parent, bpRef, attached, null, context, out TypeReference propertyType)
|
||||
&& !CanGet(parent, localName, context, out propertyType))
|
||||
return false;
|
||||
|
||||
|
@ -1364,11 +1423,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
static Dictionary<VariableDefinition, IList<string>> resourceNamesInUse = new Dictionary<VariableDefinition, IList<string>>();
|
||||
static bool CanAddToResourceDictionary(VariableDefinition parent, TypeReference collectionType, IElementNode node, IXmlLineInfo lineInfo, ILContext context)
|
||||
{
|
||||
if ( collectionType.FullName != "Xamarin.Forms.ResourceDictionary"
|
||||
if (collectionType.FullName != "Xamarin.Forms.ResourceDictionary"
|
||||
&& collectionType.ResolveCached().BaseType?.FullName != "Xamarin.Forms.ResourceDictionary")
|
||||
return false;
|
||||
|
||||
if (node.Properties.ContainsKey(XmlName.xKey)) {
|
||||
if (node.Properties.ContainsKey(XmlName.xKey))
|
||||
{
|
||||
var key = (node.Properties[XmlName.xKey] as ValueNode).Value as string;
|
||||
if (!resourceNamesInUse.TryGetValue(parent, out var names))
|
||||
resourceNamesInUse[parent] = (names = new List<string>());
|
||||
|
@ -1391,13 +1451,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
var elementNode = node as IElementNode;
|
||||
var vardef = context.Variables [elementNode];
|
||||
var vardef = context.Variables[elementNode];
|
||||
|
||||
TypeReference propertyType;
|
||||
foreach (var instruction in GetPropertyValue(parent, propertyName, context, iXmlLineInfo, out propertyType))
|
||||
yield return instruction;
|
||||
|
||||
if (CanAddToResourceDictionary(parent, propertyType, elementNode, iXmlLineInfo, context)) {
|
||||
if (CanAddToResourceDictionary(parent, propertyType, elementNode, iXmlLineInfo, context))
|
||||
{
|
||||
foreach (var instruction in AddToResourceDictionary(parent, elementNode, iXmlLineInfo, context))
|
||||
yield return instruction;
|
||||
yield break;
|
||||
|
@ -1418,14 +1479,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var module = context.Body.Method.Module;
|
||||
|
||||
if (node.Properties.ContainsKey(XmlName.xKey)) {
|
||||
if (node.Properties.ContainsKey(XmlName.xKey))
|
||||
{
|
||||
var names = resourceNamesInUse[parent];
|
||||
var key = (node.Properties[XmlName.xKey] as ValueNode).Value as string;
|
||||
names.Add(key);
|
||||
|
||||
// IL_0014: ldstr "key"
|
||||
// IL_0019: ldstr "foo"
|
||||
// IL_001e: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.ResourceDictionary::Add(string, object)
|
||||
// IL_0014: ldstr "key"
|
||||
// IL_0019: ldstr "foo"
|
||||
// IL_001e: callvirt instance void class [Xamarin.Forms.Core]Xamarin.Forms.ResourceDictionary::Add(string, object)
|
||||
yield return Create(Ldstr, (key));
|
||||
foreach (var instruction in context.Variables[node].LoadAs(module.TypeSystem.Object, module))
|
||||
yield return instruction;
|
||||
|
@ -1479,7 +1541,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
"<" + parentContext.Body.Method.Name + ">_anonXamlCDataTemplate_" + dtcount++,
|
||||
TypeAttributes.BeforeFieldInit |
|
||||
TypeAttributes.Sealed |
|
||||
TypeAttributes.NestedPrivate) {
|
||||
TypeAttributes.NestedPrivate)
|
||||
{
|
||||
BaseType = module.TypeSystem.Object,
|
||||
CustomAttributes = {
|
||||
new CustomAttribute (module.ImportCtorReference(("mscorlib", "System.Runtime.CompilerServices", "CompilerGeneratedAttribute"), parameterTypes: null)),
|
||||
|
@ -1571,7 +1634,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
var runTimeName = attributes[0].ConstructorArguments[0].Value as string;
|
||||
|
||||
if (string.IsNullOrEmpty(runTimeName))
|
||||
if (string.IsNullOrEmpty(runTimeName))
|
||||
return false;
|
||||
|
||||
Context.IL.Append(SetPropertyValue(variableDefinition, new XmlName("", runTimeName), node, Context, node));
|
||||
|
|
|
@ -39,19 +39,21 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
XmlName propertyName;
|
||||
//Set ResourcesDictionaries to their parents
|
||||
if (IsResourceDictionary(node) && SetPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName)) {
|
||||
if ((propertyName.LocalName == "Resources" || propertyName.LocalName.EndsWith(".Resources", StringComparison.Ordinal))) {
|
||||
if (IsResourceDictionary(node) && SetPropertiesVisitor.TryGetPropertyName(node, parentNode, out propertyName))
|
||||
{
|
||||
if ((propertyName.LocalName == "Resources" || propertyName.LocalName.EndsWith(".Resources", StringComparison.Ordinal)))
|
||||
{
|
||||
Context.IL.Append(SetPropertiesVisitor.SetPropertyValue(Context.Variables[(IElementNode)parentNode], propertyName, node, Context, node));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//Only proceed further if the node is a keyless RD
|
||||
if ( parentNode is IElementNode
|
||||
if (parentNode is IElementNode
|
||||
&& IsResourceDictionary((IElementNode)parentNode)
|
||||
&& !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
|
||||
node.Accept(new SetPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
|
||||
else if ( parentNode is ListNode
|
||||
else if (parentNode is ListNode
|
||||
&& IsResourceDictionary((IElementNode)parentNode.Parent)
|
||||
&& !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))
|
||||
node.Accept(new SetPropertiesVisitor(Context, stopOnResourceDictionary: false), parentNode);
|
||||
|
@ -79,13 +81,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var enode = node as ElementNode;
|
||||
if (enode == null)
|
||||
return false;
|
||||
if ( parentNode is IElementNode
|
||||
&& IsResourceDictionary((IElementNode)parentNode)
|
||||
&& !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
|
||||
if (parentNode is IElementNode
|
||||
&& IsResourceDictionary((IElementNode)parentNode)
|
||||
&& !((IElementNode)parentNode).Properties.ContainsKey(XmlName.xKey))
|
||||
return true;
|
||||
if ( parentNode is ListNode
|
||||
&& IsResourceDictionary((IElementNode)parentNode.Parent)
|
||||
&& !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))
|
||||
if (parentNode is ListNode
|
||||
&& IsResourceDictionary((IElementNode)parentNode.Parent)
|
||||
&& !((IElementNode)parentNode.Parent).Properties.ContainsKey(XmlName.xKey))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var module = targetType.Module;
|
||||
var voidType = module.ImportReference(("mscorlib", "System", "Void"));
|
||||
var methodAttributes = MethodAttributes.Public |
|
||||
MethodAttributes.HideBySig |
|
||||
MethodAttributes.SpecialName |
|
||||
MethodAttributes.RTSpecialName;
|
||||
MethodAttributes.HideBySig |
|
||||
MethodAttributes.SpecialName |
|
||||
MethodAttributes.RTSpecialName;
|
||||
|
||||
var parentctor = module.ImportCtorReference(parentType, paramCount: 0) ?? module.ImportCtorReference(("mscorlib", "System", "Object"), parameterTypes: null);
|
||||
|
||||
|
@ -49,7 +49,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
public static IEnumerable<(MethodDefinition methodDef, TypeReference declTypeRef)> AllMethods(this TypeDefinition self)
|
||||
{
|
||||
TypeReference selfTypeRef = self;
|
||||
while (self != null) {
|
||||
while (self != null)
|
||||
{
|
||||
foreach (var md in self.Methods)
|
||||
yield return (md, selfTypeRef);
|
||||
selfTypeRef = self.BaseType;
|
||||
|
|
|
@ -34,12 +34,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
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)
|
||||
|| xasm.StartsWith("System.Xml", StringComparison.Ordinal))
|
||||
&& ( yasm.StartsWith("System.Runtime", StringComparison.Ordinal)
|
||||
&& (yasm.StartsWith("System.Runtime", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("System", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("mscorlib", StringComparison.Ordinal)
|
||||
|| yasm.StartsWith("netstandard", StringComparison.Ordinal)
|
||||
|
@ -67,10 +67,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var properties = typeDef.Properties.Where(predicate);
|
||||
if (properties.Any())
|
||||
return properties.Single();
|
||||
if (typeDef.IsInterface) {
|
||||
foreach (var face in typeDef.Interfaces) {
|
||||
if (typeDef.IsInterface)
|
||||
{
|
||||
foreach (var face in typeDef.Interfaces)
|
||||
{
|
||||
var p = face.InterfaceType.ResolveGenericParameters(typeRef).GetProperty(predicate, out var interfaceDeclaringTypeRef);
|
||||
if (p != null) {
|
||||
if (p != null)
|
||||
{
|
||||
declaringTypeRef = interfaceDeclaringTypeRef;
|
||||
return p;
|
||||
}
|
||||
|
@ -87,7 +90,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
declaringTypeRef = typeRef;
|
||||
var typeDef = typeRef.ResolveCached();
|
||||
var events = typeDef.Events.Where(predicate);
|
||||
if (events.Any()) {
|
||||
if (events.Any())
|
||||
{
|
||||
var ev = events.Single();
|
||||
return ev.ResolveGenericEvent(declaringTypeRef);
|
||||
}
|
||||
|
@ -182,20 +186,28 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
public static bool InheritsFromOrImplements(this TypeReference typeRef, TypeReference baseClass)
|
||||
{
|
||||
if (typeRef is GenericInstanceType genericInstance) {
|
||||
if (typeRef is GenericInstanceType genericInstance)
|
||||
{
|
||||
if (baseClass is GenericInstanceType genericInstanceBaseClass &&
|
||||
TypeRefComparer.Default.Equals(genericInstance.ElementType, genericInstanceBaseClass.ElementType)) {
|
||||
foreach (var parameter in genericInstanceBaseClass.ElementType.ResolveCached().GenericParameters) {
|
||||
TypeRefComparer.Default.Equals(genericInstance.ElementType, genericInstanceBaseClass.ElementType))
|
||||
{
|
||||
foreach (var parameter in genericInstanceBaseClass.ElementType.ResolveCached().GenericParameters)
|
||||
{
|
||||
var argument = genericInstance.GenericArguments[parameter.Position];
|
||||
var baseClassArgument = genericInstanceBaseClass.GenericArguments[parameter.Position];
|
||||
|
||||
if (parameter.IsCovariant) {
|
||||
if (parameter.IsCovariant)
|
||||
{
|
||||
if (!argument.InheritsFromOrImplements(baseClassArgument))
|
||||
return false;
|
||||
} else if (parameter.IsContravariant) {
|
||||
}
|
||||
else if (parameter.IsContravariant)
|
||||
{
|
||||
if (!baseClassArgument.InheritsFromOrImplements(argument))
|
||||
return false;
|
||||
} else if (!TypeRefComparer.Default.Equals(argument, baseClassArgument)) {
|
||||
}
|
||||
else if (!TypeRefComparer.Default.Equals(argument, baseClassArgument))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -203,11 +215,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
if (TypeRefComparer.Default.Equals(typeRef, baseClass))
|
||||
return true;
|
||||
|
||||
if (typeRef.IsArray) {
|
||||
if (typeRef.IsArray)
|
||||
{
|
||||
var array = (ArrayType)typeRef;
|
||||
var arrayType = typeRef.ResolveCached();
|
||||
if (arrayInterfaces.Contains(baseClass.FullName))
|
||||
|
@ -326,24 +340,26 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (TypeRefComparer.Default.Equals(fromType, toType))
|
||||
return null;
|
||||
|
||||
var implicitOperatorsOnFromType = fromType.GetMethods(md => md.IsPublic
|
||||
var implicitOperatorsOnFromType = fromType.GetMethods(md => md.IsPublic
|
||||
&& md.IsStatic
|
||||
&& md.IsSpecialName
|
||||
&& md.Name == "op_Implicit", module);
|
||||
var implicitOperatorsOnToType = toType.GetMethods(md => md.IsPublic
|
||||
var implicitOperatorsOnToType = toType.GetMethods(md => md.IsPublic
|
||||
&& md.IsStatic
|
||||
&& md.IsSpecialName
|
||||
&& md.Name == "op_Implicit", module);
|
||||
var implicitOperators = implicitOperatorsOnFromType.Concat(implicitOperatorsOnToType).ToList();
|
||||
|
||||
if (implicitOperators.Any()) {
|
||||
foreach (var op in implicitOperators) {
|
||||
if (implicitOperators.Any())
|
||||
{
|
||||
foreach (var op in implicitOperators)
|
||||
{
|
||||
var cast = op.Item1;
|
||||
var opDeclTypeRef = op.Item2;
|
||||
var castDef = module.ImportReference(cast).ResolveGenericParameters(opDeclTypeRef, module);
|
||||
var returnType = castDef.ReturnType;
|
||||
if (returnType.IsGenericParameter)
|
||||
returnType = ((GenericInstanceType)opDeclTypeRef).GenericArguments [((GenericParameter)returnType).Position];
|
||||
returnType = ((GenericInstanceType)opDeclTypeRef).GenericArguments[((GenericParameter)returnType).Position];
|
||||
if (!returnType.InheritsFromOrImplements(toType))
|
||||
continue;
|
||||
var paramType = cast.Parameters[0].ParameterType.ResolveGenericParameters(castDef);
|
||||
|
@ -362,15 +378,17 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var declaringTypeReference = declaringMethodReference.DeclaringType;
|
||||
var genericdeclType = declaringTypeReference as GenericInstanceType;
|
||||
|
||||
if (genericParameterSelf != null) {
|
||||
switch (genericParameterSelf.Type) {
|
||||
case GenericParameterType.Method:
|
||||
self = genericdeclMethod.GenericArguments[genericParameterSelf.Position];
|
||||
break;
|
||||
if (genericParameterSelf != null)
|
||||
{
|
||||
switch (genericParameterSelf.Type)
|
||||
{
|
||||
case GenericParameterType.Method:
|
||||
self = genericdeclMethod.GenericArguments[genericParameterSelf.Position];
|
||||
break;
|
||||
|
||||
case GenericParameterType.Type:
|
||||
self = genericdeclType.GenericArguments[genericParameterSelf.Position];
|
||||
break;
|
||||
case GenericParameterType.Type:
|
||||
self = genericdeclType.GenericArguments[genericParameterSelf.Position];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -379,7 +397,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
return self;
|
||||
|
||||
genericself = genericself.ResolveGenericParameters(declaringTypeReference);
|
||||
for (var i = 0; i < genericself.GenericArguments.Count; i++) {
|
||||
for (var i = 0; i < genericself.GenericArguments.Count; i++)
|
||||
{
|
||||
var genericParameter = genericself.GenericArguments[i] as GenericParameter;
|
||||
if (genericParameter != null)
|
||||
genericself.GenericArguments[i] = genericdeclMethod.GenericArguments[genericParameter.Position];
|
||||
|
@ -396,7 +415,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (genericdeclType == null && genericParameterSelf == null && genericself == null)
|
||||
return self;
|
||||
|
||||
if (genericdeclType == null && genericParameterSelf!=null)
|
||||
if (genericdeclType == null && genericParameterSelf != null)
|
||||
{
|
||||
var typeDef = declaringTypeReference.Resolve();
|
||||
if (typeDef.BaseType == null || typeDef.BaseType.FullName == "System.Object")
|
||||
|
@ -424,7 +443,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
public static GenericInstanceType ResolveGenericParameters(this GenericInstanceType self, GenericInstanceType declaringTypeReference)
|
||||
{
|
||||
List<TypeReference> args = new List<TypeReference>();
|
||||
for (var i = 0; i < self.GenericArguments.Count; i++) {
|
||||
for (var i = 0; i < self.GenericArguments.Count; i++)
|
||||
{
|
||||
var genericParameter = self.GenericArguments[i] as GenericParameter;
|
||||
if (genericParameter == null)
|
||||
args.Add(self.GenericArguments[i].ResolveGenericParameters(declaringTypeReference));
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Cil;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
{
|
||||
|
|
|
@ -17,21 +17,23 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
if (TryResolve(name, out AssemblyDefinition assembly))
|
||||
return assembly;
|
||||
if ( IsMscorlib(name)
|
||||
&& ( TryResolve(AssemblyNameReference.Parse("mscorlib"), out assembly)
|
||||
|| TryResolve(AssemblyNameReference.Parse("netstandard"), out assembly)
|
||||
|| TryResolve(AssemblyNameReference.Parse("System.Runtime"), out assembly)))
|
||||
if (IsMscorlib(name)
|
||||
&& (TryResolve(AssemblyNameReference.Parse("mscorlib"), out assembly)
|
||||
|| TryResolve(AssemblyNameReference.Parse("netstandard"), out assembly)
|
||||
|| TryResolve(AssemblyNameReference.Parse("System.Runtime"), out assembly)))
|
||||
return assembly;
|
||||
throw new AssemblyResolutionException(name);
|
||||
}
|
||||
|
||||
bool TryResolve(AssemblyNameReference assemblyNameReference, out AssemblyDefinition assembly)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
assembly = base.Resolve(assemblyNameReference);
|
||||
return true;
|
||||
}
|
||||
catch (AssemblyResolutionException) {
|
||||
catch (AssemblyResolutionException)
|
||||
{
|
||||
assembly = null;
|
||||
return false;
|
||||
}
|
||||
|
@ -39,7 +41,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static bool IsMscorlib(AssemblyNameReference name)
|
||||
{
|
||||
return name.Name == "mscorlib"
|
||||
return name.Name == "mscorlib"
|
||||
|| name.Name == "System.Runtime"
|
||||
|| name.Name == "netstandard";
|
||||
}
|
||||
|
|
|
@ -45,39 +45,47 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var skipassembly = !CompileByDefault;
|
||||
bool success = true;
|
||||
|
||||
if (!File.Exists(Assembly)) {
|
||||
if (!File.Exists(Assembly))
|
||||
{
|
||||
LoggingHelper.LogMessage(Normal, $"{new string(' ', 2)}Assembly file not found. Skipping XamlC.");
|
||||
return true;
|
||||
}
|
||||
|
||||
using (var fallbackResolver = DefaultAssemblyResolver == null ? new XamlCAssemblyResolver() : null) {
|
||||
using (var fallbackResolver = DefaultAssemblyResolver == null ? new XamlCAssemblyResolver() : null)
|
||||
{
|
||||
var resolver = DefaultAssemblyResolver ?? fallbackResolver;
|
||||
if (resolver is XamlCAssemblyResolver xamlCResolver) {
|
||||
if (ReferencePath != null) {
|
||||
var paths = ReferencePath.Select (p => IOPath.GetDirectoryName(p.Replace("//", "/"))).Distinct();
|
||||
foreach (var searchpath in paths) {
|
||||
if (resolver is XamlCAssemblyResolver xamlCResolver)
|
||||
{
|
||||
if (ReferencePath != null)
|
||||
{
|
||||
var paths = ReferencePath.Select(p => IOPath.GetDirectoryName(p.Replace("//", "/"))).Distinct();
|
||||
foreach (var searchpath in paths)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Adding searchpath {searchpath}");
|
||||
xamlCResolver.AddSearchDirectory(searchpath);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Ignoring dependency and reference paths due to an unsupported resolver");
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Ignoring dependency and reference paths due to an unsupported resolver");
|
||||
|
||||
var debug = DebugSymbols || (!string.IsNullOrEmpty(DebugType) && DebugType.ToLowerInvariant() != "none");
|
||||
|
||||
var readerParameters = new ReaderParameters {
|
||||
var readerParameters = new ReaderParameters
|
||||
{
|
||||
AssemblyResolver = resolver,
|
||||
ReadWrite = !ValidateOnly,
|
||||
ReadSymbols = debug && !ValidateOnly, // We don't need symbols for ValidateOnly, since we won't be writing
|
||||
};
|
||||
|
||||
using (var assemblyDefinition = AssemblyDefinition.ReadAssembly(IOPath.GetFullPath(Assembly),readerParameters)) {
|
||||
using (var assemblyDefinition = AssemblyDefinition.ReadAssembly(IOPath.GetFullPath(Assembly), readerParameters))
|
||||
{
|
||||
CustomAttribute xamlcAttr;
|
||||
if (assemblyDefinition.HasCustomAttributes &&
|
||||
(xamlcAttr =
|
||||
assemblyDefinition.CustomAttributes.FirstOrDefault(
|
||||
ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null) {
|
||||
ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null)
|
||||
{
|
||||
var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
|
||||
if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
|
||||
skipassembly = true;
|
||||
|
@ -85,12 +93,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
skipassembly = false;
|
||||
}
|
||||
|
||||
foreach (var module in assemblyDefinition.Modules) {
|
||||
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) {
|
||||
ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null)
|
||||
{
|
||||
var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
|
||||
if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
|
||||
skipmodule = true;
|
||||
|
@ -100,15 +110,18 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}Module: {module.Name}");
|
||||
var resourcesToPrune = new List<EmbeddedResource>();
|
||||
foreach (var resource in module.Resources.OfType<EmbeddedResource>()) {
|
||||
foreach (var resource in module.Resources.OfType<EmbeddedResource>())
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 4)}Resource: {resource.Name}");
|
||||
string classname;
|
||||
if (!resource.IsXaml(module, out classname)) {
|
||||
if (!resource.IsXaml(module, out classname))
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}skipped.");
|
||||
continue;
|
||||
}
|
||||
TypeDefinition typeDef = module.GetType(classname);
|
||||
if (typeDef == null) {
|
||||
if (typeDef == null)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}no type found... skipped.");
|
||||
continue;
|
||||
}
|
||||
|
@ -116,7 +129,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (typeDef.HasCustomAttributes &&
|
||||
(xamlcAttr =
|
||||
typeDef.CustomAttributes.FirstOrDefault(
|
||||
ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null) {
|
||||
ca => ca.AttributeType.FullName == "Xamarin.Forms.Xaml.XamlCompilationAttribute")) != null)
|
||||
{
|
||||
var options = (XamlCompilationOptions)xamlcAttr.ConstructorArguments[0].Value;
|
||||
if ((options & XamlCompilationOptions.Skip) == XamlCompilationOptions.Skip)
|
||||
skiptype = true;
|
||||
|
@ -127,13 +141,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
if (Type != null)
|
||||
skiptype = !(Type == classname);
|
||||
|
||||
if (skiptype && !ForceCompile) {
|
||||
if (skiptype && !ForceCompile)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}has XamlCompilationAttribute set to Skip and not Compile... skipped.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var initComp = typeDef.Methods.FirstOrDefault(md => md.Name == "InitializeComponent");
|
||||
if (initComp == null) {
|
||||
if (initComp == null)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}no InitializeComponent found... skipped.");
|
||||
continue;
|
||||
}
|
||||
|
@ -170,7 +186,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Parsing Xaml");
|
||||
var rootnode = ParseXaml(resource.GetResourceStream(), typeDef);
|
||||
if (rootnode == null) {
|
||||
if (rootnode == null)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
|
||||
continue;
|
||||
}
|
||||
|
@ -180,11 +197,12 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Replacing {0}.InitializeComponent ()");
|
||||
Exception e;
|
||||
if (!TryCoreCompile(initComp, initCompRuntime, rootnode, xamlFilePath, out e)) {
|
||||
if (!TryCoreCompile(initComp, initCompRuntime, rootnode, xamlFilePath, out e))
|
||||
{
|
||||
success = false;
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}failed.");
|
||||
(thrownExceptions = thrownExceptions ?? new List<Exception>()).Add(e);
|
||||
if (e is BuildException be)
|
||||
if (e is BuildException be)
|
||||
LoggingHelper.LogError("XamlC", be.Code.Code, be.HelpLink, xamlFilePath, be.XmlInfo?.LineNumber ?? 0, be.XmlInfo?.LinePosition ?? 0, 0, 0, ErrorMessages.ResourceManager.GetString(be.Code.ErrorMessageKey), be.MessageArgs);
|
||||
else if (e is XamlParseException xpe) //shouldn't happen anymore
|
||||
LoggingHelper.LogError("XamlC", null, xpe.HelpLink, xamlFilePath, xpe.XmlInfo.LineNumber, xpe.XmlInfo.LinePosition, 0, 0, xpe.Message);
|
||||
|
@ -196,14 +214,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
continue;
|
||||
}
|
||||
if (Type != null)
|
||||
InitCompForType = initComp;
|
||||
InitCompForType = initComp;
|
||||
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done.");
|
||||
|
||||
if (ValidateOnly)
|
||||
continue;
|
||||
|
||||
if (OptimizeIL) {
|
||||
if (OptimizeIL)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Optimizing IL");
|
||||
initComp.Body.Optimize();
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done.");
|
||||
|
@ -215,37 +234,46 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
#pragma warning restore 0618
|
||||
resourcesToPrune.Add(resource);
|
||||
}
|
||||
if (hasCompiledXamlResources) {
|
||||
if (hasCompiledXamlResources)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 4)}Changing the module MVID");
|
||||
module.Mvid = Guid.NewGuid();
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}done.");
|
||||
}
|
||||
if (!KeepXamlResources) {
|
||||
if (!KeepXamlResources)
|
||||
{
|
||||
if (resourcesToPrune.Any())
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 4)}Removing compiled xaml resources");
|
||||
foreach (var resource in resourcesToPrune) {
|
||||
foreach (var resource in resourcesToPrune)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 6)}Removing {resource.Name}");
|
||||
module.Resources.Remove(resource);
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 8)}done.");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ValidateOnly) {
|
||||
if (ValidateOnly)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 0)}ValidateOnly=True. Skipping writing assembly.");
|
||||
return success;
|
||||
}
|
||||
if (!hasCompiledXamlResources) {
|
||||
if (!hasCompiledXamlResources)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 0)}No compiled resources. Skipping writing assembly.");
|
||||
return success;
|
||||
}
|
||||
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 0)}Writing the assembly");
|
||||
try {
|
||||
assemblyDefinition.Write(new WriterParameters {
|
||||
try
|
||||
{
|
||||
assemblyDefinition.Write(new WriterParameters
|
||||
{
|
||||
WriteSymbols = debug,
|
||||
});
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}done.");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LoggingHelper.LogMessage(Low, $"{new string(' ', 2)}failed.");
|
||||
LoggingHelper.LogErrorFromException(e);
|
||||
(thrownExceptions = thrownExceptions ?? new List<Exception>()).Add(e);
|
||||
|
@ -259,7 +287,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
bool TryCoreCompile(MethodDefinition initComp, MethodDefinition initCompRuntime, ILRootNode rootnode, string xamlFilePath, out Exception exception)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
var body = new MethodBody(initComp);
|
||||
var module = body.Method.Module;
|
||||
body.InitLocals = true;
|
||||
|
@ -268,7 +297,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
il.Emit(Nop);
|
||||
|
||||
if (initCompRuntime != null) {
|
||||
if (initCompRuntime != null)
|
||||
{
|
||||
// Generating branching code for the Previewer
|
||||
|
||||
//First using the ResourceLoader
|
||||
|
@ -318,7 +348,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
il.Emit(Callvirt, module.ImportMethodReference(("mscorlib", "System", "Func`2"),
|
||||
methodName: "Invoke",
|
||||
paramCount: 1,
|
||||
classArguments: new[] { ("mscorlib", "System", "Type"), ("mscorlib", "System", "String")}));
|
||||
classArguments: new[] { ("mscorlib", "System", "Type"), ("mscorlib", "System", "String") }));
|
||||
il.Emit(Brfalse, nop);
|
||||
il.Emit(Ldarg_0);
|
||||
il.Emit(Call, initCompRuntime);
|
||||
|
@ -326,7 +356,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
il.Append(nop);
|
||||
}
|
||||
|
||||
var visitorContext = new ILContext(il, body, module) {
|
||||
var visitorContext = new ILContext(il, body, module)
|
||||
{
|
||||
DefineDebug = DebugSymbols || (!string.IsNullOrEmpty(DebugType) && DebugType.ToLowerInvariant() != "none"),
|
||||
XamlFilePath = xamlFilePath
|
||||
};
|
||||
|
@ -345,7 +376,9 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
initComp.Body = body;
|
||||
exception = null;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
exception = e;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
public string Language { get; set; }
|
||||
public string AssemblyName { get; set; }
|
||||
public string References { get; set; }
|
||||
public string References { get; set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
|
@ -25,37 +25,44 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
Log.LogMessage(MessageImportance.Normal, "Generating code behind for XAML files");
|
||||
|
||||
//NOTE: should not happen due to [Required], but there appears to be a place this is class is called directly
|
||||
if (XamlFiles == null || OutputFiles == null) {
|
||||
if (XamlFiles == null || OutputFiles == null)
|
||||
{
|
||||
Log.LogMessage("Skipping XamlG");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (XamlFiles.Length != OutputFiles.Length) {
|
||||
if (XamlFiles.Length != OutputFiles.Length)
|
||||
{
|
||||
Log.LogError("\"{2}\" refers to {0} item(s), and \"{3}\" refers to {1} item(s). They must have the same number of items.", XamlFiles.Length, OutputFiles.Length, "XamlFiles", "OutputFiles");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < XamlFiles.Length; i++) {
|
||||
for (int i = 0; i < XamlFiles.Length; i++)
|
||||
{
|
||||
var xamlFile = XamlFiles[i];
|
||||
var outputFile = OutputFiles[i].ItemSpec;
|
||||
if (IOPath.DirectorySeparatorChar == '/' && outputFile.Contains(@"\"))
|
||||
outputFile = outputFile.Replace('\\','/');
|
||||
outputFile = outputFile.Replace('\\', '/');
|
||||
else if (IOPath.DirectorySeparatorChar == '\\' && outputFile.Contains(@"/"))
|
||||
outputFile = outputFile.Replace('/', '\\');
|
||||
|
||||
|
||||
var generator = new XamlGenerator(xamlFile, Language, AssemblyName, outputFile, References, Log);
|
||||
try {
|
||||
if (!generator.Execute()) {
|
||||
try
|
||||
{
|
||||
if (!generator.Execute())
|
||||
{
|
||||
//If Execute() fails, the file still needs to exist because it is added to the <Compile/> ItemGroup
|
||||
File.WriteAllText (outputFile, string.Empty);
|
||||
File.WriteAllText(outputFile, string.Empty);
|
||||
}
|
||||
}
|
||||
catch (XmlException xe) {
|
||||
catch (XmlException xe)
|
||||
{
|
||||
Log.LogError(null, null, null, xamlFile.ItemSpec, xe.LineNumber, xe.LinePosition, 0, 0, xe.Message, xe.HelpLink, xe.Source);
|
||||
Log.LogMessage(MessageImportance.Low, xe.StackTrace);
|
||||
success = false;
|
||||
}
|
||||
catch (Exception e) {
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.LogError(null, null, null, xamlFile.ItemSpec, 0, 0, 0, 0, e.Message, e.HelpLink, e.Source);
|
||||
Log.LogMessage(MessageImportance.Low, e.StackTrace);
|
||||
success = false;
|
||||
|
|
|
@ -3,14 +3,14 @@ using System.CodeDom;
|
|||
using System.CodeDom.Compiler;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Linq;
|
||||
using System.Xml;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
using Microsoft.CSharp;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Mono.Cecil;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using IOPath = System.IO.Path;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
|
@ -123,12 +123,14 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
nsmgr.AddNamespace("__f__", XamlParser.XFUri);
|
||||
|
||||
var root = xmlDoc.SelectSingleNode("/*", nsmgr);
|
||||
if (root == null) {
|
||||
if (root == null)
|
||||
{
|
||||
Logger?.LogMessage(MessageImportance.Low, " No root node found");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (XmlAttribute attr in root.Attributes) {
|
||||
foreach (XmlAttribute attr in root.Attributes)
|
||||
{
|
||||
if (attr.Name == "xmlns")
|
||||
nsmgr.AddNamespace("", attr.Value); //Add default xmlns
|
||||
if (attr.Prefix != "xmlns")
|
||||
|
@ -139,20 +141,23 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var rootClass = root.Attributes["Class", XamlParser.X2006Uri]
|
||||
?? root.Attributes["Class", XamlParser.X2009Uri];
|
||||
|
||||
if (rootClass != null) {
|
||||
if (rootClass != null)
|
||||
{
|
||||
string rootType, rootNs, rootAsm, targetPlatform;
|
||||
XmlnsHelper.ParseXmlns(rootClass.Value, out rootType, out rootNs, out rootAsm, out targetPlatform);
|
||||
RootType = rootType;
|
||||
RootClrNamespace = rootNs;
|
||||
}
|
||||
else if (hasXamlCompilationProcessingInstruction) {
|
||||
else if (hasXamlCompilationProcessingInstruction)
|
||||
{
|
||||
RootClrNamespace = "__XamlGeneratedCode__";
|
||||
RootType = $"__Type{Guid.NewGuid().ToString("N")}";
|
||||
GenerateDefaultCtor = true;
|
||||
AddXamlCompilationAttribute = true;
|
||||
HideFromIntellisense = true;
|
||||
}
|
||||
else { // rootClass == null && !hasXamlCompilationProcessingInstruction) {
|
||||
else
|
||||
{ // rootClass == null && !hasXamlCompilationProcessingInstruction) {
|
||||
XamlResourceIdOnly = true; //only generate the XamlResourceId assembly attribute
|
||||
return true;
|
||||
}
|
||||
|
@ -192,7 +197,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
var declNs = new CodeNamespace(RootClrNamespace);
|
||||
ccu.Namespaces.Add(declNs);
|
||||
|
||||
var declType = new CodeTypeDeclaration(RootType) {
|
||||
var declType = new CodeTypeDeclaration(RootType)
|
||||
{
|
||||
IsPartial = true,
|
||||
CustomAttributes = {
|
||||
new CodeAttributeDeclaration(new CodeTypeReference($"global::{typeof(XamlFilePathAttribute).FullName}"),
|
||||
|
@ -213,8 +219,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
declNs.Types.Add(declType);
|
||||
|
||||
//Create a default ctor calling InitializeComponent
|
||||
if (GenerateDefaultCtor) {
|
||||
var ctor = new CodeConstructor {
|
||||
if (GenerateDefaultCtor)
|
||||
{
|
||||
var ctor = new CodeConstructor
|
||||
{
|
||||
Attributes = MemberAttributes.Public,
|
||||
CustomAttributes = { GeneratedCodeAttrDecl },
|
||||
Statements = {
|
||||
|
@ -226,7 +234,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
|
||||
//Create InitializeComponent()
|
||||
var initcomp = new CodeMemberMethod {
|
||||
var initcomp = new CodeMemberMethod
|
||||
{
|
||||
Name = "InitializeComponent",
|
||||
CustomAttributes = { GeneratedCodeAttrDecl }
|
||||
};
|
||||
|
@ -238,7 +247,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
new CodeTypeReferenceExpression(new CodeTypeReference($"global::{typeof(Extensions).FullName}")),
|
||||
"LoadFromXaml", new CodeThisReferenceExpression(), new CodeTypeOfExpression(declType.Name)));
|
||||
|
||||
foreach (var namedField in NamedFields) {
|
||||
foreach (var namedField in NamedFields)
|
||||
{
|
||||
declType.Members.Add(namedField);
|
||||
|
||||
var find_invoke = new CodeMethodInvokeExpression(
|
||||
|
@ -269,7 +279,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
root.SelectNodes(
|
||||
"//*[@" + xPrefix + ":Name" +
|
||||
"][not(ancestor:: __f__:DataTemplate) and not(ancestor:: __f__:ControlTemplate) and not(ancestor:: __f__:Style) and not(ancestor:: __f__:VisualStateManager.VisualStateGroups)]", nsmgr);
|
||||
foreach (XmlNode node in names) {
|
||||
foreach (XmlNode node in names)
|
||||
{
|
||||
var name = GetAttributeValue(node, "Name", XamlParser.X2006Uri, XamlParser.X2009Uri);
|
||||
var typeArguments = GetAttributeValue(node, "TypeArguments", XamlParser.X2006Uri, XamlParser.X2009Uri);
|
||||
var fieldModifier = GetAttributeValue(node, "FieldModifier", XamlParser.X2006Uri, XamlParser.X2009Uri);
|
||||
|
@ -280,8 +291,10 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
: null);
|
||||
|
||||
var access = MemberAttributes.Private;
|
||||
if (fieldModifier != null) {
|
||||
switch (fieldModifier.ToLowerInvariant()) {
|
||||
if (fieldModifier != null)
|
||||
{
|
||||
switch (fieldModifier.ToLowerInvariant())
|
||||
{
|
||||
default:
|
||||
case "private":
|
||||
access = MemberAttributes.Private;
|
||||
|
@ -299,7 +312,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
}
|
||||
|
||||
yield return new CodeMemberField {
|
||||
yield return new CodeMemberField
|
||||
{
|
||||
Name = name,
|
||||
Type = GetType(xmlType, node.GetNamespaceOfPrefix),
|
||||
Attributes = access,
|
||||
|
@ -327,11 +341,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
CodeTypeReference returnType = null;
|
||||
var ns = GetClrNamespace(xmlType.NamespaceUri);
|
||||
if (ns == null) {
|
||||
if (ns == null)
|
||||
{
|
||||
// It's an external, non-built-in namespace URL.
|
||||
returnType = GetCustomNamespaceUrlType(xmlType);
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
var type = xmlType.Name;
|
||||
type = $"{ns}.{type}";
|
||||
|
||||
|
@ -354,8 +370,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
if (namespaceuri == XamlParser.X2009Uri)
|
||||
return "System";
|
||||
if (namespaceuri != XamlParser.X2006Uri &&
|
||||
!namespaceuri.StartsWith("clr-namespace", StringComparison.InvariantCulture) &&
|
||||
if (namespaceuri != XamlParser.X2006Uri &&
|
||||
!namespaceuri.StartsWith("clr-namespace", StringComparison.InvariantCulture) &&
|
||||
!namespaceuri.StartsWith("using:", StringComparison.InvariantCulture))
|
||||
return null;
|
||||
return XmlnsHelper.ParseNamespaceFromXmlns(namespaceuri);
|
||||
|
@ -369,14 +385,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
throw new ArgumentNullException(nameof(localName));
|
||||
if (namespaceURIs == null)
|
||||
throw new ArgumentNullException(nameof(namespaceURIs));
|
||||
foreach (var namespaceURI in namespaceURIs) {
|
||||
foreach (var namespaceURI in namespaceURIs)
|
||||
{
|
||||
var attr = node.Attributes[localName, namespaceURI];
|
||||
if (attr == null)
|
||||
continue;
|
||||
return attr.Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void GatherXmlnsDefinitionAttributes()
|
||||
{
|
||||
|
@ -388,20 +405,24 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
paths.Add(typeof(Label).Assembly.Location);
|
||||
paths.Add(typeof(Xamarin.Forms.Xaml.Extensions).Assembly.Location);
|
||||
|
||||
foreach (var path in paths) {
|
||||
foreach (var path in paths)
|
||||
{
|
||||
string asmName = IOPath.GetFileName(path);
|
||||
if (AssemblyIsSystem(asmName))
|
||||
// Skip the myriad "System." assemblies and others
|
||||
continue;
|
||||
continue;
|
||||
|
||||
using (var asmDef = AssemblyDefinition.ReadAssembly(path)) {
|
||||
foreach (var ca in asmDef.CustomAttributes) {
|
||||
if (ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName) {
|
||||
using (var asmDef = AssemblyDefinition.ReadAssembly(path))
|
||||
{
|
||||
foreach (var ca in asmDef.CustomAttributes)
|
||||
{
|
||||
if (ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName)
|
||||
{
|
||||
_xmlnsDefinitions.Add(ca.GetXmlnsDefinition(asmDef));
|
||||
_xmlnsModules[asmDef.FullName] = asmDef.MainModule;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -446,9 +467,11 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
}
|
||||
|
||||
void CleanupXmlnsAssemblyData()
|
||||
{
|
||||
if ( _xmlnsModules != null ) {
|
||||
foreach (var moduleDef in _xmlnsModules.Values) {
|
||||
{
|
||||
if (_xmlnsModules != null)
|
||||
{
|
||||
foreach (var moduleDef in _xmlnsModules.Values)
|
||||
{
|
||||
moduleDef.Dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,16 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
using Mono.Cecil;
|
||||
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Mono.Cecil.Cil;
|
||||
using Mono.Cecil.Pdb;
|
||||
using Mono.Cecil.Mdb;
|
||||
using System.ComponentModel;
|
||||
using Mono.Cecil.Pdb;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
{
|
||||
|
@ -50,12 +47,15 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
internal static ILRootNode ParseXaml(Stream stream, TypeReference typeReference)
|
||||
{
|
||||
ILRootNode rootnode = null;
|
||||
using (var reader = XmlReader.Create(stream)) {
|
||||
while (reader.Read()) {
|
||||
using (var reader = XmlReader.Create(stream))
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
//Skip until element
|
||||
if (reader.NodeType == XmlNodeType.Whitespace)
|
||||
continue;
|
||||
if (reader.NodeType != XmlNodeType.Element) {
|
||||
if (reader.NodeType != XmlNodeType.Element)
|
||||
{
|
||||
Debug.WriteLine("Unhandled node {0} {1} {2}", reader.NodeType, reader.Name, reader.Value);
|
||||
continue;
|
||||
}
|
||||
|
@ -81,7 +81,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
using (var reader = XmlReader.Create(resourceStream))
|
||||
{
|
||||
// Read to the first Element
|
||||
while (reader.Read() && reader.NodeType != XmlNodeType.Element) ;
|
||||
while (reader.Read() && reader.NodeType != XmlNodeType.Element)
|
||||
;
|
||||
|
||||
if (reader.NodeType != XmlNodeType.Element)
|
||||
return false;
|
||||
|
@ -94,7 +95,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
//no x:Class, but it might be a RD without x:Class and with <?xaml-comp compile="true" ?>
|
||||
//in that case, it has a XamlResourceIdAttribute
|
||||
var typeRef = GetTypeForResourceId(module, resource.Name);
|
||||
if (typeRef != null) {
|
||||
if (typeRef != null)
|
||||
{
|
||||
classname = typeRef.FullName;
|
||||
return true;
|
||||
}
|
||||
|
@ -105,7 +107,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
|
||||
static TypeReference GetTypeForResourceId(ModuleDefinition module, string resourceId)
|
||||
{
|
||||
foreach (var ca in module.GetCustomAttributes()) {
|
||||
foreach (var ca in module.GetCustomAttributes())
|
||||
{
|
||||
if (!TypeRefComparer.Default.Equals(ca.AttributeType, module.ImportReference(("Xamarin.Forms.Core", "Xamarin.Forms.Xaml", "XamlResourceIdAttribute"))))
|
||||
continue;
|
||||
if (ca.ConstructorArguments[0].Value as string != resourceId)
|
||||
|
|
|
@ -3,14 +3,14 @@ using System.Linq;
|
|||
using System.Xml;
|
||||
using Mono.Cecil;
|
||||
using Mono.Cecil.Rocks;
|
||||
using Xamarin.Forms.Xaml;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
namespace Xamarin.Forms.Build.Tasks
|
||||
{
|
||||
static class XmlTypeExtensions
|
||||
{
|
||||
static Dictionary<ModuleDefinition, IList<XmlnsDefinitionAttribute>> s_xmlnsDefinitions =
|
||||
static Dictionary<ModuleDefinition, IList<XmlnsDefinitionAttribute>> s_xmlnsDefinitions =
|
||||
new Dictionary<ModuleDefinition, IList<XmlnsDefinitionAttribute>>();
|
||||
static object _nsLock = new object();
|
||||
|
||||
|
@ -18,19 +18,25 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
{
|
||||
var xmlnsDefinitions = new List<XmlnsDefinitionAttribute>();
|
||||
|
||||
if (module.AssemblyReferences?.Count > 0) {
|
||||
if (module.AssemblyReferences?.Count > 0)
|
||||
{
|
||||
// Search for the attribute in the assemblies being
|
||||
// referenced.
|
||||
foreach (var asmRef in module.AssemblyReferences) {
|
||||
foreach (var asmRef in module.AssemblyReferences)
|
||||
{
|
||||
var asmDef = module.AssemblyResolver.Resolve(asmRef);
|
||||
foreach (var ca in asmDef.CustomAttributes) {
|
||||
if (ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName) {
|
||||
foreach (var ca in asmDef.CustomAttributes)
|
||||
{
|
||||
if (ca.AttributeType.FullName == typeof(XmlnsDefinitionAttribute).FullName)
|
||||
{
|
||||
var attr = GetXmlnsDefinition(ca, asmDef);
|
||||
xmlnsDefinitions.Add(attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// Use standard XF assemblies
|
||||
// (Should only happen in unit tests)
|
||||
var requiredAssemblies = new[] {
|
||||
|
@ -38,7 +44,8 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
typeof(View).Assembly,
|
||||
};
|
||||
foreach (var assembly in requiredAssemblies)
|
||||
foreach (XmlnsDefinitionAttribute attribute in assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false)) {
|
||||
foreach (XmlnsDefinitionAttribute attribute in assembly.GetCustomAttributes(typeof(XmlnsDefinitionAttribute), false))
|
||||
{
|
||||
attribute.AssemblyName = attribute.AssemblyName ?? assembly.FullName;
|
||||
xmlnsDefinitions.Add(attribute);
|
||||
}
|
||||
|
@ -55,10 +62,13 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
throw new BuildException(BuildExceptionCode.InvalidXaml, node as IXmlLineInfo, null, xmlType);
|
||||
|
||||
string prefix, name;
|
||||
if (split.Length == 2) {
|
||||
if (split.Length == 2)
|
||||
{
|
||||
prefix = split[0];
|
||||
name = split[1];
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
prefix = "";
|
||||
name = split[0];
|
||||
}
|
||||
|
@ -74,17 +84,19 @@ namespace Xamarin.Forms.Build.Tasks
|
|||
public static bool TryGetTypeReference(this XmlType xmlType, ModuleDefinition module, IXmlLineInfo xmlInfo, out TypeReference typeReference)
|
||||
{
|
||||
IList<XmlnsDefinitionAttribute> xmlnsDefinitions = null;
|
||||
lock (_nsLock) {
|
||||
lock (_nsLock)
|
||||
{
|
||||
if (!s_xmlnsDefinitions.TryGetValue(module, out xmlnsDefinitions))
|
||||
xmlnsDefinitions = GatherXmlnsDefinitionAttributes(module);
|
||||
}
|
||||
|
||||
var typeArguments = xmlType.TypeArguments;
|
||||
|
||||
TypeReference type = xmlType.GetTypeReference(xmlnsDefinitions, module.Assembly.Name.Name, (typeInfo) => {
|
||||
string typeName = typeInfo.TypeName.Replace('+', '/'); //Nested types
|
||||
return module.GetTypeDefinition((typeInfo.AssemblyName, typeInfo.ClrNamespace, typeName));
|
||||
},
|
||||
TypeReference type = xmlType.GetTypeReference(xmlnsDefinitions, module.Assembly.Name.Name, (typeInfo) =>
|
||||
{
|
||||
string typeName = typeInfo.TypeName.Replace('+', '/'); //Nested types
|
||||
return module.GetTypeDefinition((typeInfo.AssemblyName, typeInfo.ClrNamespace, typeName));
|
||||
},
|
||||
out IList<XamlLoader.FallbackTypeInfo> potentialTypes);
|
||||
|
||||
if (type != null && typeArguments != null && type.HasGenericParameters)
|
||||
|
|
|
@ -1,66 +1,66 @@
|
|||
using GLib;
|
||||
using System;
|
||||
using GLib;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.ControlGallery.GTK;
|
||||
using System;
|
||||
using Xamarin.Forms.Platform.GTK;
|
||||
using Xamarin.Forms.Platform.GTK.Renderers;
|
||||
using Xamarin.Forms.Controls;
|
||||
using Xamarin.Forms.Maps.GTK;
|
||||
using Xamarin.Forms.Platform.GTK;
|
||||
using Xamarin.Forms.Platform.GTK.Renderers;
|
||||
|
||||
[assembly: ExportRenderer(typeof(DisposePage), typeof(DisposePageRenderer))]
|
||||
[assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))]
|
||||
namespace Xamarin.Forms.ControlGallery.GTK
|
||||
{
|
||||
class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
ExceptionManager.UnhandledException += OnUnhandledException;
|
||||
class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
ExceptionManager.UnhandledException += OnUnhandledException;
|
||||
|
||||
GtkOpenGL.Init();
|
||||
GtkThemes.Init();
|
||||
Gtk.Application.Init();
|
||||
FormsMaps.Init(string.Empty);
|
||||
Forms.Init();
|
||||
var app = new App();
|
||||
var window = new FormsWindow();
|
||||
window.LoadApplication(app);
|
||||
window.SetApplicationTitle("Xamarin.Forms GTK# Backend");
|
||||
window.SetApplicationIcon("xamarinlogo.png");
|
||||
window.Show();
|
||||
Gtk.Application.Run();
|
||||
}
|
||||
GtkOpenGL.Init();
|
||||
GtkThemes.Init();
|
||||
Gtk.Application.Init();
|
||||
FormsMaps.Init(string.Empty);
|
||||
Forms.Init();
|
||||
var app = new App();
|
||||
var window = new FormsWindow();
|
||||
window.LoadApplication(app);
|
||||
window.SetApplicationTitle("Xamarin.Forms GTK# Backend");
|
||||
window.SetApplicationIcon("xamarinlogo.png");
|
||||
window.Show();
|
||||
Gtk.Application.Run();
|
||||
}
|
||||
|
||||
private static void OnUnhandledException(UnhandledExceptionArgs args)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Unhandled GTK# exception: {args.ExceptionObject}");
|
||||
}
|
||||
}
|
||||
private static void OnUnhandledException(UnhandledExceptionArgs args)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Unhandled GTK# exception: {args.ExceptionObject}");
|
||||
}
|
||||
}
|
||||
|
||||
public class DisposePageRenderer : PageRenderer
|
||||
{
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
((DisposePage)Element).SendRendererDisposed();
|
||||
}
|
||||
public class DisposePageRenderer : PageRenderer
|
||||
{
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
((DisposePage)Element).SendRendererDisposed();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
|
||||
public class DisposeLabelRenderer : LabelRenderer
|
||||
{
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
((DisposeLabel)Element).SendRendererDisposed();
|
||||
}
|
||||
public class DisposeLabelRenderer : LabelRenderer
|
||||
{
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
((DisposeLabel)Element).SendRendererDisposed();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms.ControlGallery.GTK
|
|||
|
||||
var renderer = Platform.GTK.Platform.CreateRenderer(element);
|
||||
|
||||
if (renderer == null
|
||||
if (renderer == null
|
||||
|| renderer.GetType().Name == "DefaultRenderer"
|
||||
)
|
||||
{
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Platform.Tizen;
|
||||
using Xamarin.Forms.Controls;
|
||||
using ElmSharp;
|
||||
using Tizen.Applications;
|
||||
using Tizen.NET.MaterialComponents;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Controls;
|
||||
using Xamarin.Forms.Platform.Tizen;
|
||||
|
||||
namespace Xamarin.Forms.ControlGallery.Tizen
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Controls;
|
||||
using Xamarin.Forms.ControlGallery.Tizen;
|
||||
using Xamarin.Forms.Controls;
|
||||
using Xamarin.Forms.Platform.Tizen;
|
||||
|
||||
[assembly: ExportRenderer(typeof(DisposeLabel), typeof(DisposeLabelRenderer))]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Controls;
|
||||
using Xamarin.Forms.ControlGallery.Tizen;
|
||||
using Xamarin.Forms.Controls;
|
||||
using Xamarin.Forms.Platform.Tizen;
|
||||
|
||||
[assembly: ExportRenderer(typeof(DisposePage), typeof(DisposePageRenderer))]
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms.ControlGallery.Tizen
|
|||
|
||||
var renderer = Platform.Tizen.Platform.GetOrCreateRenderer(element);
|
||||
|
||||
if (renderer == null
|
||||
if (renderer == null
|
||||
|| renderer.GetType().Name == "DefaultRenderer"
|
||||
)
|
||||
{
|
||||
|
|
|
@ -1,18 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Tizen.NET.Sdk/1.0.9">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>tizen40</TargetFramework>
|
||||
<TargetFrameworkIdentifier>Tizen</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Tizen.NET" Version="4.0.0">
|
||||
<ExcludeAssets>Runtime</ExcludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Tizen.NET.MaterialComponents" Version="0.9.9-pre1" />
|
||||
<PackageReference Include="Tizen.NET.Sdk" Version="1.0.1" />
|
||||
<PackageReference Include="Tizen.NET.MaterialComponents" Version="0.9.9-pre2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
namespace Xamarin.Forms.ControlGallery.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Logique d'interaction pour App.xaml
|
||||
/// </summary>
|
||||
public partial class App : System.Windows.Application
|
||||
/// <summary>
|
||||
/// Logique d'interaction pour App.xaml
|
||||
/// </summary>
|
||||
public partial class App : System.Windows.Application
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
namespace Xamarin.Forms.ControlGallery.WPF
|
||||
{
|
||||
/// <summary>
|
||||
/// Logique d'interaction pour MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : FormsApplicationPage
|
||||
/// <summary>
|
||||
/// Logique d'interaction pour MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class MainWindow : FormsApplicationPage
|
||||
{
|
||||
public MainWindow()
|
||||
{
|
||||
|
@ -13,6 +13,6 @@ namespace Xamarin.Forms.ControlGallery.WPF
|
|||
Xamarin.Forms.Forms.Init();
|
||||
FormsMaps.Init("");
|
||||
LoadApplication(new Controls.App());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ namespace Xamarin.Forms.ControlGallery.WPF
|
|||
|
||||
var renderer = Platform.WPF.Platform.GetOrCreateRenderer(element);
|
||||
|
||||
if (renderer == null
|
||||
if (renderer == null
|
||||
|| renderer.GetType().Name == "DefaultRenderer"
|
||||
)
|
||||
{
|
||||
|
|
|
@ -8,7 +8,7 @@ using WRect = System.Windows.Rect;
|
|||
[assembly: ExportRenderer(typeof(Issue6693Control), typeof(Issue6693ControlRenderer))]
|
||||
namespace Xamarin.Forms.ControlGallery.WPF.Renderers
|
||||
{
|
||||
public class Issue6693ControlRenderer:ViewRenderer<Issue6693Control,WIssue6693Control>
|
||||
public class Issue6693ControlRenderer : ViewRenderer<Issue6693Control, WIssue6693Control>
|
||||
{
|
||||
protected override void OnElementChanged(ElementChangedEventArgs<Issue6693Control> e)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ namespace Xamarin.Forms.ControlGallery.WPF.Renderers
|
|||
{
|
||||
public WIssue6693Control()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnRender(DrawingContext drawingContext)
|
||||
|
@ -44,7 +44,7 @@ namespace Xamarin.Forms.ControlGallery.WPF.Renderers
|
|||
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
base.OnPropertyChanged(e);
|
||||
if(e.Property.Name == WIssue6693Control.IsEnabledProperty.Name)
|
||||
if (e.Property.Name == WIssue6693Control.IsEnabledProperty.Name)
|
||||
{
|
||||
InvalidateVisual();
|
||||
}
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Input;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
|
|
@ -36,7 +36,8 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
var emptyLabel = new Label { HorizontalTextAlignment = TextAlignment.Center };
|
||||
|
||||
var customLabel = new HintLabel { HorizontalTextAlignment = TextAlignment.Center }; ;
|
||||
var customLabel = new HintLabel { HorizontalTextAlignment = TextAlignment.Center };
|
||||
;
|
||||
|
||||
Content = new StackLayout { Children = { label, emptyLabel, customLabel } };
|
||||
}
|
||||
|
|
|
@ -18,10 +18,12 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
var otherButton = new Button() { Text = "back" };
|
||||
otherButton.Clicked += (sender, args) => Navigation.PopModalAsync();
|
||||
|
||||
var page = new ContentPage {
|
||||
var page = new ContentPage
|
||||
{
|
||||
Title = "Page Two",
|
||||
Content =
|
||||
new StackLayout {
|
||||
new StackLayout
|
||||
{
|
||||
Children = {
|
||||
new Label {
|
||||
Text =
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
@ -7,7 +8,6 @@ using Xamarin.Forms.CustomAttributes;
|
|||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.PlatformConfiguration;
|
||||
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest.iOS;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.Internals;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
|
|
|
@ -13,8 +13,8 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
#if UITEST
|
||||
[Category(Core.UITests.UITestCategories.Bugzilla)]
|
||||
#endif
|
||||
[Preserve (AllMembers = true)]
|
||||
[Issue (IssueTracker.Bugzilla, 22229, "ToolbarItems not clearing", PlatformAffected.iOS | PlatformAffected.WinPhone, NavigationBehavior.PushAsync)]
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 22229, "ToolbarItems not clearing", PlatformAffected.iOS | PlatformAffected.WinPhone, NavigationBehavior.PushAsync)]
|
||||
public partial class Bugzilla22229 : TabbedPage
|
||||
{
|
||||
string _prefix;
|
||||
|
@ -22,16 +22,17 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
public Bugzilla22229()
|
||||
{
|
||||
InitializeComponent();
|
||||
switch (Device.RuntimePlatform) {
|
||||
case Device.iOS:
|
||||
_prefix = "Images/";
|
||||
break;
|
||||
case Device.Android:
|
||||
_prefix = "";
|
||||
break;
|
||||
case Device.UWP:
|
||||
_prefix = "Assets/";
|
||||
break;
|
||||
switch (Device.RuntimePlatform)
|
||||
{
|
||||
case Device.iOS:
|
||||
_prefix = "Images/";
|
||||
break;
|
||||
case Device.Android:
|
||||
_prefix = "";
|
||||
break;
|
||||
case Device.UWP:
|
||||
_prefix = "Assets/";
|
||||
break;
|
||||
}
|
||||
InitializeActionBar();
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
public partial class Bugzilla26032 : TestContentPage
|
||||
{
|
||||
#if APP
|
||||
public Bugzilla26032 ()
|
||||
public Bugzilla26032()
|
||||
{
|
||||
|
||||
InitializeComponent ();
|
||||
|
||||
InitializeComponent();
|
||||
var data = new[] { "1", "2", "3", "4", "5" };
|
||||
var dataContext = new[] { "1 Context", "2 Context", "3 Context", "4 Context", "5 Context" };
|
||||
List1.ItemsSource = data;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Maps;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Maps;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
|
@ -12,14 +10,14 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
#if UITEST
|
||||
[NUnit.Framework.Category(Core.UITests.UITestCategories.Bugzilla)]
|
||||
#endif
|
||||
[Preserve (AllMembers = true)]
|
||||
[Issue (IssueTracker.Bugzilla, 27318, "Labels overlapping", PlatformAffected.Android, NavigationBehavior.PushAsync)]
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 27318, "Labels overlapping", PlatformAffected.Android, NavigationBehavior.PushAsync)]
|
||||
public partial class Bugzilla27318 : ContentPage
|
||||
{
|
||||
public Bugzilla27318 ()
|
||||
public Bugzilla27318()
|
||||
{
|
||||
InitializeComponent ();
|
||||
listView.ItemsSource = new [] { "Foo", "Bar", "Baz" };
|
||||
InitializeComponent();
|
||||
listView.ItemsSource = new[] { "Foo", "Bar", "Baz" };
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -13,10 +13,10 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
#endif
|
||||
public partial class Bugzilla27417Xaml : ContentPage
|
||||
{
|
||||
public Bugzilla27417Xaml ()
|
||||
public Bugzilla27417Xaml()
|
||||
{
|
||||
#if APP
|
||||
InitializeComponent ();
|
||||
InitializeComponent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Text;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.Controls.Issues;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
public Bugzilla29107()
|
||||
{
|
||||
#if APP
|
||||
InitializeComponent ();
|
||||
InitializeComponent();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
@ -14,9 +13,9 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
#if UITEST
|
||||
[Category(Core.UITests.UITestCategories.Bugzilla)]
|
||||
#endif
|
||||
[Preserve (AllMembers = true)]
|
||||
[Issue (IssueTracker.Bugzilla, 29257, "CarouselPage.CurrentPage Does Not Work Properly When Used Inside a NavigationPage ")]
|
||||
public class Bugzilla29257 : TestContentPage
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 29257, "CarouselPage.CurrentPage Does Not Work Properly When Used Inside a NavigationPage ")]
|
||||
public class Bugzilla29257 : TestContentPage
|
||||
{
|
||||
List<string> _menuItems = new List<string> {
|
||||
"Page 1", "Page 2", "Page 3", "Page 4", "Page 5"
|
||||
|
@ -24,7 +23,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
ListView _menu;
|
||||
|
||||
protected override void Init ()
|
||||
protected override void Init()
|
||||
{
|
||||
_menu = new ListView { ItemsSource = _menuItems };
|
||||
|
||||
|
@ -39,25 +38,25 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
switch (selection)
|
||||
{
|
||||
case "Page 1":
|
||||
await Navigation.PushAsync(new TestPage(0));
|
||||
break;
|
||||
case "Page 1":
|
||||
await Navigation.PushAsync(new TestPage(0));
|
||||
break;
|
||||
|
||||
case "Page 2":
|
||||
await Navigation.PushAsync(new TestPage(1));
|
||||
break;
|
||||
case "Page 2":
|
||||
await Navigation.PushAsync(new TestPage(1));
|
||||
break;
|
||||
|
||||
case "Page 3":
|
||||
await Navigation.PushAsync(new TestPage(2));
|
||||
break;
|
||||
case "Page 3":
|
||||
await Navigation.PushAsync(new TestPage(2));
|
||||
break;
|
||||
|
||||
case "Page 4":
|
||||
await Navigation.PushAsync(new TestPage(3));
|
||||
break;
|
||||
case "Page 4":
|
||||
await Navigation.PushAsync(new TestPage(3));
|
||||
break;
|
||||
|
||||
case "Page 5":
|
||||
await Navigation.PushAsync(new TestPage(4));
|
||||
break;
|
||||
case "Page 5":
|
||||
await Navigation.PushAsync(new TestPage(4));
|
||||
break;
|
||||
}
|
||||
_menu.SelectedItem = null;
|
||||
}
|
||||
|
@ -66,11 +65,11 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
{
|
||||
public TestPage()
|
||||
{
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 1" , BackgroundColor = Color.Red} });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 2" , BackgroundColor = Color.Green} });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 3" , BackgroundColor = Color.Blue} });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 4" , BackgroundColor = Color.Pink} });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 5" , BackgroundColor = Color.Yellow } });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 1", BackgroundColor = Color.Red } });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 2", BackgroundColor = Color.Green } });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 3", BackgroundColor = Color.Blue } });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 4", BackgroundColor = Color.Pink } });
|
||||
Children.Add(new ContentPage { Content = new Label { Text = "This is page 5", BackgroundColor = Color.Yellow } });
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -13,76 +13,83 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
[Category(Core.UITests.UITestCategories.FlyoutPage)]
|
||||
[Category(Core.UITests.UITestCategories.Bugzilla)]
|
||||
#endif
|
||||
[Preserve (AllMembers = true)]
|
||||
[Issue (IssueTracker.Bugzilla, 30324, "Detail view of FlyoutPage does not get appearance events on Android when whole FlyoutPage disappears/reappears")]
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 30324, "Detail view of FlyoutPage does not get appearance events on Android when whole FlyoutPage disappears/reappears")]
|
||||
public class Bugzilla30324 : TestNavigationPage
|
||||
{
|
||||
Label _lbl;
|
||||
int _count;
|
||||
|
||||
protected override void Init ()
|
||||
protected override void Init()
|
||||
{
|
||||
FlyoutPage page = new FlyoutPage();
|
||||
page.Flyout = new Page () { Title = "Flyout", BackgroundColor = Color.Red };
|
||||
_lbl = new Label ();
|
||||
page.Flyout = new Page() { Title = "Flyout", BackgroundColor = Color.Red };
|
||||
_lbl = new Label();
|
||||
|
||||
var otherPage = new ContentPage () {
|
||||
var otherPage = new ContentPage()
|
||||
{
|
||||
Title = "Other",
|
||||
Content = new StackLayout { Children = {
|
||||
Content = new StackLayout
|
||||
{
|
||||
Children = {
|
||||
new Button () {
|
||||
Text = "navigate back",
|
||||
HorizontalOptions = LayoutOptions.Center,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
|
||||
Command = new Command (() => Navigation.PopAsync())
|
||||
Command = new Command (() => Navigation.PopAsync())
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
page.Detail = new ContentPage () {
|
||||
page.Detail = new ContentPage()
|
||||
{
|
||||
Title = "Detail",
|
||||
Content = new StackLayout { Children = {
|
||||
Content = new StackLayout
|
||||
{
|
||||
Children = {
|
||||
_lbl,
|
||||
new Button () {
|
||||
Text = "navigate",
|
||||
HorizontalOptions = LayoutOptions.Center,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
|
||||
Command = new Command (() => Navigation.PushAsync (otherPage))
|
||||
Command = new Command (() => Navigation.PushAsync (otherPage))
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
page.Appearing += (sender, e) =>
|
||||
page.Appearing += (sender, e) =>
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Appear MDP");
|
||||
};
|
||||
page.Disappearing += (sender, e) =>
|
||||
page.Disappearing += (sender, e) =>
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Disappear MDP");
|
||||
};
|
||||
page.Detail.Appearing += (sender, args) =>
|
||||
{
|
||||
if(_count ==2)
|
||||
if (_count == 2)
|
||||
_lbl.Text = "Appear detail";
|
||||
System.Diagnostics.Debug.WriteLine("Appear detail");
|
||||
};
|
||||
page.Detail.Disappearing += (sender, args) => {
|
||||
System.Diagnostics.Debug.WriteLine ("Disappear detail");
|
||||
page.Detail.Disappearing += (sender, args) =>
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Disappear detail");
|
||||
_lbl.Text = "Disappear detail";
|
||||
page.Detail.BackgroundColor = Color.Green;
|
||||
_count++;
|
||||
};
|
||||
page.Flyout.Appearing += (sender, e) =>
|
||||
page.Flyout.Appearing += (sender, e) =>
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine("Appear master");
|
||||
};
|
||||
Navigation.PushAsync (page);
|
||||
Navigation.PushAsync(page);
|
||||
}
|
||||
|
||||
#if UITEST
|
||||
#if UITEST
|
||||
[Test]
|
||||
public void Bugzilla30324Test ()
|
||||
{
|
||||
|
@ -93,7 +100,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
RunningApp.Tap (q => q.Marked ("navigate back"));
|
||||
RunningApp.WaitForElement (q => q.Marked ("Appear detail"));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.ObjectModel;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.ComponentModel;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Windows.Input;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
|
||||
using Xamarin.Forms;
|
||||
using System.ComponentModel;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
|
@ -13,35 +11,39 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
#if UITEST
|
||||
[NUnit.Framework.Category(Core.UITests.UITestCategories.Bugzilla)]
|
||||
#endif
|
||||
[Preserve (AllMembers = true)]
|
||||
[Issue (IssueTracker.Bugzilla, 31967, "Grid Layout on Bound RowDefinition")]
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Bugzilla, 31967, "Grid Layout on Bound RowDefinition")]
|
||||
public partial class Bugzilla31967 : ContentPage
|
||||
{
|
||||
public Bugzilla31967 ()
|
||||
public Bugzilla31967()
|
||||
{
|
||||
InitializeComponent ();
|
||||
BindingContext = new Bugzilla31967Vm ();
|
||||
InitializeComponent();
|
||||
BindingContext = new Bugzilla31967Vm();
|
||||
}
|
||||
|
||||
public class Bugzilla31967Vm: INotifyPropertyChanged {
|
||||
public Command Fire {
|
||||
get { return new Command (() => ToolbarHeight = 50); }
|
||||
public class Bugzilla31967Vm : INotifyPropertyChanged
|
||||
{
|
||||
public Command Fire
|
||||
{
|
||||
get { return new Command(() => ToolbarHeight = 50); }
|
||||
}
|
||||
|
||||
GridLength _toolbarHeight;
|
||||
public GridLength ToolbarHeight {
|
||||
public GridLength ToolbarHeight
|
||||
{
|
||||
get { return _toolbarHeight; }
|
||||
set {
|
||||
set
|
||||
{
|
||||
_toolbarHeight = value;
|
||||
OnPropertyChanged ("ToolbarHeight");
|
||||
OnPropertyChanged("ToolbarHeight");
|
||||
}
|
||||
}
|
||||
|
||||
protected void OnPropertyChanged (string propertyName)
|
||||
protected void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
var handler = PropertyChanged;
|
||||
if (handler != null)
|
||||
handler (this, new PropertyChangedEventArgs (propertyName));
|
||||
handler(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
|
@ -84,14 +83,14 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
// If we want to filter the data, GetItems by expression
|
||||
IList<Contact1> contactEntities = new List<Contact1>();
|
||||
// If we want to filter the data, GetItems by expression
|
||||
IList<Contact1> contactEntities = new List<Contact1>();
|
||||
List<ContactViewModel1> data = new List<ContactViewModel1>();
|
||||
|
||||
if (contactEntities == null || contactEntities.Count == 0)
|
||||
{
|
||||
// Fill with dummy contacts
|
||||
for (int i = 0; i < 20; i++)
|
||||
// Fill with dummy contacts
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
Contact1 contact = new Contact1()
|
||||
{
|
||||
|
@ -103,8 +102,8 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
}
|
||||
}
|
||||
|
||||
// Create Contact items for the listView
|
||||
foreach (Contact1 contact in contactEntities)
|
||||
// Create Contact items for the listView
|
||||
foreach (Contact1 contact in contactEntities)
|
||||
{
|
||||
ContactViewModel1 contactItem = new ContactViewModel1()
|
||||
{
|
||||
|
@ -117,14 +116,14 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
data.Add(contactItem);
|
||||
}
|
||||
|
||||
// Sort, order and group the contacts
|
||||
var contacts = from contact in data
|
||||
// Sort, order and group the contacts
|
||||
var contacts = from contact in data
|
||||
orderby contact.LastName, contact.FirstName
|
||||
group contact by contact.FirstNameSort into contactGroup
|
||||
select new Grouping1<string, ContactViewModel1>(contactGroup.Key, contactGroup);
|
||||
|
||||
// Create a new collection of groups
|
||||
var grouppedContacts = new ObservableCollection<Grouping1<string, ContactViewModel1>>(contacts);
|
||||
// Create a new collection of groups
|
||||
var grouppedContacts = new ObservableCollection<Grouping1<string, ContactViewModel1>>(contacts);
|
||||
|
||||
_contactsListView.ItemsSource = grouppedContacts;
|
||||
});
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System.Threading;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
{
|
||||
#if APP
|
||||
|
||||
InitializeComponent ();
|
||||
InitializeComponent();
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using Xamarin.Forms.CustomAttributes;
|
||||
using System;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -14,13 +14,13 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
"[WinRT] ItemSelected Not Ignored When a ListView Item Contains a TapGestureRecognizer", PlatformAffected.WinRT)]
|
||||
public partial class Bugzilla32842 : ContentPage
|
||||
{
|
||||
public Bugzilla32842 ()
|
||||
public Bugzilla32842()
|
||||
{
|
||||
|
||||
|
||||
List<string> items = new List<string> { "item1", "item2", "item3" };
|
||||
|
||||
InitializeComponent ();
|
||||
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
MainList.ItemsSource = items;
|
||||
MainList.ItemSelected += MainListSelectionChanged;
|
||||
}
|
||||
|
@ -30,7 +30,8 @@ namespace Xamarin.Forms.Controls.Issues
|
|||
|
||||
void MainListSelectionChanged(object sender, SelectedItemChangedEventArgs e)
|
||||
{
|
||||
if (e.SelectedItem == null) {
|
||||
if (e.SelectedItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System.ComponentModel;
|
||||
|
||||
#if UITEST
|
||||
using NUnit.Framework;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
using System;
|
||||
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
|
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче