1 //----------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //----------------------------------------------------------------
4 namespace System.Activities.Presentation.Metadata
7 using System.Activities.Presentation.Internal.Metadata;
9 using System.Collections;
10 using System.Collections.Generic;
11 using System.ComponentModel;
12 using System.Diagnostics;
13 using System.Reflection;
16 using System.Activities.Presentation;
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.
24 [Fx.Tag.XamlVisible(false)]
25 public sealed class AttributeTable
28 private MutableAttributeTable _attributes;
31 // Creates a new attribute table given dictionary information
32 // from the attribute table builder.
34 internal AttributeTable(MutableAttributeTable attributes)
36 Fx.Assert(attributes != null, "attributes parameter should not be null");
37 _attributes = attributes;
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.
46 // <returns></returns>
47 public IEnumerable<Type> AttributedTypes
49 get { return _attributes.AttributedTypes; }
53 // Returns our internal mutable table. This is used
54 // by AttributeTableBuilder's AddTable method.
56 internal MutableAttributeTable MutableTable
58 get { return _attributes; }
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.
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)
76 throw FxTrace.Exception.ArgumentNull("type");
78 return _attributes.ContainsAttributes(type);
82 // Returns an enumeration of all attributes provided for the
83 // given argument. This will never return a null enumeration.
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)
92 throw FxTrace.Exception.ArgumentNull("type");
94 return _attributes.GetCustomAttributes(type);
98 // Returns an enumeration of all attributes provided for the
99 // given argument. This will never return a null enumeration.
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)
107 if (ownerType == null)
109 throw FxTrace.Exception.ArgumentNull("ownerType");
111 if (descriptor == null)
113 throw FxTrace.Exception.ArgumentNull("descriptor");
115 return _attributes.GetCustomAttributes(ownerType, descriptor);
119 // Returns an enumeration of all attributes provided for the
120 // given argument. This will never return a null enumeration.
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)
128 if (ownerType == null)
130 throw FxTrace.Exception.ArgumentNull("ownerType");
134 throw FxTrace.Exception.ArgumentNull("dp");
136 return _attributes.GetCustomAttributes(ownerType, dp);
140 // Returns an enumeration of all attributes provided for the
141 // given argument. This will never return a null enumeration.
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)
149 if (ownerType == null)
151 throw FxTrace.Exception.ArgumentNull("ownerType");
155 throw FxTrace.Exception.ArgumentNull("member");
157 return _attributes.GetCustomAttributes(ownerType, member);
161 // Returns an enumeration of all attributes provided for the
162 // given argument. This will never return a null enumeration.
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)
170 if (ownerType == null)
172 throw FxTrace.Exception.ArgumentNull("ownerType");
174 if (memberName == null)
176 throw FxTrace.Exception.ArgumentNull("memberName");
178 return _attributes.GetCustomAttributes(ownerType, memberName);
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
187 internal void DebugValidateProvider()
190 _attributes.DebugValidateProvider();