1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
5 namespace System.Activities.Presentation.Metadata
9 using System.Activities.Presentation.Internal.Metadata;
10 using System.Activities.Presentation.Internal.Properties;
13 using System.ComponentModel;
14 using System.Globalization;
15 using System.Reflection;
17 using System.Activities.Presentation;
20 // An instance of this class is passed to callback delegates to lazily
21 // populate the attributes for a type.
23 [Fx.Tag.XamlVisible(false)]
24 public sealed class AttributeCallbackBuilder
26 private MutableAttributeTable _table;
27 private Type _callbackType;
29 internal AttributeCallbackBuilder(MutableAttributeTable table, Type callbackType)
32 _callbackType = callbackType;
36 // The type this callback is being invoked for.
38 public Type CallbackType
40 get { return _callbackType; }
44 // Adds the contents of the provided attributes to this builder.
45 // Conflicts are resolved with a last-in-wins strategy.
47 // <param name="attributes">
48 // The new attributes to add.
50 // <exception cref="ArgumentNullException">if type or attributes is null</exception>
51 public void AddCustomAttributes(params Attribute[] attributes) {
52 if (attributes == null)
54 throw FxTrace.Exception.ArgumentNull("attributes");
56 _table.AddCustomAttributes(_callbackType, attributes);
60 // Adds the contents of the provided attributes to this builder.
61 // Conflicts are resolved with a last-in-wins strategy.
63 // <param name="descriptor">An event or property descriptor to add attributes to.</param>
64 // <param name="attributes">
65 // The new attributes to add.
67 // <exception cref="ArgumentNullException">if descriptor or attributes is null</exception>
68 public void AddCustomAttributes(MemberDescriptor descriptor, params Attribute[] attributes) {
69 if (descriptor == null)
71 throw FxTrace.Exception.ArgumentNull("descriptor");
73 if (attributes == null)
75 throw FxTrace.Exception.ArgumentNull("attributes");
77 _table.AddCustomAttributes(_callbackType, descriptor, attributes);
81 // Adds the contents of the provided attributes to this builder.
82 // Conflicts are resolved with a last-in-wins strategy.
84 // <param name="member">An event or property info to add attributes to.</param>
85 // <param name="attributes">
86 // The new attributes to add.
88 // <exception cref="ArgumentNullException">if member or attributes is null</exception>
89 public void AddCustomAttributes(MemberInfo member, params Attribute[] attributes) {
92 throw FxTrace.Exception.ArgumentNull("member");
94 if (attributes == null)
96 throw FxTrace.Exception.ArgumentNull("attributes");
98 _table.AddCustomAttributes(_callbackType, member, attributes);
102 // Adds attributes to the member with the given name. The member can be a property
103 // or an event. The member is evaluated on demand when the user queries
104 // attributes on a given property or event.
106 // <param name="memberName">
107 // The member to add attributes for. Only property and event members are supported;
108 // all others will be ignored.
110 // <param name="attributes">
111 // The new attributes to add.
113 public void AddCustomAttributes(string memberName, params Attribute[] attributes) {
114 if (memberName == null)
116 throw FxTrace.Exception.ArgumentNull("memberName");
118 if (attributes == null)
120 throw FxTrace.Exception.ArgumentNull("attributes");
122 _table.AddCustomAttributes(_callbackType, memberName, attributes);
126 // Adds the contents of the provided attributes to this builder.
127 // Conflicts are resolved with a last-in-wins strategy.
129 // <param name="dp">A dependency property to add attributes to.</param>
130 // <param name="attributes">
131 // The new attributes to add.
133 // <exception cref="ArgumentNullException">if dp or attributes is null</exception>
134 public void AddCustomAttributes(DependencyProperty dp, params Attribute[] attributes) {
137 throw FxTrace.Exception.ArgumentNull("dp");
139 if (attributes == null)
141 throw FxTrace.Exception.ArgumentNull("attributes");
143 _table.AddCustomAttributes(_callbackType, dp, attributes);