Esempio n. 1
0
        public AvaloniaXamlIlAvaloniaListConstantAstNode(IXamlLineInfo lineInfo, AvaloniaXamlIlWellKnownTypes types, IXamlType listType, IXamlType elementType, IReadOnlyList <IXamlAstValueNode> values) : base(lineInfo)
        {
            _constructor           = listType.GetConstructor();
            _listAddMethod         = listType.GetMethod(new FindMethodMethodSignature("Add", types.XamlIlTypes.Void, elementType));
            _listSetCapacityMethod = listType.GetMethod(new FindMethodMethodSignature("set_Capacity", types.XamlIlTypes.Void, types.Int));

            _elementType = elementType;
            _values      = values;

            Type = new XamlAstClrTypeReference(lineInfo, listType, 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);
            }
        }