/// <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); } } } }
public override CodeTypeDeclarationCollection EmitApiClass() { Debug.Assert(Item.AssociationEndMembers.Count == 2, "must have exactly two ends"); AssociationEndMember end1 = Item.AssociationEndMembers[0]; AssociationEndMember end2 = Item.AssociationEndMembers[1]; Generator.CompileUnit.AssemblyCustomAttributes.Add( AttributeEmitter.EmitSimpleAttribute( Utils.FQAdoFrameworkDataClassesName("EdmRelationshipAttribute"), Item.NamespaceName, //it is ok to use the c namespace because relationships aren't backed by clr objects Item.Name, end1.Name, GetMultiplicityCodeExpression(end1.RelationshipMultiplicity), GetEndTypeCodeExpression(end1), end2.Name, GetMultiplicityCodeExpression(end2.RelationshipMultiplicity), GetEndTypeCodeExpression(end2) )); // this method doesn't actually create a new type, just a new assembly level attribute for each end return(new CodeTypeDeclarationCollection()); }