Example #1
0
 public XamlValueWithManipulationNode(IXamlLineInfo lineInfo,
                                      IXamlAstValueNode value,
                                      IXamlAstManipulationNode manipulation) : base(lineInfo, value)
 {
     Value        = value;
     Manipulation = manipulation;
 }
Example #2
0
 public XamlLoadMethodDelegateNode(IXamlLineInfo lineInfo, IXamlAstValueNode value,
                                   IXamlType delegateType, IXamlMethod method) : base(lineInfo, value)
 {
     DelegateType = delegateType;
     Method       = method;
     Type         = new XamlAstClrTypeReference(value, DelegateType, false);
 }
        public static bool CustomValueConverter(AstTransformationContext context,
                                                IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text  = textNode.Text;
            var types = context.GetAvaloniaTypes();

            if (AvaloniaXamlIlLanguageParseIntrinsics.TryConvert(context, node, text, type, types, out result))
            {
                return(true);
            }

            if (type.FullName == "Avalonia.AvaloniaProperty")
            {
                var scope = context.ParentNodes().OfType <AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault();
                if (scope == null)
                {
                    throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node);
                }

                result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text, scope.TargetType, node);
                return(true);
            }

            result = null;
            return(false);
        }
Example #4
0
 public XamlMarkupExtensionNode(IXamlLineInfo lineInfo, IXamlMethod provideValue,
                                IXamlAstValueNode value) : base(lineInfo)
 {
     ProvideValue = provideValue;
     Value        = value;
     Type         = new XamlAstClrTypeReference(this, ProvideValue.ReturnType, false);
 }
 protected abstract void CompileBuild(
     IFileSource fileSource,
     IXamlAstValueNode rootInstance,
     Func <string, IXamlType, IXamlTypeBuilder <TBackendEmitter> > createSubType,
     TBackendEmitter codeGen,
     XamlRuntimeContext <TBackendEmitter, TEmitResult> context,
     IXamlMethod compiledPopulate);
Example #6
0
        public static bool CustomValueConverter(AstTransformationContext context,
                                                IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result)
        {
            if (type.FullName == "System.TimeSpan" &&
                node is XamlAstTextNode tn &&
                !tn.Text.Contains(":"))
            {
                var seconds = double.Parse(tn.Text, CultureInfo.InvariantCulture);
                result = new XamlStaticOrTargetedReturnMethodCallNode(tn,
                                                                      type.FindMethod("FromSeconds", type, false, context.Configuration.WellKnownTypes.Double),
                                                                      new[]
                {
                    new XamlConstantNode(tn, context.Configuration.WellKnownTypes.Double, seconds)
                });
                return(true);
            }

            if (type.FullName == "Avalonia.AvaloniaProperty")
            {
                var scope = context.ParentNodes().OfType <AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault();
                if (scope == null)
                {
                    throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node);
                }
                if (!(node is XamlAstTextNode text))
                {
                    throw new XamlX.XamlLoadException("Property should be a text node", node);
                }
                result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text.Text, scope.TargetType, text);
                return(true);
            }

            result = null;
            return(false);
        }
Example #7
0
 public XamlAstLocalInitializationNodeEmitter(IXamlLineInfo lineInfo,
                                              IXamlAstValueNode value,
                                              XamlAstCompilerLocalNode local) : base(lineInfo, value)
 {
     Value = value;
     Local = local;
 }
Example #8
0
        public static bool CustomValueConverter(AstTransformationContext context,
                                                IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text = textNode.Text;

            var types = context.GetAvaloniaTypes();

            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }


                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.FullName == "Avalonia.AvaloniaProperty")
            {
                var scope = context.ParentNodes().OfType <AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault();
                if (scope == null)
                {
                    throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node);
                }

                result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text, scope.TargetType, node);
                return(true);
            }

            result = null;
            return(false);
        }
Example #9
0
 public XamlAstXamlPropertyValueNode(IXamlLineInfo lineInfo,
                                     IXamlAstPropertyReference property, IXamlAstValueNode value) : base(lineInfo)
 {
     Property = property;
     Values   = new List <IXamlAstValueNode> {
         value
     };
 }
