Пример #1
0
        private void Emit(Dictionary <string, string> usedClassName, string namespaceName, List <GlobalItem> items)
        {
            // it is a valid scenario for namespaceName to be empty
            //string namespaceName = Generator.SourceObjectNamespaceName;
            Generator.SourceEdmNamespaceName = namespaceName;

            // emit the namespace definition
            CodeNamespace codeNamespace = new CodeNamespace(namespaceName);

            // output some boiler plate comments
            string comments = Strings.NamespaceComments(
                System.IO.Path.GetFileName(_targetFilePath),
                DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture));

            CommentEmitter.EmitComments(CommentEmitter.GetFormattedLines(comments, false), codeNamespace.Comments, false);
            CompileUnit.Namespaces.Add(codeNamespace);

            // Emit the classes in the schema
            foreach (GlobalItem element in items)
            {
                if (AddElementNameToCache(element, usedClassName))
                {
                    SchemaTypeEmitter             emitter         = CreateElementEmitter(element);
                    CodeTypeDeclarationCollection typeDeclaration = emitter.EmitApiClass();
                    if (typeDeclaration.Count > 0)
                    {
                        codeNamespace.Types.AddRange(typeDeclaration);
                    }
                }
            }

            Generator.SourceEdmNamespaceName = null;
        }
Пример #2
0
        /// <summary>
        /// Common way to fill out EdmTypeAttribute derived attributes
        /// </summary>
        /// <param name="attributeName">Unqualified name of the attribute</param>
        /// <param name="emitter">The strongly typed emitter</param>
        /// <param name="typeDecl">The type declaration to add the attribues to.</param>
        public void EmitSchemaTypeAttribute(string attributeName, SchemaTypeEmitter emitter, CodeTypeDeclaration typeDecl)
        {
            // call the shared static version
            EdmType type = emitter.Item as EdmType;

            Debug.Assert(type != null, "type is not an EdmType");
            EmitSchemaTypeAttribute(attributeName, type, typeDecl as CodeTypeMember);
        }
Пример #3
0
        /// <summary>
        /// Creates the CodeTypeDeclarations necessary to generate the code
        /// </summary>
        public void Emit()
        {
            // it is a valid scenario for namespaceName to be empty
            string namespaceName = Generator.SourceObjectNamespaceName;

            // emit the namespace definition
            CodeNamespace codeNamespace = new CodeNamespace(namespaceName);

            // output some boiler plate comments
            string comments = Strings.NamespaceComments(
                System.IO.Path.GetFileName(_targetFilePath),
                DateTime.Now.ToString(System.Globalization.CultureInfo.CurrentCulture));

            CommentEmitter.EmitComments(CommentEmitter.GetFormattedLines(comments, false), codeNamespace.Comments, false);
            CompileUnit.Namespaces.Add(codeNamespace);

            // Add the assembly attribute.
            CodeAttributeDeclaration assemblyAttribute;

            // SQLBUDT 505339: VB compiler fails if multiple assembly attributes exist in the same project.
            // This adds a GUID to the assembly attribute so that each generated file will have a unique EdmSchemaAttribute in VB.
            if (this.Generator.Language == System.Data.Entity.Design.LanguageOption.GenerateVBCode) //The GUID is only added in VB
            {
                assemblyAttribute = AttributeEmitter.EmitSimpleAttribute("System.Data.Objects.DataClasses.EdmSchemaAttribute", System.Guid.NewGuid().ToString());
            }
            else
            {
                assemblyAttribute = AttributeEmitter.EmitSimpleAttribute("System.Data.Objects.DataClasses.EdmSchemaAttribute");
            }
            CompileUnit.AssemblyCustomAttributes.Add(assemblyAttribute);

            Dictionary <string, string> usedClassName = new Dictionary <string, string>(StringComparer.Ordinal);

            // Emit the classes in the schema
            foreach (GlobalItem element in Generator.GetSourceTypes())
            {
                Debug.Assert(!(element is EdmFunction), "Are you trying to emit functions now? If so add an emitter for it.");

                if (AddElementNameToCache(element, usedClassName))
                {
                    SchemaTypeEmitter             emitter         = CreateElementEmitter(element);
                    CodeTypeDeclarationCollection typeDeclaration = emitter.EmitApiClass();
                    if (typeDeclaration.Count > 0)
                    {
                        codeNamespace.Types.AddRange(typeDeclaration);
                    }
                }
            }
        }
Пример #4
0
 /// <summary>
 /// The method to be called to create the type level attributes for the SchemaTypeEmitter
 /// </summary>
 /// <param name="emitter">The strongly typed emitter</param>
 /// <param name="typeDecl">The type declaration to add the attribues to.</param>
 public void EmitTypeAttributes(SchemaTypeEmitter emitter, CodeTypeDeclaration typeDecl)
 {
     Debug.Assert(emitter != null, "emitter should not be null");
     Debug.Assert(typeDecl != null, "typeDecl should not be null");
 }
Пример #5
0
 /// <summary>
 /// The method to be called to create the type level attributes for the SchemaTypeEmitter
 /// </summary>
 /// <param name="emitter">The strongly typed emitter</param>
 /// <param name="typeDecl">The type declaration to add the attribues to.</param>
 public void EmitTypeAttributes(SchemaTypeEmitter emitter, CodeTypeDeclaration typeDecl)
 {
     Debug.Assert(emitter != null, "emitter should not be null");
     Debug.Assert(typeDecl != null, "typeDecl should not be null");
 }
 /// <summary>
 /// Common way to fill out EdmTypeAttribute derived attributes
 /// </summary>
 /// <param name="attributeName">Unqualified name of the attribute</param>
 /// <param name="emitter">The strongly typed emitter</param>
 /// <param name="typeDecl">The type declaration to add the attribues to.</param>
 public void EmitSchemaTypeAttribute(string attributeName, SchemaTypeEmitter emitter, CodeTypeDeclaration typeDecl)
 {
     // call the shared static version
     EdmType type = emitter.Item as EdmType;
     Debug.Assert(type != null, "type is not an EdmType");
     EmitSchemaTypeAttribute(attributeName, type, typeDecl as CodeTypeMember);
 }