ResourceProperty.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / ndp / fx / src / DataWeb / Server / System / Data / Services / Providers / ResourceProperty.cs / 2 / ResourceProperty.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//  
//      Provides a type to describe properties on resources.
//  
// 
// @owner  [....]
//--------------------------------------------------------------------- 

namespace System.Data.Services.Providers
{
    using System; 
    using System.Diagnostics;
    using System.Reflection; 
 
    /// Use this class to describe a property on a resource.
    [DebuggerDisplay("{kind}: {name}")] 
    internal class ResourceProperty
    {
        #region Private fields.
 
        /// A MethodInfo representing the get accessor for this property.
        private readonly MethodInfo getMethod; 
 
        /// Returns a PropertyInfo representing this property.
        private readonly PropertyInfo propertyInfo; 

        /// Returns a MethodInfo representing the set accessor for this property.
        private readonly MethodInfo setMethod;
 
        /// MIME type for the property, if it's a primitive value.
        private readonly string mimeType; 
 
        /// The name of this property.
        private readonly string name; 

        /// The resource container a resource property refers to, if applicable.
        private readonly ResourceContainer resourceContainer;
 
        /// The kind of resource Type that this property refers to.
        /// For e.g. for collection properties, this would return the resource type, 
        /// and not the collection type that this property refers to. 
        private readonly ResourceType resourcePropertyType;
 
#if ASTORIA_CONTAINMENT

        /// Property names of mapped keys in child (target) container.
        private string[] containmentChildKeys; 

        /// Property names of mapped keys in parent container. 
        private string[] containmentParentKeys; 

        /// Container of target (child) entities. 
        private ResourceContainer containmentTarget;

#endif
 
        /// The kind of property this is in relation to the resource.
        private ResourcePropertyKind kind; 
 
        #endregion Private fields.
 
#if ASTORIA_OPEN_OBJECT

        /// 
        /// Initializes a new ResourceProperty instance for an open property. 
        /// 
        /// Property name for the property. 
        /// Property kind. 
        /// The type of the resource that this property refers to
        internal ResourceProperty(string name, ResourcePropertyKind kind, ResourceType propertyResourceType) 
        {
            DebugIsValidPropertyKind(kind);
            Debug.Assert(name != null, "name cannot be null");
            Debug.Assert(propertyResourceType != null, "propertyResourceType != null"); 

            this.kind = kind; 
            this.name = name; 
            this.resourcePropertyType = propertyResourceType;
        } 

#endif

        ///  
        /// Initializes a new ResourceProperty instance based on the specified parameters.
        ///  
        /// Property info for the property. 
        /// Property kind.
        /// MIME type for the property, if it's a primitive value; null if none specified. 
        /// The type of the resource that this property refers to
        /// The resource container a resource property refers to, if applicable.
        internal ResourceProperty(PropertyInfo propertyInfo, ResourcePropertyKind kind, string mimeType, ResourceType propertyResourceType, ResourceContainer resourceContainer)
        { 
            DebugIsValidPropertyKind(kind);
            Debug.Assert(propertyInfo != null, "propertyInfo cannot be null"); 
            Debug.Assert(propertyResourceType != null, "propertyResourceType != null"); 
            Debug.Assert(
                kind == ResourcePropertyKind.ResourceSetReference || Nullable.GetUnderlyingType(propertyInfo.PropertyType) != null || propertyInfo.PropertyType == propertyResourceType.Type, 
                "Except reference and collection properties, the property type and resource property type must be identical");
            Debug.Assert(
                resourceContainer == null || kind == ResourcePropertyKind.ResourceReference || kind == ResourcePropertyKind.ResourceSetReference,
                "Only references can include a resource container."); 
            Debug.Assert(
                resourceContainer != null || (kind != ResourcePropertyKind.ResourceReference && kind != ResourcePropertyKind.ResourceSetReference), 
                "References must include their target resource container."); 

            if (mimeType != null && !WebUtil.IsValidMimeType(mimeType)) 
            {
                // 500 - Internal Server Error
                string message = Strings.ResourceProperty_MimeTypeNotValid(
                    mimeType, 
                    propertyInfo.Name,
                    propertyInfo.DeclaringType); 
                throw new InvalidOperationException(message); 
            }
 
            this.kind = kind;
            this.getMethod = propertyInfo.GetGetMethod();
            this.name = propertyInfo.Name;
            this.mimeType = mimeType; 
            this.resourcePropertyType = propertyResourceType;
            this.setMethod = propertyInfo.GetSetMethod(); 
            this.propertyInfo = propertyInfo; 
            this.resourceContainer = resourceContainer;
        } 

#if ASTORIA_CONTAINMENT