Example #10
0
 public XamlIlPropertyEqualsSelector(XamlIlSelectorNode previous,
                                     IXamlProperty property,
                                     IXamlAstValueNode value)
     : base(previous)
 {
     Property = property;
     Value    = value;
 }
 public XamlIlAttacchedPropertyEqualsSelector(XamlIlSelectorNode previous,
                                              IXamlField propertyFiled,
                                              IXamlAstValueNode value)
     : base(previous)
 {
     PropertyFiled = propertyFiled;
     Value         = value;
 }
            public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node)
            {
                if (node is XamlPropertyAssignmentNode pa)
                {
                    if (pa.Property.Name == "Name" &&
                        pa.Property.DeclaringType.FullName == "Robust.Client.UserInterface.Control")
                    {
                        if (context.ParentNodes().FirstOrDefault() is XamlManipulationGroupNode mg &&
                            mg.Children.OfType <RobustNameScopeRegistrationXamlIlNode>().Any())
                        {
                            return(node);
                        }

                        IXamlAstValueNode value = null;
                        for (var c = 0; c < pa.Values.Count; c++)
                        {
                            if (pa.Values[c].Type.GetClrType().Equals(context.Configuration.WellKnownTypes.String))
                            {
                                value = pa.Values[c];
                                if (!(value is XamlAstTextNode))
                                {
                                    var local = new XamlAstCompilerLocalNode(value);
                                    // Wrap original in local initialization
                                    pa.Values[c] = new XamlAstLocalInitializationNodeEmitter(value, value, local);
                                    // Use local
                                    value = local;
                                }

                                break;
                            }
                        }

                        if (value != null)
                        {
                            var objectType = context.ParentNodes().OfType <XamlAstConstructableObjectNode>().FirstOrDefault()?.Type.GetClrType();
                            return(new XamlManipulationGroupNode(pa)
                            {
                                Children =
                                {
                                    pa,
                                    new RobustNameScopeRegistrationXamlIlNode(value, objectType)
                                }
                            });
                        }
                    }

                    /*else if (pa.Property.CustomAttributes.Select(attr => attr.Type).Intersect(context.Configuration.TypeMappings.DeferredContentPropertyAttributes).Any())
                     * {
                     *  pa.Values[pa.Values.Count - 1] =
                     *      new NestedScopeMetadataNode(pa.Values[pa.Values.Count - 1]);
                     * }*/
                }

                return(node);
            }
Example #13
0
        public static bool TryGetCorrectlyTypedValue(AstTransformationContext context,
                                                     IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode rv)
        {
            if (type.IsAssignableFrom(node.Type.GetClrType()))
            {
                rv = node;
                return(true);
            }

            return(TryConvertValue(context, node, type, null, out rv));
        }
Example #14
0
        public XamlDeferredContentNode(IXamlAstValueNode value,
                                       IXamlType deferredContentCustomizationTypeParameter,
                                       TransformerConfiguration config) : base(value)
        {
            _deferredContentCustomizationTypeParameter = deferredContentCustomizationTypeParameter;
            Value = value;
            var funcType = config.TypeSystem.GetType("System.Func`2")
                           .MakeGenericType(config.TypeMappings.ServiceProvider, config.WellKnownTypes.Object);

            Type = new XamlAstClrTypeReference(value, funcType, false);
        }
        private static bool ConvertDefinitionList(
            IXamlAstValueNode node,
            string text,
            AvaloniaXamlIlWellKnownTypes types,
            IXamlType listType,
            IXamlType elementType,
            string errorDisplayName,
            out IXamlAstValueNode result)
        {
            try
            {
                var lengths = GridLength.ParseLengths(text);

                var definitionTypeRef = new XamlAstClrTypeReference(node, elementType, false);

                var definitionConstructorGridLength = elementType.GetConstructor(new List <IXamlType> {
                    types.GridLength
                });

                IXamlAstValueNode CreateDefinitionNode(GridLength length)
                {
                    var lengthNode = new AvaloniaXamlIlGridLengthAstNode(node, types, length);

                    return(new XamlAstNewClrObjectNode(node, definitionTypeRef,
                                                       definitionConstructorGridLength, new List <IXamlAstValueNode> {
                        lengthNode
                    }));
                }

                var definitionNodes =
                    new List <IXamlAstValueNode>(lengths.Select(CreateDefinitionNode));

                result = new AvaloniaXamlIlAvaloniaListConstantAstNode(node, types, listType, elementType, definitionNodes);

                return(true);
            }
            catch
            {
                throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a {errorDisplayName}", node);
            }
        }
