[runtime] Fix corlib out of date error with disabled COM
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Metadata / AttributeCallbackBuilder.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4
5 namespace System.Activities.Presentation.Metadata 
6 {
7     using System.Runtime;
8
9     using System.Activities.Presentation.Internal.Metadata;
10     using System.Activities.Presentation.Internal.Properties;
11
12     using System;
13     using System.ComponentModel;
14     using System.Globalization;
15     using System.Reflection;
16     using System.Windows;
17     using System.Activities.Presentation;
18
19     // <summary>
20     // An instance of this class is passed to callback delegates to lazily
21     // populate the attributes for a type.
22     // </summary>
23     [Fx.Tag.XamlVisible(false)]
24     public sealed class AttributeCallbackBuilder 
25     {
26         private MutableAttributeTable _table;
27         private Type _callbackType;
28
29         internal AttributeCallbackBuilder(MutableAttributeTable table, Type callbackType) 
30         {
31             _table = table;
32             _callbackType = callbackType;
33         }
34
35         // <summary>
36         // The type this callback is being invoked for.
37         // </summary>
38         public Type CallbackType 
39         {
40             get { return _callbackType; }
41         }
42
43         // <summary>
44         // Adds the contents of the provided attributes to this builder.
45         // Conflicts are resolved with a last-in-wins strategy.
46         // </summary>
47         // <param name="attributes">
48         // The new attributes to add.
49         // </param>
50         // <exception cref="ArgumentNullException">if type or attributes is null</exception>
51         public void AddCustomAttributes(params Attribute[] attributes) {
52             if (attributes == null) 
53             {
54                 throw FxTrace.Exception.ArgumentNull("attributes");
55             }
56             _table.AddCustomAttributes(_callbackType, attributes);
57         }
58
59         // <summary>
60         // Adds the contents of the provided attributes to this builder.
61         // Conflicts are resolved with a last-in-wins strategy.
62         // </summary>
63         // <param name="descriptor">An event or property descriptor to add attributes to.</param>
64         // <param name="attributes">
65         // The new attributes to add.
66         // </param>
67         // <exception cref="ArgumentNullException">if descriptor or attributes is null</exception>
68         public void AddCustomAttributes(MemberDescriptor descriptor, params Attribute[] attributes) {
69             if (descriptor == null) 
70             {
71                 throw FxTrace.Exception.ArgumentNull("descriptor");
72             }
73             if (attributes == null) 
74             {
75                 throw FxTrace.Exception.ArgumentNull("attributes");
76             }
77             _table.AddCustomAttributes(_callbackType, descriptor, attributes);
78         }
79
80         // <summary>
81         // Adds the contents of the provided attributes to this builder.
82         // Conflicts are resolved with a last-in-wins strategy.
83         // </summary>
84         // <param name="member">An event or property info to add attributes to.</param>
85         // <param name="attributes">
86         // The new attributes to add.
87         // </param>
88         // <exception cref="ArgumentNullException">if member or attributes is null</exception>
89         public void AddCustomAttributes(MemberInfo member, params Attribute[] attributes) {
90             if (member == null) 
91             {
92                 throw FxTrace.Exception.ArgumentNull("member");
93             }
94             if (attributes == null) 
95             {
96                 throw FxTrace.Exception.ArgumentNull("attributes");
97             }
98             _table.AddCustomAttributes(_callbackType, member, attributes);
99         }
100
101         // <summary>
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.
105         // </summary>
106         // <param name="memberName">
107         // The member to add attributes for.  Only property and event members are supported;
108         // all others will be ignored.
109         // </param>
110         // <param name="attributes">
111         // The new attributes to add.
112         // </param>
113         public void AddCustomAttributes(string memberName, params Attribute[] attributes) {
114             if (memberName == null) 
115             {
116                 throw FxTrace.Exception.ArgumentNull("memberName");
117             }
118             if (attributes == null) 
119             {
120                 throw FxTrace.Exception.ArgumentNull("attributes");
121             }
122             _table.AddCustomAttributes(_callbackType, memberName, attributes);
123         }
124
125         // <summary>
126         // Adds the contents of the provided attributes to this builder.
127         // Conflicts are resolved with a last-in-wins strategy.
128         // </summary>
129         // <param name="dp">A dependency property to add attributes to.</param>
130         // <param name="attributes">
131         // The new attributes to add.
132         // </param>
133         // <exception cref="ArgumentNullException">if dp or attributes is null</exception>
134         public void AddCustomAttributes(DependencyProperty dp, params Attribute[] attributes) {
135             if (dp == null) 
136             {
137                 throw FxTrace.Exception.ArgumentNull("dp");
138             }
139             if (attributes == null) 
140             {
141                 throw FxTrace.Exception.ArgumentNull("attributes");
142             }
143             _table.AddCustomAttributes(_callbackType, dp, attributes);
144         }
145     }
146 }