        /// Property names of mapped keys in child (target) container. 
        internal string[] ContainmentChildKeys
        { 
            [DebuggerStepThrough] 
            get { return this.containmentChildKeys; }
        } 

        /// Property names of mapped keys in parent container.
        internal string[] ContainmentParentKeys
        { 
            [DebuggerStepThrough]
            get { return this.containmentParentKeys; } 
        } 

        /// Container of target (child) entities. 
        internal ResourceContainer ContainmentTarget
        {
            [DebuggerStepThrough]
            get { return this.containmentTarget; } 
        }
 
        /// Whether this property is the canonical containment path for its target container. 
        /// 
        /// This property is only meaningful in the context of reflection services, as containment is defined 
        /// on a per-set basis and properties are defined on a per-type basis.
        /// 
        internal bool ContainmentTargetCanonical
        { 
            get
            { 
                return this.containmentTarget != null && this.containmentTarget.ContainmentCanonicalProperty == this; 
            }
        } 

#endif

        /// Gets a MethodInfo representing the get accessor for this property. 
        internal MethodInfo GetMethod
        { 
            get { return this.getMethod; } 
        }
 
        /// The kind of property this is in relation to the resource.
        internal ResourcePropertyKind Kind
        {
            [DebuggerStepThrough] 
            get { return this.kind; }
            [DebuggerStepThrough] 
            set { this.kind = value; } 
        }
 
        /// Returns a PropertyInfo representing this property.
        internal PropertyInfo PropertyInfo
        {
            [DebuggerStepThrough] 
            get { return this.propertyInfo; }
        } 
 
        /// Returns the  this property refers to, if applicable.
        ///  
        /// In MEST (multiple entity sets per type) scenarios, the specific
        /// resource container may vary depending on the container (entity set)
        /// of type that has holds this property.
        /// 
        /// In this case, the value of this property will be a representative
        /// container for security purposes, meaning that all associated 
        /// containers will have identical rights. 
        /// 
        internal ResourceContainer ResourceContainer 
        {
            [DebuggerStepThrough]
            get { return this.resourceContainer; }
        } 

        /// The kind of type this property has in relation to the data service. 
        internal ResourceTypeKind TypeKind 
        {
            get 
            {
                if (this.IsOfKind(ResourcePropertyKind.Primitive))
                {
                    return ResourceTypeKind.Primitive; 
                }
                else if (this.kind == ResourcePropertyKind.ResourceReference || 
                         this.kind == ResourcePropertyKind.ResourceSetReference) 
                {
                    return ResourceTypeKind.EntityType; 
                }
                else
                {
                    Debug.Assert(this.kind == ResourcePropertyKind.ComplexType, "this.kind == ResourcePropertyKind.ComplexType"); 
                    return ResourceTypeKind.ComplexType;
                } 
            } 
        }
 
        /// MIME type for the property, if it's a primitive value; null if none specified.
        internal string MimeType
        {
            [DebuggerStepThrough] 
            get { return this.mimeType; }
        } 
 
        /// The property name.
        internal string Name 
        {
            [DebuggerStepThrough]
            get { return this.name; }
        } 

