SchemaTypeEmitter.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataWeb / Design / system / Data / EntityModel / Emitters / SchemaTypeEmitter.cs / 1 / SchemaTypeEmitter.cs

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

using System.CodeDom; 
using System.Collections.Generic;
using System.Data.Services.Design;
using System.Data.Metadata.Edm;
using System.Diagnostics; 
using System.Reflection;
 
namespace System.Data.EntityModel.Emitters 
{
    ///  
    ///
    /// 
    internal abstract class SchemaTypeEmitter : MetadataItemEmitter
    { 
        #region Public Methods
        public abstract CodeTypeDeclarationCollection EmitApiClass(); 
        #endregion 

        #region Protected Methods 
        /// 
        ///
        /// 
        ///  
        /// 
        protected SchemaTypeEmitter(ClientApiGenerator generator, MetadataItem item) 
        : base(generator, item) 
        {
        } 

        /// 
        ///
        ///  
        /// 
        protected virtual void EmitTypeAttributes( CodeTypeDeclaration typeDecl ) 
        { 
            Generator.AttributeEmitter.EmitTypeAttributes( this, typeDecl );
        } 

        /// 
        /// Emitter-specific validation: for SchemaTypeEmitter-derived classes, we
        /// check the EdmItemCollection for other entities that have the same name 
        /// but differ in case
        ///  
        protected override void Validate() 
        {
            Generator.VerifyLanguageCaseSensitiveCompatibilityForType(Item); 
        }

        /// 
        /// Add attributes to a type's CustomAttributes collection 
        /// 
        /// The name of the type 
        /// The type to annotate 
        /// The additional attributes
        protected void EmitTypeAttributes(string itemName, CodeTypeDeclaration typeDecl, 
                                          List additionalAttributes)
        {
            if (additionalAttributes != null && additionalAttributes.Count > 0)
            { 
                try
                { 
                    typeDecl.CustomAttributes.AddRange(additionalAttributes.ToArray()); 
                }
                catch (ArgumentNullException e) 
                {
                    Generator.AddError(Strings.InvalidAttributeSuppliedForType(itemName),
                                       ModelBuilderErrorCode.InvalidAttributeSuppliedForType,
                                       EdmSchemaErrorSeverity.Error, 
                                       e);
                } 
            } 

            EmitTypeAttributes(typeDecl); 
        }

        /// 
        /// Add interfaces to the type's list of BaseTypes 
        /// 
        /// The name of the type 
        /// The type whose list of base types needs to be extended 
        /// The interfaces to add to the list of base types
        protected void AddInterfaces(string itemName, 
                                     CodeTypeDeclaration typeDecl,
                                     List additionalInterfaces)
        {
            if (additionalInterfaces != null) 
            {
                try 
                { 
                    foreach (Type interfaceType in additionalInterfaces)
                    { 
                        typeDecl.BaseTypes.Add(new CodeTypeReference(interfaceType));
                    }
                }
                catch (ArgumentNullException e) 
                {
                    Generator.AddError(Strings.InvalidInterfaceSuppliedForType(itemName), 
                                      ModelBuilderErrorCode.InvalidInterfaceSuppliedForType, 
                                      EdmSchemaErrorSeverity.Error,
                                      e); 
                }
            }
        }
 
        /// 
        /// Add interfaces to the type's list of BaseTypes 
        ///  
        /// The name of the type
        /// The type to which members need to be added 
        /// The members to add
        protected void AddMembers(string itemName, CodeTypeDeclaration typeDecl,
                                  List additionalMembers)
        { 
            if (additionalMembers != null && additionalMembers.Count > 0)
            { 
                try 
                {
                    typeDecl.Members.AddRange(additionalMembers.ToArray()); 
                }
                catch (ArgumentNullException e)
                {
                    Generator.AddError(Strings.InvalidMemberSuppliedForType(itemName), 
                                       ModelBuilderErrorCode.InvalidMemberSuppliedForType,
                                       EdmSchemaErrorSeverity.Error, 
                                       e); 
                }
            } 
        }

        #endregion
 
        #region Protected Properties
 
        ///  
        /// Gets the element that code is being emitted for.
        ///  
        internal new GlobalItem Item
        {
            get
            { 
                return base.Item as GlobalItem;
            } 
        } 

        internal void SetTypeVisibility(CodeTypeDeclaration typeDecl) 
        {
            typeDecl.TypeAttributes &= ~System.Reflection.TypeAttributes.VisibilityMask;
            typeDecl.TypeAttributes |= GetTypeAccessibilityValue(Item);
        } 