Example #16
0
        public static bool TryConvertMarkupExtension(AstTransformationContext context,
                                                     IXamlAstValueNode node, out XamlMarkupExtensionNode o)
        {
            var cache = context.GetOrCreateItem <MarkupExtensionProvideValueCache>();

            o = null;
            var nodeType = node.Type.GetClrType();

            if (!cache.TypeToProvideValue.TryGetValue(nodeType, out var provideValue))
            {
                var candidates = GetMarkupExtensionProvideValueAlternatives(context, nodeType).ToList();
                var so         = context.Configuration.WellKnownTypes.Object;
                var sp         = context.Configuration.TypeMappings.ServiceProvider;

                // Try non-object variant first and variants without IServiceProvider argument first

                provideValue = candidates.FirstOrDefault(m => m.Parameters.Count == 0 && !m.ReturnType.Equals(so))
                               ?? candidates.FirstOrDefault(m => m.Parameters.Count == 0)
                               ?? candidates.FirstOrDefault(m =>
                                                            m.Parameters.Count == 1 && m.Parameters[0].Equals(sp) &&
                                                            !m.ReturnType.Equals(so))
                               ?? candidates.FirstOrDefault(m =>
                                                            m.Parameters.Count == 1 && m.Parameters[0].Equals(sp));
                cache.TypeToProvideValue[nodeType] = provideValue;
            }

            if (provideValue == null)
            {
                if (node.Type.IsMarkupExtension)
                {
                    throw new XamlParseException(
                              $"{node.Type.GetClrType().GetFqn()} was resolved as markup extension, but doesn't have a matching ProvideValue/ProvideTypedValue method",
                              node.Type);
                }

                return(false);
            }
            o = new XamlMarkupExtensionNode(node, provideValue, node);
            return(true);
        }
Example #17
0
        private static bool CustomValueConverter(
            AstTransformationContext context,
            IXamlAstValueNode node,
            IXamlType type,
            out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text  = textNode.Text;
            var types = context.GetRobustTypes();

            if (type.Equals(types.Vector2))
            {
                var foo = MathParsing.Single2.Parse(text);

                if (!foo.Success)
                {
                    throw new XamlLoadException($"Unable to parse \"{text}\" as a Vector2", node);
                }

                var(x, y) = foo.Value;

                result = new RXamlSingleVecLikeConstAstNode(
                    node,
                    types.Vector2, types.Vector2ConstructorFull,
                    types.Single, new[] { x, y });
                return(true);
            }

            result = null;
            return(false);
        }
        public static bool TryConvert(AstTransformationContext context, IXamlAstValueNode node, string text, IXamlType type, AvaloniaXamlIlWellKnownTypes types, out IXamlAstValueNode result)
        {
            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }

                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                result = new AvaloniaXamlIlFontFamilyAstNode(types, text, node);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                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);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a thickness", node);
                }
            }

            if (type.Equals(types.Point))
            {
                try
                {
                    var point = Point.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                         new[] { point.X, point.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a point", node);
                }
            }

            if (type.Equals(types.Vector))
            {
                try
                {
                    var vector = Vector.Parse(text);

                    result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                         new[] { vector.X, vector.Y });

                    return(true);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a vector", node);
                }
            }

            if (type.Equals(types.Size))
            {
                try
                {
                    var size = Size.Parse(text);

                    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))
            {
                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);
                }
                catch
                {
                    throw new XamlX.XamlLoadException($"Unable to parse \"{text}\" as a matrix", node);
                }
            }

            if (type.Equals(types.CornerRadius))
            {
                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.Equals(types.Cursor))
            {
                if (TypeSystemHelpers.TryGetEnumValueNode(types.StandardCursorType, text, node, out var enumConstantNode))
                {
                    var cursorTypeRef = new XamlAstClrTypeReference(node, types.Cursor, false);

                    result = new XamlAstNewClrObjectNode(node, cursorTypeRef, types.CursorTypeConstructor, new List <IXamlAstValueNode> {
                        enumConstantNode
                    });

                    return(true);
                }
            }

            if (type.Equals(types.ColumnDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.ColumnDefinitions, types.ColumnDefinition, "column definitions", out result));
            }

            if (type.Equals(types.RowDefinitions))
            {
                return(ConvertDefinitionList(node, text, types, types.RowDefinitions, types.RowDefinition, "row definitions", out result));
            }

            if (type.Equals(types.Classes))
            {
                var classes    = text.Split(' ');
                var classNodes = classes.Select(c => new XamlAstTextNode(node, c, types.XamlIlTypes.String)).ToArray();

                result = new AvaloniaXamlIlAvaloniaListConstantAstNode(node, types, types.Classes, types.XamlIlTypes.String, classNodes);
                return(true);
            }

            result = null;
            return(false);
        }