        /// The type of the property. 
        internal Type Type 
        {
            get 
            {
                if (this.PropertyInfo != null)
                {
                    return this.PropertyInfo.PropertyType; 
                }
                else 
                { 
                    if (this.Kind == ResourcePropertyKind.ResourceSetReference)
                    { 
                        return typeof(System.Collections.Generic.IEnumerable<>).MakeGenericType(this.resourcePropertyType.Type);
                    }
                    else
                    { 
                        return this.resourcePropertyType.Type;
                    } 
                } 
            }
        } 

        /// 
        /// The clr type that is property refers to [For collection,
        /// this will return the element of the collection, and not the 
        /// collection].
        ///  
        internal Type ResourceClrType 
        {
            [DebuggerStepThrough] 
            get { return this.resourcePropertyType.Type; }
        }

        ///  
        /// The resource type that is property refers to [For collection,
        /// this will return the element of the collection, and not the 
        /// collection]. 
        /// 
        internal ResourceType ResourceType 
        {
            [DebuggerStepThrough]
            get { return this.resourcePropertyType; }
        } 

        /// Returns the value of the property. 
        /// The object whose property value will be returned. 
        /// The property value for the  parameter.
        internal object GetValue(object instance) 
        {
            Debug.Assert(instance != null, "instance != null");
            try
            { 
                return this.getMethod.Invoke(instance, null);
            } 
            catch (TargetInvocationException exception) 
            {
                ErrorHandler.HandleTargetInvocationException(exception); 
                throw;
            }
        }
 
        /// Sets the value of the property.
        /// The object whose property needs to be set. 
        /// new value for the property. 
        internal void SetValue(object instance, object propertyValue)
        { 
            Debug.Assert(instance != null, "instance != null");
            try
            {
                if (this.setMethod == null) 
                {
                    throw DataServiceException.CreateBadRequestError(Strings.BadRequest_PropertyValueCannotBeSet(this.Name)); 
                } 

                this.setMethod.Invoke(instance, new object[] { propertyValue }); 
            }
            catch (TargetInvocationException exception)
            {
                ErrorHandler.HandleTargetInvocationException(exception); 
                throw;
            } 
            catch (ArgumentException exception) 
            {
                throw DataServiceException.CreateBadRequestError(Strings.BadRequest_ErrorInSettingPropertyValue(this.Name), exception); 
            }
        }

        ///  
        /// return true if this property is of the given kind
        ///  
        /// flag which needs to be checked on the current property kind 
        /// true if the current property is of the given kind
        internal bool IsOfKind(ResourcePropertyKind checkKind) 
        {
            return ResourceProperty.IsOfKind(this.kind, checkKind);
        }
 
#if ASTORIA_CONTAINMENT
 
        ///  
        /// Sets all properties for the target in a containment relationship.
        ///  
        /// Property names of mapped keys in child (target) container.
        /// Property names of mapped keys in parent container.
        /// Container of target (child) entities.
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "containmentChildKeys", Justification = "1:1 mapping")] 
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "containmentParentKeys", Justification = "1:1 mapping")]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "containmentTarget", Justification = "1:1 mapping")] 
        internal void SetupContainmentTarget( 
            string[] containmentChildKeys,
            string[] containmentParentKeys, 
            ResourceContainer containmentTarget)
        {
            Debug.Assert(containmentChildKeys != null, "containmentChildKeys != null");
            Debug.Assert(containmentParentKeys != null, "containmentParentKeys != null"); 
            Debug.Assert(containmentTarget != null, "containmentTarget != null");
            Debug.Assert( 
                this.containmentChildKeys == null, 
                "this.containmentChildKeys == null -- otherwise the navigation property has more than one target");
            Debug.Assert( 
                this.IsOfKind(ResourcePropertyKind.ResourceSetReference),
                "this.IsOfKind(ResourcePropertyKind.ResourceSetReference) -- otherwise this cannot be a containment source.");

            this.containmentChildKeys = containmentChildKeys; 
            this.containmentParentKeys = containmentParentKeys;
            this.containmentTarget = containmentTarget; 
        } 

