EdmProperty.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Metadata / Edm / EdmProperty.cs / 1305376 / EdmProperty.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner       [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Data.Common; 
using System.Threading;

namespace System.Data.Metadata.Edm
{ 
    /// 
    /// Represent the edm property class 
    ///  
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
    public sealed class EdmProperty : EdmMember 
    {
        #region Constructors
        /// 
        /// Initializes a new instance of the property class 
        /// 
        /// name of the property 
        /// TypeUsage object containing the property type and its facets 
        /// Thrown if name or typeUsage arguments are null
        /// Thrown if name argument is empty string 
        internal EdmProperty(string name, TypeUsage typeUsage)
            : base(name, typeUsage)
        {
            EntityUtil.CheckStringArgument(name, "name"); 
            EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage");
        } 
        #endregion 

        #region Fields 
        /// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd
        internal readonly System.RuntimeMethodHandle PropertyGetterHandle;

        /// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd 
        internal readonly System.RuntimeMethodHandle PropertySetterHandle;
 
        /// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd 
        internal readonly System.RuntimeTypeHandle EntityDeclaringType;
 
        /// cached dynamic method to get the property value from a CLR instance
        private Func _memberGetter;

        /// cached dynamic method to set a CLR property value on a CLR instance 
        private Action _memberSetter;
        #endregion 
 
        /// 
        /// Initializes a new OSpace instance of the property class 
        /// 
        /// name of the property
        /// TypeUsage object containing the property type and its facets
        /// for the property 
        /// The declaring type of the entity containing the property
        internal EdmProperty(string name, TypeUsage typeUsage, System.Reflection.PropertyInfo propertyInfo, RuntimeTypeHandle entityDeclaringType) 
            : this(name, typeUsage) 
        {
            System.Diagnostics.Debug.Assert(name == propertyInfo.Name, "different PropertyName"); 
            if (null != propertyInfo)
            {
                System.Reflection.MethodInfo method;
 
                method = propertyInfo.GetGetMethod(true); // return public or non-public getter
                PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle)); 
 
                method = propertyInfo.GetSetMethod(true); // return public or non-public getter
                PropertySetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle)); 

                EntityDeclaringType = entityDeclaringType;
            }
        } 

        ///  
        /// Returns the kind of the type 
        /// 
        public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EdmProperty; } } 

        /// 
        /// Returns true if this property is nullable
        ///  
        /// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
        public bool Nullable 
        { 
            get
            { 
                return (bool)TypeUsage.Facets[DbProviderManifest.NullableFacetName].Value;
            }
        }
 
        /// 
        /// Returns the default value for this property 
        ///  
        /// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
        public Object DefaultValue 
        {
            get
            {
                return TypeUsage.Facets[DbProviderManifest.DefaultValueFacetName].Value; 
            }
        } 
 
        /// cached dynamic method to get the property value from a CLR instance
        internal Func ValueGetter { 
            get { return _memberGetter; }
            set
            {
                System.Diagnostics.Debug.Assert(null != value, "clearing ValueGetter"); 
                // It doesn't matter which delegate wins, but only one should be jitted
                Interlocked.CompareExchange(ref _memberGetter, value, null); 
            } 
        }
 
        /// cached dynamic method to set a CLR property value on a CLR instance
        internal Action ValueSetter
        {
            get { return _memberSetter; } 
            set
            { 
                System.Diagnostics.Debug.Assert(null != value, "clearing ValueSetter"); 
                // It doesn't matter which delegate wins, but only one should be jitted
                Interlocked.CompareExchange(ref _memberSetter, value, null); 
            }
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner       [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Data.Common; 
using System.Threading;

namespace System.Data.Metadata.Edm
{ 
    /// 
    /// Represent the edm property class 
    ///  
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Edm")]
    public sealed class EdmProperty : EdmMember 
    {
        #region Constructors
        /// 
        /// Initializes a new instance of the property class 
        /// 
        /// name of the property 
        /// TypeUsage object containing the property type and its facets 
        /// Thrown if name or typeUsage arguments are null
        /// Thrown if name argument is empty string 
        internal EdmProperty(string name, TypeUsage typeUsage)
            : base(name, typeUsage)
        {
            EntityUtil.CheckStringArgument(name, "name"); 
            EntityUtil.GenericCheckArgumentNull(typeUsage, "typeUsage");
        } 
        #endregion 

        #region Fields 
        /// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd
        internal readonly System.RuntimeMethodHandle PropertyGetterHandle;

        /// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd 
        internal readonly System.RuntimeMethodHandle PropertySetterHandle;
 
        /// Store the handle, allowing the PropertyInfo/MethodInfo/Type references to be GC'd 
        internal readonly System.RuntimeTypeHandle EntityDeclaringType;
 
        /// cached dynamic method to get the property value from a CLR instance
        private Func _memberGetter;

        /// cached dynamic method to set a CLR property value on a CLR instance 
        private Action _memberSetter;
        #endregion 
 
        /// 
        /// Initializes a new OSpace instance of the property class 
        /// 
        /// name of the property
        /// TypeUsage object containing the property type and its facets
        /// for the property 
        /// The declaring type of the entity containing the property
        internal EdmProperty(string name, TypeUsage typeUsage, System.Reflection.PropertyInfo propertyInfo, RuntimeTypeHandle entityDeclaringType) 
            : this(name, typeUsage) 
        {
            System.Diagnostics.Debug.Assert(name == propertyInfo.Name, "different PropertyName"); 
            if (null != propertyInfo)
            {
                System.Reflection.MethodInfo method;
 
                method = propertyInfo.GetGetMethod(true); // return public or non-public getter
                PropertyGetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle)); 
 
                method = propertyInfo.GetSetMethod(true); // return public or non-public getter
                PropertySetterHandle = ((null != method) ? method.MethodHandle : default(System.RuntimeMethodHandle)); 

                EntityDeclaringType = entityDeclaringType;
            }
        } 

        ///  
        /// Returns the kind of the type 
        /// 
        public override BuiltInTypeKind BuiltInTypeKind { get { return BuiltInTypeKind.EdmProperty; } } 

        /// 
        /// Returns true if this property is nullable
        ///  
        /// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
        public bool Nullable 
        { 
            get
            { 
                return (bool)TypeUsage.Facets[DbProviderManifest.NullableFacetName].Value;
            }
        }
 
        /// 
        /// Returns the default value for this property 
        ///  
        /// Thrown if the setter is called when the EdmProperty instance is in ReadOnly state
        public Object DefaultValue 
        {
            get
            {
                return TypeUsage.Facets[DbProviderManifest.DefaultValueFacetName].Value; 
            }
        } 
 
        /// cached dynamic method to get the property value from a CLR instance
        internal Func ValueGetter { 
            get { return _memberGetter; }
            set
            {
                System.Diagnostics.Debug.Assert(null != value, "clearing ValueGetter"); 
                // It doesn't matter which delegate wins, but only one should be jitted
                Interlocked.CompareExchange(ref _memberGetter, value, null); 
            } 
        }
 
        /// cached dynamic method to set a CLR property value on a CLR instance
        internal Action ValueSetter
        {
            get { return _memberSetter; } 
            set
            { 
                System.Diagnostics.Debug.Assert(null != value, "clearing ValueSetter"); 
                // It doesn't matter which delegate wins, but only one should be jitted
                Interlocked.CompareExchange(ref _memberSetter, value, null); 
            }
        }
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.

                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK