Exemple #1
0
        public object[] GetCustomAttributes(Type attributeType, bool inherit)
        {
            Attribute result = null;

            var ti = _type.GetTypeInfo();

            if (attributeType == typeof(pm.ContentPropertyAttribute))
            {
                result = GetContentPropertyAttribute(inherit);
            }
            else if (attributeType == typeof(pm.RuntimeNamePropertyAttribute))
            {
                if (_namedType.IsAssignableFrom(ti))
                {
                    result = new pm.RuntimeNamePropertyAttribute(nameof(INamed.Name));
                }
            }
            else if (attributeType == typeof(TypeConverterAttribute))
            {
                var builtin = AvaloniaTypeConverters.GetBuiltinTypeConverter(_type);
                if (builtin != null)
                {
                    result = new TypeConverterAttribute(builtin);
                }
                result = result ?? ti.GetCustomAttribute(attributeType, inherit);

                if (result == null)
                {
                    var convType = AvaloniaTypeConverters.GetTypeConverter(_type);

                    if (convType != null)
                    {
                        result = new TypeConverterAttribute(convType);
                    }
                }
            }
            else if (attributeType == typeof(pm.AmbientAttribute))
            {
                result = ti.GetCustomAttribute <avm.AmbientAttribute>(inherit)
                         .ToPortableXaml();
            }

            if (result == null)
            {
                var attr = ti.GetCustomAttributes(attributeType, inherit);
                return((attr as object[]) ?? attr.ToArray());
            }
            else
            {
                return(new object[] { result });
            }
        }
        public object[] GetCustomAttributes(Type attributeType, bool inherit)
        {
            Attribute result = null;

            if (attributeType == typeof(pm.XamlDeferLoadAttribute))
            {
                result = _info.GetCustomAttribute <avm.TemplateContentAttribute>(inherit)
                         .ToPortableXaml();
            }
            else if (attributeType == typeof(pm.AmbientAttribute))
            {
                result = _info.GetCustomAttribute <avm.AmbientAttribute>(inherit)
                         .ToPortableXaml();
            }
            else if (attributeType == typeof(pm.DependsOnAttribute))
            {
                result = _info.GetCustomAttribute <avm.DependsOnAttribute>(inherit)
                         .ToPortableXaml();
            }
            else if (attributeType == typeof(TypeConverterAttribute) &&
                     _info.DeclaringType == typeof(Setter) &&
                     _info.Name == nameof(Setter.Value))
            {
                //actually it never comes here looks like if property type is object
                //Portable.Xaml is not searching for Type Converter
                result = new TypeConverterAttribute(typeof(SetterValueTypeConverter));
            }
            else if (attributeType == typeof(TypeConverterAttribute) && _info is EventInfo)
            {
                // If a type converter for `EventInfo` is registered, then use that to convert
                // event handler values. This is used by the designer to override the lookup
                // for event handlers with a null handler.
                var eventConverter = AvaloniaTypeConverters.GetTypeConverter(typeof(EventInfo));

                if (eventConverter != null)
                {
                    result = new TypeConverterAttribute(eventConverter);
                }
            }

            if (result == null)
            {
                var attr = _info.GetCustomAttributes(attributeType, inherit);
                return((attr as object[]) ?? attr.ToArray());
            }
            else
            {
                return(new object[] { result });
            }
        }