#endif 

        /// 
        /// return true if the given property kind is of the given kind
        ///  
        /// kind of the property
        /// flag which needs to be checked on property kind 
        /// true if the kind flag is set on the given property kind 
        private static bool IsOfKind(ResourcePropertyKind propertyKind, ResourcePropertyKind kind)
        { 
            return ((propertyKind & kind) == kind);
        }

        ///  
        /// Validates that the given property kind is valid
        ///  
        /// property kind is valid 
        [Conditional("DEBUG")]
        private static void DebugIsValidPropertyKind(ResourcePropertyKind propertyKind) 
        {
            if (ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.ResourceReference))
            {
                Debug.Assert( 
                    propertyKind == ResourcePropertyKind.ResourceReference || propertyKind == (ResourcePropertyKind.ResourceReference | ResourcePropertyKind.OpenProperty),
                    "reference property can't have any flags set"); 
            } 
            else if (ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.ResourceSetReference))
            { 
                Debug.Assert(
                    propertyKind == ResourcePropertyKind.ResourceSetReference || propertyKind == (ResourcePropertyKind.ResourceSetReference | ResourcePropertyKind.OpenProperty),
                    "setreference property can't have any flags set");
            } 
            else if (ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.ComplexType))
            { 
                Debug.Assert(propertyKind == ResourcePropertyKind.ComplexType, "complex property can't have any flags set"); 
            }
            else 
            {
                Debug.Assert(ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.Primitive), "property must be primitive");
                Debug.Assert(propertyKind != ResourcePropertyKind.Key, "property can't be alone set to key");
                ResourcePropertyKind all = ResourcePropertyKind.ComplexType | 
                    ResourcePropertyKind.Key |
                    ResourcePropertyKind.Primitive | 
                    ResourcePropertyKind.ResourceReference | 
                    ResourcePropertyKind.ResourceSetReference |
                    ResourcePropertyKind.OpenProperty; 

                Debug.Assert((propertyKind | all) == all, "no higher bits must be set on the propertyKind");
            }
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
//  
//      Provides a type to describe properties on resources.
//  
// 
// @owner  [....]
//--------------------------------------------------------------------- 

namespace System.Data.Services.Providers
{
    using System; 
    using System.Diagnostics;
    using System.Reflection; 
 
    /// Use this class to describe a property on a resource.
    [DebuggerDisplay("{kind}: {name}")] 
    internal class ResourceProperty
    {
        #region Private fields.
 
        /// A MethodInfo representing the get accessor for this property.
        private readonly MethodInfo getMethod; 
 
        /// Returns a PropertyInfo representing this property.
        private readonly PropertyInfo propertyInfo; 

        /// Returns a MethodInfo representing the set accessor for this property.
        private readonly MethodInfo setMethod;
 
        /// MIME type for the property, if it's a primitive value.
        private readonly string mimeType; 
 
        /// The name of this property.
        private readonly string name; 

        /// The resource container a resource property refers to, if applicable.
        private readonly ResourceContainer resourceContainer;
 
        /// The kind of resource Type that this property refers to.
        /// For e.g. for collection properties, this would return the resource type, 
        /// and not the collection type that this property refers to. 
        private readonly ResourceType resourcePropertyType;
 
#if ASTORIA_CONTAINMENT

        /// Property names of mapped keys in child (target) container.
        private string[] containmentChildKeys; 

        /// Property names of mapped keys in parent container. 
        private string[] containmentParentKeys; 

        /// Container of target (child) entities. 
        private ResourceContainer containmentTarget;

#endif
 
        /// The kind of property this is in relation to the resource.
        private ResourcePropertyKind kind; 
 
        #endregion Private fields.
 
#if ASTORIA_OPEN_OBJECT

