예제 #1
0
            public AvaloniaAttachedInstanceProperty(XamlIlAstNamePropertyReference prop,
                                                    XamlIlTransformerConfiguration config,
                                                    IXamlIlType declaringType,
                                                    IXamlIlType type,
                                                    IXamlIlType avaloniaPropertyType,
                                                    IXamlIlType avaloniaObject,
                                                    IXamlIlField 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(XamlIlAstTransformationContext context,
                                                             string propertyName, IXamlIlAstTypeReference selectorTypeReference, IXamlIlLineInfo lineInfo)
        {
            XamlIlAstNamePropertyReference forgedReference;

            var parser = new PropertyParser();

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

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

                var tref = XamlIlTypeReferenceResolver.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 XamlIlParseException(
                              $"Unable to find {propertyFieldName} field on type {tref.Type.GetFullName()}", lineInfo);
                }
                return(new XamlIlAvaloniaPropertyFieldNode(context.GetAvaloniaTypes(), lineInfo, found));
            }

            var clrProperty =
                ((XamlIlAstClrProperty) new XamlIlPropertyReferenceResolver().Transform(context,
                                                                                        forgedReference));

            return(new XamlIlAvaloniaPropertyNode(lineInfo,
                                                  context.Configuration.TypeSystem.GetType("Avalonia.AvaloniaProperty"),
                                                  clrProperty));
        }
예제 #3
0
        public static XamlIlAvaloniaPropertyNode CreateNode(XamlIlAstTransformationContext context,
                                                            string propertyName, IXamlIlAstTypeReference selectorTypeReference, IXamlIlLineInfo lineInfo)
        {
            XamlIlAstNamePropertyReference forgedReference;

            var parser = new PropertyParser();

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

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

                var tref = XamlIlTypeReferenceResolver.ResolveType(context, xmlOwner, false, lineInfo, true);
                forgedReference = new XamlIlAstNamePropertyReference(lineInfo,
                                                                     tref, parsedPropertyName.name, tref);
            }

            var clrProperty =
                ((XamlIlAstClrProperty) new XamlIlPropertyReferenceResolver().Transform(context,
                                                                                        forgedReference));

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