Example #19
0
        public static bool CustomValueConverter(AstTransformationContext context,
                                                IXamlAstValueNode node, IXamlType type, out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text = textNode.Text;

            var types = context.GetAvaloniaTypes();

            if (type.FullName == "System.TimeSpan")
            {
                var tsText = text.Trim();

                if (!TimeSpan.TryParse(tsText, CultureInfo.InvariantCulture, out var timeSpan))
                {
                    // // shorthand seconds format (ie. "0.25")
                    if (!tsText.Contains(":") && double.TryParse(tsText,
                                                                 NumberStyles.Float | NumberStyles.AllowThousands,
                                                                 CultureInfo.InvariantCulture, out var seconds))
                    {
                        timeSpan = TimeSpan.FromSeconds(seconds);
                    }
                    else
                    {
                        throw new XamlX.XamlLoadException($"Unable to parse {text} as a time span", node);
                    }
                }


                result = new XamlStaticOrTargetedReturnMethodCallNode(node,
                                                                      type.FindMethod("FromTicks", type, false, types.Long),
                                                                      new[] { new XamlConstantNode(node, types.Long, timeSpan.Ticks) });
                return(true);
            }

            if (type.Equals(types.FontFamily))
            {
                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 });

                return(true);
            }

            if (type.Equals(types.Point))
            {
                var point = Point.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Point, types.PointFullConstructor,
                                                                     new[] { point.X, point.Y });

                return(true);
            }

            if (type.Equals(types.Vector))
            {
                var vector = Vector.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Vector, types.VectorFullConstructor,
                                                                     new[] { vector.X, vector.Y });

                return(true);
            }

            if (type.Equals(types.Size))
            {
                var size = Size.Parse(text);

                result = new AvaloniaXamlIlVectorLikeConstantAstNode(node, types, types.Size, types.SizeFullConstructor,
                                                                     new[] { size.Width, size.Height });

                return(true);
            }

            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 });

                return(true);
            }

            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 });

                return(true);
            }

            if (type.FullName == "Avalonia.AvaloniaProperty")
            {
                var scope = context.ParentNodes().OfType <AvaloniaXamlIlTargetTypeMetadataNode>().FirstOrDefault();
                if (scope == null)
                {
                    throw new XamlX.XamlLoadException("Unable to find the parent scope for AvaloniaProperty lookup", node);
                }

                result = XamlIlAvaloniaPropertyHelper.CreateNode(context, text, scope.TargetType, node);
                return(true);
            }

            result = null;
            return(false);
        }
 public AvaloniaXamlIlUninferrableDataContextMetadataNode(IXamlAstValueNode value)
     : base(value, null)
 {
 }
 public AvaloniaXamlIlDataContextTypeMetadataNode(IXamlAstValueNode value, IXamlType targetType)
     : base(value, value)
 {
     DataContextType = targetType;
 }
Example #22
0
 public XamlToArrayNode(IXamlLineInfo lineInfo, IXamlAstTypeReference arrayType,
                        IXamlAstValueNode value) : base(lineInfo)
 {
     Type  = arrayType;
     Value = value;
 }