        /// 
        /// Initializes a new ResourceProperty instance for an open property. 
        /// 
        /// Property name for the property. 
        /// Property kind. 
        /// The type of the resource that this property refers to
        internal ResourceProperty(string name, ResourcePropertyKind kind, ResourceType propertyResourceType) 
        {
            DebugIsValidPropertyKind(kind);
            Debug.Assert(name != null, "name cannot be null");
            Debug.Assert(propertyResourceType != null, "propertyResourceType != null"); 

            this.kind = kind; 
            this.name = name; 
            this.resourcePropertyType = propertyResourceType;
        } 

#endif

        ///  
        /// Initializes a new ResourceProperty instance based on the specified parameters.
        ///  
        /// Property info for the property. 
        /// Property kind.
        /// MIME type for the property, if it's a primitive value; null if none specified. 
        /// The type of the resource that this property refers to
        /// The resource container a resource property refers to, if applicable.
        internal ResourceProperty(PropertyInfo propertyInfo, ResourcePropertyKind kind, string mimeType, ResourceType propertyResourceType, ResourceContainer resourceContainer)
        { 
            DebugIsValidPropertyKind(kind);
            Debug.Assert(propertyInfo != null, "propertyInfo cannot be null"); 
            Debug.Assert(propertyResourceType != null, "propertyResourceType != null"); 
            Debug.Assert(
                kind == ResourcePropertyKind.ResourceSetReference || Nullable.GetUnderlyingType(propertyInfo.PropertyType) != null || propertyInfo.PropertyType == propertyResourceType.Type, 
                "Except reference and collection properties, the property type and resource property type must be identical");
            Debug.Assert(
                resourceContainer == null || kind == ResourcePropertyKind.ResourceReference || kind == ResourcePropertyKind.ResourceSetReference,
                "Only references can include a resource container."); 
            Debug.Assert(
                resourceContainer != null || (kind != ResourcePropertyKind.ResourceReference && kind != ResourcePropertyKind.ResourceSetReference), 
                "References must include their target resource container."); 

            if (mimeType != null && !WebUtil.IsValidMimeType(mimeType)) 
            {
                // 500 - Internal Server Error
                string message = Strings.ResourceProperty_MimeTypeNotValid(
                    mimeType, 
                    propertyInfo.Name,
                    propertyInfo.DeclaringType); 
                throw new InvalidOperationException(message); 
            }
 
            this.kind = kind;
            this.getMethod = propertyInfo.GetGetMethod();
            this.name = propertyInfo.Name;
            this.mimeType = mimeType; 
            this.resourcePropertyType = propertyResourceType;
            this.setMethod = propertyInfo.GetSetMethod(); 
            this.propertyInfo = propertyInfo; 
            this.resourceContainer = resourceContainer;
        } 

#if ASTORIA_CONTAINMENT

        /// Property names of mapped keys in child (target) container. 
        internal string[] ContainmentChildKeys
        { 
            [DebuggerStepThrough] 
            get { return this.containmentChildKeys; }
        } 

        /// Property names of mapped keys in parent container.
        internal string[] ContainmentParentKeys
        { 
            [DebuggerStepThrough]
            get { return this.containmentParentKeys; } 
        } 

        /// Container of target (child) entities. 
        internal ResourceContainer ContainmentTarget
        {
            [DebuggerStepThrough]
            get { return this.containmentTarget; } 
        }
 
        /// Whether this property is the canonical containment path for its target container. 
        /// 
        /// This property is only meaningful in the context of reflection services, as containment is defined 
        /// on a per-set basis and properties are defined on a per-type basis.
        /// 
        internal bool ContainmentTargetCanonical
        { 
            get
            { 
                return this.containmentTarget != null && this.containmentTarget.ContainmentCanonicalProperty == this; 
            }
        } 

#endif

        /// Gets a MethodInfo representing the get accessor for this property. 
        internal MethodInfo GetMethod
        { 
            get { return this.getMethod; } 
        }
 
        /// The kind of property this is in relation to the resource.
        internal ResourcePropertyKind Kind
        {
            [DebuggerStepThrough] 
            get { return this.kind; }
            [DebuggerStepThrough] 
            set { this.kind = value; } 
        }
 
