Beispiel #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;
        }
Beispiel #2
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);
                    }
                }
            }
        }