|
|
|
@ -2,8 +2,10 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Globalization; |
|
|
|
using System.Linq; |
|
|
|
using Avalonia.Controls; |
|
|
|
using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.AstNodes; |
|
|
|
using Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers; |
|
|
|
using Avalonia.Media; |
|
|
|
using XamlX; |
|
|
|
using XamlX.Ast; |
|
|
|
using XamlX.Emit; |
|
|
|
@ -205,67 +207,140 @@ namespace Avalonia.Markup.Xaml.XamlIl.CompilerExtensions |
|
|
|
result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (type.Equals(types.Thickness)) |
|
|
|
{ |
|
|
|
var thickness = Thickness.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor, |
|
|
|
new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom }); |
|
|
|
try |
|
|
|
{ |
|
|
|
var thickness = Thickness.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Thickness, types.ThicknessFullConstructor, |
|
|
|
new[] { thickness.Left, thickness.Top, thickness.Right, thickness.Bottom }); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.Point)) |
|
|
|
{ |
|
|
|
var point = Point.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor, |
|
|
|
new[] { point.X, point.Y }); |
|
|
|
try |
|
|
|
{ |
|
|
|
var point = Point.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor, |
|
|
|
new[] { point.X, point.Y }); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.Vector)) |
|
|
|
{ |
|
|
|
var vector = Vector.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor, |
|
|
|
new[] { vector.X, vector.Y }); |
|
|
|
try |
|
|
|
{ |
|
|
|
var vector = Vector.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor, |
|
|
|
new[] { vector.X, vector.Y }); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.Size)) |
|
|
|
{ |
|
|
|
var size = Size.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor, |
|
|
|
new[] { size.Width, size.Height }); |
|
|
|
try |
|
|
|
{ |
|
|
|
var size = Size.Parse(text); |
|
|
|
|
|
|
|
return true; |
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor, |
|
|
|
new[] { size.Width, size.Height }); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a size", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.Matrix)) |
|
|
|
{ |
|
|
|
var matrix = Matrix.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor, |
|
|
|
new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 }); |
|
|
|
try |
|
|
|
{ |
|
|
|
var matrix = Matrix.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Matrix, types.MatrixFullConstructor, |
|
|
|
new[] { matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32 }); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.CornerRadius)) |
|
|
|
{ |
|
|
|
var cornerRadius = CornerRadius.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor, |
|
|
|
new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft }); |
|
|
|
try |
|
|
|
{ |
|
|
|
var cornerRadius = CornerRadius.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.CornerRadius, types.CornerRadiusFullConstructor, |
|
|
|
new[] { cornerRadius.TopLeft, cornerRadius.TopRight, cornerRadius.BottomRight, cornerRadius.BottomLeft }); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a corner radius", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.Color)) |
|
|
|
{ |
|
|
|
if (!Color.TryParse(text, out Color color)) |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a color", node); |
|
|
|
} |
|
|
|
|
|
|
|
result = new XamlStaticOrTargetedReturnMethodCallNode(node, |
|
|
|
type.GetMethod( |
|
|
|
new FindMethodMethodSignature("FromUInt32", type, types.UInt) { IsStatic = true }), |
|
|
|
new[] { new XamlConstantNode(node, types.UInt, color.ToUint32()) }); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (type.Equals(types.GridLength)) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var gridLength = GridLength.Parse(text); |
|
|
|
|
|
|
|
result = new AvaloniaXamlIlGridLengthAstNode(node, types, gridLength); |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
catch |
|
|
|
{ |
|
|
|
throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a grid length", node); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (type.FullName == "Avalonia.AvaloniaProperty") |
|
|
|
{ |
|
|
|
var scope = context.ParentNodes().OfType<AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault(); |
|
|
|
|