        /// Returns a PropertyInfo representing this property.
        internal PropertyInfo PropertyInfo
        {
            [DebuggerStepThrough] 
            get { return this.propertyInfo; }
        } 
 
        /// Returns the  this property refers to, if applicable.
        ///  
        /// In MEST (multiple entity sets per type) scenarios, the specific
        /// resource container may vary depending on the container (entity set)
        /// of type that has holds this property.
        /// 
        /// In this case, the value of this property will be a representative
        /// container for security purposes, meaning that all associated 
        /// containers will have identical rights. 
        /// 
        internal ResourceContainer ResourceContainer 
        {
            [DebuggerStepThrough]
            get { return this.resourceContainer; }
        } 

        /// The kind of type this property has in relation to the data service. 
        internal ResourceTypeKind TypeKind 
        {
            get 
            {
                if (this.IsOfKind(ResourcePropertyKind.Primitive))
                {
                    return ResourceTypeKind.Primitive; 
                }
                else if (this.kind == ResourcePropertyKind.ResourceReference || 
                         this.kind == ResourcePropertyKind.ResourceSetReference) 
                {
                    return ResourceTypeKind.EntityType; 
                }
                else
                {
                    Debug.Assert(this.kind == ResourcePropertyKind.ComplexType, "this.kind == ResourcePropertyKind.ComplexType"); 
                    return ResourceTypeKind.ComplexType;
                } 
            } 
        }
 
        /// MIME type for the property, if it's a primitive value; null if none specified.
        internal string MimeType
        {
            [DebuggerStepThrough] 
            get { return this.mimeType; }
        } 
 
        /// The property name.
        internal string Name 
        {
            [DebuggerStepThrough]
            get { return this.name; }
        } 

        /// The type of the property. 
        internal Type Type 
        {
            get 
            {
                if (this.PropertyInfo != null)
                {
                    return this.PropertyInfo.PropertyType; 
                }
                else 
                { 
                    if (this.Kind == ResourcePropertyKind.ResourceSetReference)
                    { 
                        return typeof(System.Collections.Generic.IEnumerable<>).MakeGenericType(this.resourcePropertyType.Type);
                    }
                    else
                    { 
                        return this.resourcePropertyType.Type;
                    } 
                } 
            }
        } 

        /// 
        /// The clr type that is property refers to [For collection,
        /// this will return the element of the collection, and not the 
        /// collection].
        ///  
        internal Type ResourceClrType 
        {
            [DebuggerStepThrough] 
            get { return this.resourcePropertyType.Type; }
        }

        ///  
        /// The resource type that is property refers to [For collection,
        /// this will return the element of the collection, and not the 
        /// collection]. 
        /// 
        internal ResourceType ResourceType 
        {
            [DebuggerStepThrough]
            get { return this.resourcePropertyType; }
        } 

        /// Returns the value of the property. 
        /// The object whose property value will be returned. 
        /// The property value for the  parameter.
        internal object GetValue(object instance) 
        {
            Debug.Assert(instance != null, "instance != null");
            try
            { 
                return this.getMethod.Invoke(instance, null);
            } 
            catch (TargetInvocationException exception) 
            {
                ErrorHandler.HandleTargetInvocationException(exception); 
                throw;
            }
        }
 
        /// Sets the value of the property.
        /// The object whose property needs to be set. 
        /// new value for the property. 
        internal void SetValue(object instance, object propertyValue)
        { 
            Debug.Assert(instance != null, "instance != null");
            try
            {
                if (this.setMethod == null) 
                {
                    throw DataServiceException.CreateBadRequestError(Strings.BadRequest_PropertyValueCannotBeSet(this.Name)); 
                } 

                this.setMethod.Invoke(instance, new object[] { propertyValue }); 
            }
            catch (TargetInvocationException exception)
            {
                ErrorHandler.HandleTargetInvocationException(exception); 
                throw;
            } 
            catch (ArgumentException exception) 
            {
                throw DataServiceException.CreateBadRequestError(Strings.BadRequest_ErrorInSettingPropertyValue(this.Name), exception); 
            }
        }

