3e0684456cbf4341f70e49667b78f178a23b9b94
[mono.git] / mcs / class / referencesource / System.Data.Entity / System / Data / Metadata / Edm / MetadataPropertyAttribute.cs
1 //---------------------------------------------------------------------
2 // <copyright file="MetadataPropertyAttribute.cs" company="Microsoft">
3 //      Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //
6 // @owner       Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
9
10 using System;
11 using System.Collections.Generic;
12 using System.Data.Common;
13 using System.Diagnostics;
14
15 namespace System.Data.Metadata.Edm
16 {
17     /// <summary>
18     /// Attribute used to mark up properties that should appear in the MetadataItem.MetadataProperties collection
19     /// </summary>
20     [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
21     internal sealed class MetadataPropertyAttribute : Attribute
22     {
23         /// <summary>
24         /// Initializes a new attribute with built in type kind
25         /// </summary>
26         /// <param name="builtInTypeKind">Built in type setting Type property</param>
27         /// <param name="isCollectionType">Sets IsCollectionType property</param>
28         internal MetadataPropertyAttribute(BuiltInTypeKind builtInTypeKind, bool isCollectionType)
29             : this(MetadataItem.GetBuiltInType(builtInTypeKind), isCollectionType)
30         {
31         }
32
33         /// <summary>
34         /// Initializes a new attribute with primitive type kind
35         /// </summary>
36         /// <param name="primitiveTypeKind">Primitive type setting Type property</param>
37         /// <param name="isCollectionType">Sets IsCollectionType property</param>
38         internal MetadataPropertyAttribute(PrimitiveTypeKind primitiveTypeKind, bool isCollectionType)
39             : this(MetadataItem.EdmProviderManifest.GetPrimitiveType(primitiveTypeKind), isCollectionType)
40         {
41         }
42
43         /// <summary>
44         /// Initialize a new attribute with complex type kind (corresponding the the CLR type)
45         /// </summary>
46         /// <param name="type">CLR type setting Type property</param>
47         /// <param name="isCollection">Sets IsCollectionType property</param>
48         internal MetadataPropertyAttribute(Type type, bool isCollection)
49             : this(ClrComplexType.CreateReadonlyClrComplexType(type, type.Namespace ?? string.Empty, type.Name), isCollection)
50         {
51         }
52
53         /// <summary>
54         /// Initialize a new attribute
55         /// </summary>
56         /// <param name="type">Sets Type property</param>
57         /// <param name="isCollectionType">Sets IsCollectionType property</param>
58         private MetadataPropertyAttribute(EdmType type, bool isCollectionType)
59         {
60             Debug.Assert(null != type);
61             _type = type;
62             _isCollectionType = isCollectionType;
63         }
64
65         private readonly EdmType _type;
66         private readonly bool _isCollectionType;
67
68         /// <summary>
69         /// Gets EDM type for values stored in property.
70         /// </summary>
71         internal EdmType Type { get { return _type; } }
72
73         /// <summary>
74         /// Gets bool indicating whether this is a collection type.
75         /// </summary>
76         internal bool IsCollectionType { get { return _isCollectionType; } }
77     }
78 }