1 namespace System.Activities.Presentation.PropertyEditing
4 using System.Collections.Generic;
5 using System.Activities.Presentation.Internal;
6 using System.Activities.Presentation.Internal.Properties;
8 using System.Diagnostics.CodeAnalysis;
11 /// This attributes is used to specify which object Types can be assigned as the value of a given
12 /// property or as the value of a given property type. If the property represents a collection,
13 /// this attribute specifies the object Types of which instances can be created as the items
14 /// of that collection.
16 [Fx.Tag.XamlVisible(false)]
17 [AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true)]
18 sealed class NewItemTypesAttribute : Attribute
21 private Type _factoryType;
22 private Type[] _types;
25 /// Constructor for the attribute
27 /// <param name="type">Type that this attribute declares as being valid new item Type.</param>
28 /// <exception cref="ArgumentNullException">If type is null.</exception>
29 public NewItemTypesAttribute(Type type)
32 throw FxTrace.Exception.ArgumentNull("type");
34 _factoryType = typeof(NewItemFactory);
35 _types = new Type[] { type };
39 /// Constructor for the attribute
41 /// <param name="types">List of types that this attribute declares as being
42 /// valid new item Types.</param>
43 /// <exception cref="ArgumentNullException">If types is null or emtpy.</exception>
44 public NewItemTypesAttribute(params Type[] types)
46 if (types == null || types.Length < 1)
47 throw FxTrace.Exception.ArgumentNull("types");
49 _factoryType = typeof(NewItemFactory);
54 /// Gets a list of Types that this attribute declares as being valid new item Types.
55 /// Guaranteed to be non-null.
57 [SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods", Justification = "Suppress to avoid unnecessary change.")]
67 /// Gets a list of Types that this attribute declares as being valid new item Types.
68 /// Guaranteed to be non-null.
70 public IEnumerable<Type> Types
79 /// Gets or sets the factory Type associated with this attribute. The Type is
80 /// guaranteed to derive from NewItemFactory.
82 /// <exception cref="ArgumentException">If type does not derive from NewItemFactory</exception>
83 /// <exception cref="ArgumentNullException">If type is null.</exception>
84 public Type FactoryType
93 throw FxTrace.Exception.ArgumentNull("value");
94 if (!typeof(NewItemFactory).IsAssignableFrom(value))
95 throw FxTrace.Exception.AsError(new ArgumentException(Resources.Error_InvalidFactoryType));
102 /// Gets the TypeId for this attribute. Returns an equality array unique to this attribute
103 /// type and the contained factory type. The order in which the type attributes are passed
104 /// into the constructor of this class (if there are more than one) matters and is used in
105 /// determining the equality of two NewItemTypesAttribute instances.
107 public override object TypeId
111 object[] typeId = new object[_types.Length + 2];
112 for (int i = 0; i < _types.Length; i++)
114 typeId[i + 2] = _types[i];
116 typeId[0] = typeof(NewItemTypesAttribute);
117 typeId[1] = _factoryType;
118 return new EqualityArray(typeId);