1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
//---------------------------------------------------------------------
// <copyright file="MetadataProperty.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//
// @owner Microsoft
// @backupOwner Microsoft
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Diagnostics;
using System.Reflection;
namespace System.Data.Metadata.Edm
{
/// <summary>
/// Class representing a metadata attribute for an item
/// </summary>
public sealed class MetadataProperty : MetadataItem
{
#region Constructors
/// <summary>
/// The constructor for MetadataProperty taking in a name, a TypeUsage object, and a value for the attribute
/// </summary>
/// <param name="name">The name of this MetadataProperty</param>
/// <param name="typeUsage">The TypeUsage describing the type of this MetadataProperty</param>
/// <param name="value">The value for this attribute</param>
/// <exception cref="System.ArgumentNullException">Thrown if typeUsage argument is null</exception>
internal MetadataProperty(string name, TypeUsage typeUsage, object value)
{
EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage");
_name = name;
_value = value;
_typeUsage = typeUsage;
_propertyKind = PropertyKind.Extended;
}
/// <summary>
/// The constructor for MetadataProperty taking in all the ingredients for creating TypeUsage and the actual value
/// </summary>
/// <param name="name">The name of the attribute</param>
/// <param name="edmType">The edm type of the attribute</param>
/// <param name="isCollectionType">Whether the collection type of the given edm type should be used</param>
/// <param name="value">The value of the attribute</param>
internal MetadataProperty(string name, EdmType edmType, bool isCollectionType, object value)
{
EntityUtil.CheckArgumentNull(edmType, "edmType");
_name = name;
_value = value;
if (isCollectionType)
{
_typeUsage = TypeUsage.Create(edmType.GetCollectionType());
}
else
{
_typeUsage = TypeUsage.Create(edmType);
}
_propertyKind = PropertyKind.System;
}
#endregion
#region Fields
private string _name;
private PropertyKind _propertyKind;
private object _value;
private TypeUsage _typeUsage;
#endregion
#region Properties
/// <summary>
/// Returns the kind of the type
/// </summary>
public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.MetadataProperty; } }
/// <summary>
/// Gets the identity of this item
/// </summary>
internal override string Identity
{
get
{
return Name;
}
}
/// <summary>
/// Gets/Sets the name of this MetadataProperty
/// </summary>
[MetadataProperty(PrimitiveTypeKind.String, false)]
public string Name
{
get
{
// The name is immutable, so it should be safe to always get it from the field
return _name;
}
}
/// <summary>
/// Gets/Sets the value of this MetadataProperty
/// </summary>
/// <exception cref="System.InvalidOperationException">Thrown if the MetadataProperty instance is in readonly state</exception>
[MetadataProperty(typeof(Object), false)]
public object Value
{
get
{
// Check if we're redirecting to an MetadataItem system property
MetadataPropertyValue redirectValue = _value as MetadataPropertyValue;
if (null != redirectValue)
{
return redirectValue.GetValue();
}
// If not, return the actual stored value
return _value;
}
}
/// <summary>
/// Gets/Sets the TypeUsage object describing the type of this attribute
/// </summary>
/// <exception cref="System.ArgumentNullException">Thrown if value passed into setter is null</exception>
/// <exception cref="System.InvalidOperationException">Thrown if the MetadataProperty instance is in readonly state</exception>
[MetadataProperty(BuiltInTypeKind.TypeUsage, false)]
public TypeUsage TypeUsage
{
get
{
return _typeUsage;
}
}
#endregion
#region Methods
/// <summary>
/// Sets this item to be readonly, once this is set, the item will never be writable again.
/// </summary>
internal override void SetReadOnly()
{
if (!IsReadOnly)
{
base.SetReadOnly();
// TypeUsage is always readonly, no need to set _typeUsage
}
}
/// <summary>
/// Returns the kind of the attribute
/// </summary>
public PropertyKind PropertyKind
{
get
{
return _propertyKind;
}
}
#endregion
}
}
|