/
AttributeTableBuilder.cs
98 lines (82 loc) · 6.41 KB
/
AttributeTableBuilder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.ComponentModel;
using System.Windows.Markup;
using Microsoft.VisualStudio.DesignTools.Extensibility;
namespace Microsoft.Maui.Controls.Design
{
internal class AttributeTableBuilder : Microsoft.VisualStudio.DesignTools.Extensibility.Metadata.AttributeTableBuilder
{
public AttributeTableBuilder()
{
AddAssemblyCustomAttributes("Microsoft.Maui.Controls",
new XmlnsSupportsValidationAttribute("http://schemas.microsoft.com/dotnet/2021/maui", false));
AddAssemblyCustomAttributes("Microsoft.Maui.Graphics",
new XmlnsSupportsValidationAttribute("http://schemas.microsoft.com/dotnet/2021/maui", false));
// Style isn't a view, make it visible
AddTypeAttributes("Microsoft.Maui.Controls.Style",
new EditorBrowsableAttribute(EditorBrowsableState.Always),
new ContentPropertyAttribute("Setters"),
// Since the class doesn't have a public parameterless ctor, we need to provide a converter
new TypeConverterAttribute(typeof(StringConverter)));
// The Setter.Value can actually come from an <OnPlatform />, so enable it as Content.
AddTypeAttributes("Microsoft.Maui.Controls.Setter",
new EditorBrowsableAttribute(EditorBrowsableState.Always),
new ContentPropertyAttribute("Value"));
AddMemberAttributes("Microsoft.Maui.Controls.VisualElement", "Visual",
new TypeConverterAttribute(typeof(VisualDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.FlowDirection",
new TypeConverterAttribute(typeof(FlowDirectionDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.ItemsView", "ItemsLayout",
new TypeConverterAttribute(typeof(ItemsLayoutDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.InputView", "Keyboard",
new TypeConverterAttribute(typeof(KeyboardDesignTypeConverter)),
new TypeConverterAttribute(typeof(StringConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.EntryCell", "Keyboard",
new TypeConverterAttribute(typeof(KeyboardDesignTypeConverter)));
// TODO: OnPlatform/OnIdiom
// These two should be proper markup extensions, to follow WPF syntax for those.
// That would allow us to turn on XAML validation, which otherwise fails.
// NOTE: the two also need to provide a non-generic, object-based T so that
// the language service can find the type by its name. That class can be internal
// though, since its visibility in the markup is controlled by the EditorBrowsableAttribute.
// Make OnPlatform/OnIdiom visible for intellisense, and set as markup extension.
AddTypeAttributes("Microsoft.Maui.Controls.OnPlatform<>",
new EditorBrowsableAttribute (EditorBrowsableState.Always)
//new System.ComponentModel.TypeConverterAttribute(typeof(AnythingConverter)),
//new System.Windows.Markup.MarkupExtensionReturnTypeAttribute (),
);
AddTypeAttributes("Microsoft.Maui.Controls.OnIdiom<>",
new EditorBrowsableAttribute(EditorBrowsableState.Always)
//new System.ComponentModel.TypeConverterAttribute(typeof(AnythingConverter)),
//new System.Windows.Markup.MarkupExtensionReturnTypeAttribute (),
);
AddTypeAttributes("Microsoft.Maui.Graphics.Color", new TypeConverterAttribute(typeof(ColorDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Controls.ConstraintExpression", new MarkupExtensionReturnTypeAttribute());
AddTypeAttributes("Microsoft.Maui.Controls.LayoutOptions", new TypeConverterAttribute(typeof(LayoutOptionsDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Controls.LinearItemsLayout", new TypeConverterAttribute(typeof(LinearItemsLayoutDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Controls.ResourcesChangedEventArgs", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.Button", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.DatePicker", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.Editor", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.Entry", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.Label", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.Picker", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.SearchBar", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.TimePicker", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.RadioButton", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.SearchHandler", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddMemberAttributes("Microsoft.Maui.Controls.Span", "FontSize", new TypeConverterAttribute(typeof(FontSizeDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexJustify", new TypeConverterAttribute(typeof(FlexJustifyDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexDirection", new TypeConverterAttribute(typeof(FlexDirectionDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexAlignContent", new TypeConverterAttribute(typeof(FlexAlignContentDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexAlignItems", new TypeConverterAttribute(typeof(FlexAlignItemsDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexAlignSelf", new TypeConverterAttribute(typeof(FlexAlignSelfDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexWrap", new TypeConverterAttribute(typeof(FlexWrapDesignTypeConverter)));
AddTypeAttributes("Microsoft.Maui.Layouts.FlexBasis", new TypeConverterAttribute(typeof(FlexBasisDesignTypeConverter)));
}
private void AddTypeAttributes(string typeName, params Attribute[] attribs)
=> AddCallback(typeName, builder => builder.AddCustomAttributes(attribs));
private void AddMemberAttributes(string typeName, string memberName, params Attribute[] attribs)
=> AddCallback(typeName, builder => builder.AddCustomAttributes(memberName, attribs));
}
}