[corlib] Update ValueTuple implementation
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Metadata / AttributeTable.cs
1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation.  All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Metadata 
5 {
6
7     using System.Activities.Presentation.Internal.Metadata;
8     using System;
9     using System.Collections;
10     using System.Collections.Generic;
11     using System.ComponentModel;
12     using System.Diagnostics;
13     using System.Reflection;
14     using System.Windows;
15     using System.Runtime;
16     using System.Activities.Presentation;
17
18     // <summary>
19     // Attribute tables are essentially read-only dictionaries, but the keys
20     // and values are computed separately.  It is very efficient to ask an
21     // attribute table if it contains attributes for a particular type.
22     // The actual set of attributes is demand created.
23     // </summary>
24     [Fx.Tag.XamlVisible(false)]
25     public sealed class AttributeTable 
26     {
27
28         private MutableAttributeTable _attributes;
29
30         //
31         // Creates a new attribute table given dictionary information
32         // from the attribute table builder.
33         //
34         internal AttributeTable(MutableAttributeTable attributes) 
35         {
36             Fx.Assert(attributes != null, "attributes parameter should not be null");
37             _attributes = attributes;
38         }
39
40         // <summary>
41         // Returns an enumeration of all types that have attribute overrides
42         // of some kind (on a property, on the type itself, etc).  This can be
43         // used to determine what types will be refreshed when this attribute
44         // table is added to the metadata store.
45         // </summary>
46         // <returns></returns>
47         public IEnumerable<Type> AttributedTypes 
48         {
49             get { return _attributes.AttributedTypes; }
50         }
51
52         //
53         // Returns our internal mutable table.  This is used
54         // by AttributeTableBuilder's AddTable method.
55         //
56         internal MutableAttributeTable MutableTable 
57         {
58             get { return _attributes; }
59         }
60
61         // <summary>
62         // Returns true if this table contains any metadata for the given type.
63         // The metadata may be class-level metadata or metadata associated with
64         // a DepenendencyProperty or MemberDescriptor.  The AttributeStore uses
65         // this method to identify loaded types that need a Refresh event raised
66         // when a new attribute table is added, and to quickly decide which
67         // tables should be further queried during attribute queries.
68         // </summary>
69         // <param name="type">The type to check.</param>
70         // <returns>true if the table contains attributes for the given type.</returns>
71         // <exception cref="ArgumentNullException">if type is null</exception>
72         public bool ContainsAttributes(Type type) 
73         {
74             if (type == null) 
75             {
76                 throw FxTrace.Exception.ArgumentNull("type");
77             }
78             return _attributes.ContainsAttributes(type);
79         }
80
81         // <summary>
82         // Returns an enumeration of all attributes provided for the
83         // given argument.  This will never return a null enumeration.
84         // </summary>
85         // <param name="type">The type to get class-level attributes for.</param>
86         // <returns>An enumeration of attributes.</returns>
87         // <exception cref="ArgumentNullException">if type is null</exception>
88         public IEnumerable GetCustomAttributes(Type type) 
89         {
90             if (type == null) 
91             {
92                 throw FxTrace.Exception.ArgumentNull("type");
93             }
94             return _attributes.GetCustomAttributes(type);
95         }
96
97         // <summary>
98         // Returns an enumeration of all attributes provided for the
99         // given argument.  This will never return a null enumeration.
100         // </summary>
101         // <param name="ownerType">The type that declares this descriptor.</param>
102         // <param name="descriptor">A member descriptor to get custom attributes for.</param>
103         // <returns>An enumeration of attributes.</returns>
104         // <exception cref="ArgumentNullException">if descriptor is null</exception>
105         public IEnumerable GetCustomAttributes(Type ownerType, MemberDescriptor descriptor) 
106         {
107             if (ownerType == null) 
108             {
109                 throw FxTrace.Exception.ArgumentNull("ownerType");
110             }
111             if (descriptor == null) 
112             {
113                 throw FxTrace.Exception.ArgumentNull("descriptor");
114             }
115             return _attributes.GetCustomAttributes(ownerType, descriptor);
116         }
117
118         // <summary>
119         // Returns an enumeration of all attributes provided for the
120         // given argument.  This will never return a null enumeration.
121         // </summary>
122         // <param name="ownerType">The owner type of the dependency property.</param>
123         // <param name="dp">A dependency property to get custom attributes for.</param>
124         // <returns>An enumeration of attributes.</returns>
125         // <exception cref="ArgumentNullException">if ownerType or dp is null</exception>
126         public IEnumerable GetCustomAttributes(Type ownerType, DependencyProperty dp) 
127         {
128             if (ownerType == null) 
129             {
130                 throw FxTrace.Exception.ArgumentNull("ownerType");
131             }
132             if (dp == null) 
133             {
134                 throw FxTrace.Exception.ArgumentNull("dp");
135             }
136             return _attributes.GetCustomAttributes(ownerType, dp);
137         }
138
139         // <summary>
140         // Returns an enumeration of all attributes provided for the
141         // given argument.  This will never return a null enumeration.
142         // </summary>
143         // <param name="ownerType">The owner type of the dependency property.</param>
144         // <param name="member">The member to provide attributes for.</param>
145         // <returns>An enumeration of attributes.</returns>
146         // <exception cref="ArgumentNullException">if ownerType or member is null</exception>
147         public IEnumerable GetCustomAttributes(Type ownerType, MemberInfo member) 
148         {
149             if (ownerType == null) 
150             {
151                 throw FxTrace.Exception.ArgumentNull("ownerType");
152             }
153             if (member == null) 
154             {
155                 throw FxTrace.Exception.ArgumentNull("member");
156             }
157             return _attributes.GetCustomAttributes(ownerType, member);
158         }
159
160         // <summary>
161         // Returns an enumeration of all attributes provided for the
162         // given argument.  This will never return a null enumeration.
163         // </summary>
164         // <param name="ownerType">The owner type of the dependency property.</param>
165         // <param name="memberName">The name of the member to provide attributes for.</param>
166         // <returns>An enumeration of attributes.</returns>
167         // <exception cref="ArgumentNullException">if ownerType or member is null</exception>
168         public IEnumerable GetCustomAttributes(Type ownerType, string memberName) 
169         {
170             if (ownerType == null) 
171             {
172                 throw FxTrace.Exception.ArgumentNull("ownerType");
173             }
174             if (memberName == null) 
175             {
176                 throw FxTrace.Exception.ArgumentNull("memberName");
177             }
178             return _attributes.GetCustomAttributes(ownerType, memberName);
179         }
180
181         //
182         // Called by the MetadataStore to walk through all the metadata and
183         // ensure that it can be found on the appropriate types and members.
184         // Any asserts that come from here are bugs in the type description
185         // provider.
186         //
187         internal void DebugValidateProvider()
188         {
189 #if DEBUG
190             _attributes.DebugValidateProvider();
191 #else
192 #endif
193         }
194     }
195 }