1 //---------------------------------------------------------------------
2 // <copyright file="CollectionType.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
8 //---------------------------------------------------------------------
10 using System.Collections.Generic;
11 using System.Data.Common;
14 namespace System.Data.Metadata.Edm
17 /// Represents the Edm Collection Type
19 public sealed class CollectionType : EdmType
23 /// The constructor for constructing a CollectionType object with the element type it contains
25 /// <param name="elementType">The element type that this collection type contains</param>
26 /// <exception cref="System.ArgumentNullException">Thrown if the argument elementType is null</exception>
27 internal CollectionType(EdmType elementType)
28 : this(TypeUsage.Create(elementType))
30 this.DataSpace = elementType.DataSpace;
34 /// The constructor for constructing a CollectionType object with the element type (as a TypeUsage) it contains
36 /// <param name="elementType">The element type that this collection type contains</param>
37 /// <exception cref="System.ArgumentNullException">Thrown if the argument elementType is null</exception>
38 internal CollectionType(TypeUsage elementType)
39 : base(GetIdentity(EntityUtil.GenericCheckArgumentNull(elementType, "elementType")),
40 EdmConstants.TransientNamespace, elementType.EdmType.DataSpace)
42 _typeUsage = elementType;
48 private readonly TypeUsage _typeUsage;
53 /// Returns the kind of the type
55 public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.CollectionType; } }
58 /// The type of the element that this collection type contains
60 [MetadataProperty(BuiltInTypeKind.TypeUsage, false)]
61 public TypeUsage TypeUsage
72 /// Constructs the name of the collection type
74 /// <param name="typeUsage">The typeusage for the element type that this collection type refers to</param>
75 /// <returns>The identity of the resulting collection type</returns>
76 private static string GetIdentity(TypeUsage typeUsage)
78 StringBuilder builder = new StringBuilder(50);
79 builder.Append("collection[");
80 typeUsage.BuildIdentity(builder);
82 return builder.ToString();
86 /// Override EdmEquals to support value comparison of TypeUsage property
88 /// <param name="item"></param>
89 /// <returns></returns>
90 internal override bool EdmEquals(MetadataItem item)
92 // short-circuit if this and other are reference equivalent
93 if (Object.ReferenceEquals(this, item)) { return true; }
96 if (null == item || BuiltInTypeKind.CollectionType != item.BuiltInTypeKind) { return false; }
97 CollectionType other = (CollectionType)item;
100 return this.TypeUsage.EdmEquals(other.TypeUsage);