Example #23
0
 public override void VisitChildren(Visitor visitor)
 {
     Value = (IXamlAstValueNode)Value.Visit(visitor);
 }
Example #24
0
 protected XamlValueWithSideEffectNodeBase(IXamlLineInfo lineInfo, IXamlAstValueNode value) : base(lineInfo)
 {
     Value = value;
 }
Example #25
0
        private static bool CustomValueConverter(
            AstTransformationContext context,
            IXamlAstValueNode node,
            IXamlType type,
            out IXamlAstValueNode result)
        {
            if (!(node is XamlAstTextNode textNode))
            {
                result = null;
                return(false);
            }

            var text  = textNode.Text;
            var types = context.GetRobustTypes();

            if (type.Equals(types.Vector2))
            {
                var foo = MathParsing.Single2.Parse(text);

                if (!foo.Success)
                {
                    throw new XamlLoadException($"Unable to parse \"{text}\" as a Vector2", node);
                }

                var(x, y) = foo.Value;

                result = new RXamlSingleVecLikeConstAstNode(
                    node,
                    types.Vector2, types.Vector2ConstructorFull,
                    types.Single, new[] { x, y });
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                var foo = MathParsing.Thickness.Parse(text);

                if (!foo.Success)
                {
                    throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);
                }

                var     val = foo.Value;
                float[] full;
                if (val.Length == 1)
                {
                    var u = val[0];
                    full = new[] { u, u, u, u };
                }
                else if (val.Length == 2)
                {
                    var h = val[0];
                    var v = val[1];
                    full = new[] { h, v, h, v };
                }
                else // 4
                {
                    full = val;
                }

                result = new RXamlSingleVecLikeConstAstNode(
                    node,
                    types.Thickness, types.ThicknessConstructorFull,
                    types.Single, full);
                return(true);
            }

            if (type.Equals(types.Thickness))
            {
                var foo = MathParsing.Thickness.Parse(text);

                if (!foo.Success)
                {
                    throw new XamlLoadException($"Unable to parse \"{text}\" as a Thickness", node);
                }

                var     val = foo.Value;
                float[] full;
                if (val.Length == 1)
                {
                    var u = val[0];
                    full = new[] { u, u, u, u };
                }
                else if (val.Length == 2)
                {
                    var h = val[0];
                    var v = val[1];
                    full = new[] { h, v, h, v };
                }
                else // 4
                {
                    full = val;
                }

                result = new RXamlSingleVecLikeConstAstNode(
                    node,
                    types.Thickness, types.ThicknessConstructorFull,
                    types.Single, full);
                return(true);
            }

            if (type.Equals(types.Color))
            {
                // TODO: Interpret these colors at XAML compile time instead of at runtime.
                result = new RXamlColorAstNode(node, types, text);
                return(true);
            }

            result = null;
            return(false);
        }
 public RawSourceBindingExpressionNode(IXamlAstValueNode rawSource)
     : base(rawSource)
 {
     RawSource = rawSource;
 }
        public IXamlType EmitLoadIndexerAccessorFactory(XamlIlEmitContext context, IXamlILEmitter codeGen, IXamlAstValueNode value)
        {
            var intType = context.Configuration.TypeSystem.GetType("System.Int32");

            if (_indexerClosureType is null)
            {
                _indexerClosureType = InitializeClosureType(context);
            }

            context.Emit(value, codeGen, intType);
            codeGen.Newobj(_indexerClosureType.FindConstructor(new List <IXamlType> {
                intType
            }));
            EmitLoadPropertyAccessorFactory(context, codeGen, _indexerClosureType, IndexerClosureFactoryMethodName, isStatic: false);
            return(EmitCreateAccessorFactoryDelegate(context, codeGen));
        }
Example #28
0
 public XamlValueNodeWithBeginInit(IXamlAstValueNode value) : base(value, value)
 {
 }
 public override void VisitChildren(IXamlAstVisitor visitor)
 {
     RawSource = (IXamlAstValueNode)RawSource.Visit(visitor);
 }
 public RobustNameScopeRegistrationXamlIlNode(IXamlAstValueNode name, IXamlType targetType) : base(name)
 {
     TargetType = targetType;
     Name       = name;
 }