        ///  
        /// return true if this property is of the given kind
        ///  
        /// flag which needs to be checked on the current property kind 
        /// true if the current property is of the given kind
        internal bool IsOfKind(ResourcePropertyKind checkKind) 
        {
            return ResourceProperty.IsOfKind(this.kind, checkKind);
        }
 
#if ASTORIA_CONTAINMENT
 
        ///  
        /// Sets all properties for the target in a containment relationship.
        ///  
        /// Property names of mapped keys in child (target) container.
        /// Property names of mapped keys in parent container.
        /// Container of target (child) entities.
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "containmentChildKeys", Justification = "1:1 mapping")] 
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "containmentParentKeys", Justification = "1:1 mapping")]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1500:VariableNamesShouldNotMatchFieldNames", MessageId = "containmentTarget", Justification = "1:1 mapping")] 
        internal void SetupContainmentTarget( 
            string[] containmentChildKeys,
            string[] containmentParentKeys, 
            ResourceContainer containmentTarget)
        {
            Debug.Assert(containmentChildKeys != null, "containmentChildKeys != null");
            Debug.Assert(containmentParentKeys != null, "containmentParentKeys != null"); 
            Debug.Assert(containmentTarget != null, "containmentTarget != null");
            Debug.Assert( 
                this.containmentChildKeys == null, 
                "this.containmentChildKeys == null -- otherwise the navigation property has more than one target");
            Debug.Assert( 
                this.IsOfKind(ResourcePropertyKind.ResourceSetReference),
                "this.IsOfKind(ResourcePropertyKind.ResourceSetReference) -- otherwise this cannot be a containment source.");

            this.containmentChildKeys = containmentChildKeys; 
            this.containmentParentKeys = containmentParentKeys;
            this.containmentTarget = containmentTarget; 
        } 

#endif 

        /// 
        /// return true if the given property kind is of the given kind
        ///  
        /// kind of the property
        /// flag which needs to be checked on property kind 
        /// true if the kind flag is set on the given property kind 
        private static bool IsOfKind(ResourcePropertyKind propertyKind, ResourcePropertyKind kind)
        { 
            return ((propertyKind & kind) == kind);
        }

        ///  
        /// Validates that the given property kind is valid
        ///  
        /// property kind is valid 
        [Conditional("DEBUG")]
        private static void DebugIsValidPropertyKind(ResourcePropertyKind propertyKind) 
        {
            if (ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.ResourceReference))
            {
                Debug.Assert( 
                    propertyKind == ResourcePropertyKind.ResourceReference || propertyKind == (ResourcePropertyKind.ResourceReference | ResourcePropertyKind.OpenProperty),
                    "reference property can't have any flags set"); 
            } 
            else if (ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.ResourceSetReference))
            { 
                Debug.Assert(
                    propertyKind == ResourcePropertyKind.ResourceSetReference || propertyKind == (ResourcePropertyKind.ResourceSetReference | ResourcePropertyKind.OpenProperty),
                    "setreference property can't have any flags set");
            } 
            else if (ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.ComplexType))
            { 
                Debug.Assert(propertyKind == ResourcePropertyKind.ComplexType, "complex property can't have any flags set"); 
            }
            else 
            {
                Debug.Assert(ResourceProperty.IsOfKind(propertyKind, ResourcePropertyKind.Primitive), "property must be primitive");
                Debug.Assert(propertyKind != ResourcePropertyKind.Key, "property can't be alone set to key");
                ResourcePropertyKind all = ResourcePropertyKind.ComplexType | 
                    ResourcePropertyKind.Key |
                    ResourcePropertyKind.Primitive | 
                    ResourcePropertyKind.ResourceReference | 
                    ResourcePropertyKind.ResourceSetReference |
                    ResourcePropertyKind.OpenProperty; 

                Debug.Assert((propertyKind | all) == all, "no higher bits must be set on the propertyKind");
            }
        } 
    }
} 

// 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