        #endregion 
    } 
}

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

using System.CodeDom; 
using System.Collections.Generic;
using System.Data.Services.Design;
using System.Data.Metadata.Edm;
using System.Diagnostics; 
using System.Reflection;
 
namespace System.Data.EntityModel.Emitters 
{
    ///  
    ///
    /// 
    internal abstract class SchemaTypeEmitter : MetadataItemEmitter
    { 
        #region Public Methods
        public abstract CodeTypeDeclarationCollection EmitApiClass(); 
        #endregion 

        #region Protected Methods 
        /// 
        ///
        /// 
        ///  
        /// 
        protected SchemaTypeEmitter(ClientApiGenerator generator, MetadataItem item) 
        : base(generator, item) 
        {
        } 

        /// 
        ///
        ///  
        /// 
        protected virtual void EmitTypeAttributes( CodeTypeDeclaration typeDecl ) 
        { 
            Generator.AttributeEmitter.EmitTypeAttributes( this, typeDecl );
        } 

        /// 
        /// Emitter-specific validation: for SchemaTypeEmitter-derived classes, we
        /// check the EdmItemCollection for other entities that have the same name 
        /// but differ in case
        ///  
        protected override void Validate() 
        {
            Generator.VerifyLanguageCaseSensitiveCompatibilityForType(Item); 
        }

        /// 
        /// Add attributes to a type's CustomAttributes collection 
        /// 
        /// The name of the type 
        /// The type to annotate 
        /// The additional attributes
        protected void EmitTypeAttributes(string itemName, CodeTypeDeclaration typeDecl, 
                                          List additionalAttributes)
        {
            if (additionalAttributes != null && additionalAttributes.Count > 0)
            { 
                try
                { 
                    typeDecl.CustomAttributes.AddRange(additionalAttributes.ToArray()); 
                }
                catch (ArgumentNullException e) 
                {
                    Generator.AddError(Strings.InvalidAttributeSuppliedForType(itemName),
                                       ModelBuilderErrorCode.InvalidAttributeSuppliedForType,
                                       EdmSchemaErrorSeverity.Error, 
                                       e);
                } 
            } 

            EmitTypeAttributes(typeDecl); 
        }

        /// 
        /// Add interfaces to the type's list of BaseTypes 
        /// 
        /// The name of the type 
        /// The type whose list of base types needs to be extended 
        /// The interfaces to add to the list of base types
        protected void AddInterfaces(string itemName, 
                                     CodeTypeDeclaration typeDecl,
                                     List additionalInterfaces)
        {
            if (additionalInterfaces != null) 
            {
                try 
                { 
                    foreach (Type interfaceType in additionalInterfaces)
                    { 
                        typeDecl.BaseTypes.Add(new CodeTypeReference(interfaceType));
                    }
                }
                catch (ArgumentNullException e) 
                {
                    Generator.AddError(Strings.InvalidInterfaceSuppliedForType(itemName), 
                                      ModelBuilderErrorCode.InvalidInterfaceSuppliedForType, 
                                      EdmSchemaErrorSeverity.Error,
                                      e); 
                }
            }
        }
 
        /// 
        /// Add interfaces to the type's list of BaseTypes 
        ///  
        /// The name of the type
        /// The type to which members need to be added 
        /// The members to add
        protected void AddMembers(string itemName, CodeTypeDeclaration typeDecl,
                                  List additionalMembers)
        { 
            if (additionalMembers != null && additionalMembers.Count > 0)
            { 
                try 
                {
                    typeDecl.Members.AddRange(additionalMembers.ToArray()); 
                }
                catch (ArgumentNullException e)
                {
                    Generator.AddError(Strings.InvalidMemberSuppliedForType(itemName), 
                                       ModelBuilderErrorCode.InvalidMemberSuppliedForType,
                                       EdmSchemaErrorSeverity.Error, 
                                       e); 
                }
            } 
        }

        #endregion
 
        #region Protected Properties
 
        ///  
        /// Gets the element that code is being emitted for.
        ///  
        internal new GlobalItem Item
        {
            get
            { 
                return base.Item as GlobalItem;
            } 
        } 

        internal void SetTypeVisibility(CodeTypeDeclaration typeDecl) 
        {
            typeDecl.TypeAttributes &= ~System.Reflection.TypeAttributes.VisibilityMask;
            typeDecl.TypeAttributes |= GetTypeAccessibilityValue(Item);
        } 

        #endregion 
    } 
}

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