コード例 #1
0
            public AvaloniaAttachedInstanceProperty(XamlAstNamePropertyReference prop,
                                                    TransformerConfiguration config,
                                                    IXamlType declaringType,
                                                    IXamlType type,
                                                    IXamlType avaloniaPropertyType,
                                                    IXamlType avaloniaObject,
                                                    IXamlField field) : base(prop, prop.Name,
                                                                             declaringType, null)


            {
                _config               = config;
                _declaringType        = declaringType;
                _avaloniaPropertyType = avaloniaPropertyType;

                // XamlIl doesn't support generic methods yet
                if (_avaloniaPropertyType.GenericArguments?.Count > 0)
                {
                    _avaloniaPropertyType = _avaloniaPropertyType.BaseType;
                }

                _avaloniaObject = avaloniaObject;
                _field          = field;
                PropertyType    = type;
                Setters.Add(new SetterMethod(this));
                Getter = new GetterMethod(this);
            }
コード例 #2
0
        public static IXamlIlAvaloniaPropertyNode CreateNode(AstTransformationContext context,
                                                             string propertyName, IXamlAstTypeReference selectorTypeReference, IXamlLineInfo lineInfo)
        {
            XamlAstNamePropertyReference forgedReference;

            var parser = new PropertyParser();

            var parsedPropertyName = parser.Parse(new CharacterReader(propertyName.AsSpan()));

            if (parsedPropertyName.owner == null)
            {
                forgedReference = new XamlAstNamePropertyReference(lineInfo, selectorTypeReference,
                                                                   propertyName, selectorTypeReference);
            }
            else
            {
                var xmlOwner = parsedPropertyName.ns;
                if (xmlOwner != null)
                {
                    xmlOwner += ":";
                }
                xmlOwner += parsedPropertyName.owner;

                var tref = TypeReferenceResolver.ResolveType(context, xmlOwner, false, lineInfo, true);

                var propertyFieldName = parsedPropertyName.name + "Property";
                var found             = tref.Type.GetAllFields()
                                        .FirstOrDefault(f => f.IsStatic && f.IsPublic && f.Name == propertyFieldName);
                if (found == null)
                {
                    throw new XamlX.XamlParseException(
                              $"Unable to find {propertyFieldName} field on type {tref.Type.GetFullName()}", lineInfo);
                }
                return(new XamlIlAvaloniaPropertyFieldNode(context.GetAvaloniaTypes(), lineInfo, found));
            }

            var clrProperty =
                ((XamlAstClrProperty) new PropertyReferenceResolver().Transform(context,
                                                                                forgedReference));

            return(new XamlIlAvaloniaPropertyNode(lineInfo,
                                                  context.Configuration.TypeSystem.GetType("Avalonia.AvaloniaProperty"),
                                                  clrProperty));
        }