/// <summary> /// Helper method that raises the TypeGenerated event /// </summary> /// <param name="eventArgs">The event arguments passed to the subscriber</param> internal void RaiseTypeGeneratedEvent(TypeGeneratedEventArgs eventArgs) { if (this.OnTypeGenerated != null) { this.OnTypeGenerated(this, eventArgs); } }
/// <summary> /// /// </summary> /// <returns></returns> public override CodeTypeDeclarationCollection EmitApiClass() { Validate(); // emitter-specific validation CodeTypeReference baseType = this.GetBaseType(); // raise the TypeGenerated event TypeGeneratedEventArgs eventArgs = new TypeGeneratedEventArgs(Item, baseType); this.Generator.RaiseTypeGeneratedEvent(eventArgs); // public [abstract] partial class ClassName CodeTypeDeclaration typeDecl = new CodeTypeDeclaration(Item.Name); typeDecl.IsPartial = true; typeDecl.TypeAttributes = System.Reflection.TypeAttributes.Class; if (Item.Abstract) { typeDecl.TypeAttributes |= System.Reflection.TypeAttributes.Abstract; } SetTypeVisibility(typeDecl); EmitTypeAttributes(Item.Name, typeDecl, eventArgs.AdditionalAttributes); // : baseclass AssignBaseType(typeDecl, baseType, eventArgs.BaseType); AddInterfaces(Item.Name, typeDecl, eventArgs.AdditionalInterfaces); CommentEmitter.EmitSummaryComments(Item, typeDecl.Comments); // Since abstract types cannot be instantiated, skip the factory method for abstract types if ( (typeDecl.TypeAttributes & System.Reflection.TypeAttributes.Abstract) == 0) EmitFactoryMethod(typeDecl); EmitProperties(typeDecl); // additional members, if provided by the event subscriber this.AddMembers(Item.Name, typeDecl, eventArgs.AdditionalMembers); CodeTypeDeclarationCollection typeDecls = new CodeTypeDeclarationCollection(); typeDecls.Add(typeDecl); return typeDecls; }
/// <summary> /// Helper method that raises the TypeGenerated event /// </summary> /// <param name="eventArgs">The event arguments passed to the subscriber</param> internal void RaiseTypeGeneratedEvent(TypeGeneratedEventArgs eventArgs) { _generator.RaiseTypeGeneratedEvent(eventArgs); }
/// <summary> /// Creates the CodeTypeDeclarations necessary to generate the code for the EntityContainer schema element /// </summary> /// <returns></returns> public override CodeTypeDeclarationCollection EmitApiClass() { Validate(); // emitter-specific validation // declare the new class // public partial class LOBScenario : ObjectContext CodeTypeDeclaration typeDecl = new CodeTypeDeclaration(Item.Name); typeDecl.IsPartial = true; // raise the TypeGenerated event CodeTypeReference objectContextTypeRef = TypeReference.ObjectContext; TypeGeneratedEventArgs eventArgs = new TypeGeneratedEventArgs(Item, objectContextTypeRef); Generator.RaiseTypeGeneratedEvent(eventArgs); if (eventArgs.BaseType != null && !eventArgs.BaseType.Equals(objectContextTypeRef)) { typeDecl.BaseTypes.Add(eventArgs.BaseType); } else { typeDecl.BaseTypes.Add(TypeReference.ObjectContext); } AddInterfaces(Item.Name, typeDecl, eventArgs.AdditionalInterfaces); CommentEmitter.EmitSummaryComments(Item, typeDecl.Comments); EmitTypeAttributes(Item.Name, typeDecl, eventArgs.AdditionalAttributes); CreateConstructors(typeDecl); // adding partial OnContextCreated method CreateContextPartialMethods(typeDecl); foreach (EntitySetBase entitySetBase in Item.BaseEntitySets) { if (MetadataUtil.IsEntitySet(entitySetBase)) { EntitySet set = (EntitySet)entitySetBase; CodeMemberProperty codeProperty = CreateEntitySetProperty(set); typeDecl.Members.Add(codeProperty); CodeMemberField codeField = CreateEntitySetField(set); typeDecl.Members.Add(codeField); } } foreach (EntitySetBase entitySetBase in Item.BaseEntitySets) { if (MetadataUtil.IsEntitySet(entitySetBase)) { EntitySet set = (EntitySet)entitySetBase; CodeMemberMethod codeProperty = CreateEntitySetAddObjectProperty(set); typeDecl.Members.Add(codeProperty); } } foreach (EdmFunction functionImport in Item.FunctionImports) { if (ShouldEmitFunctionImport(functionImport)) { CodeMemberMethod functionMethod = CreateFunctionImportStructuralTypeReaderMethod(functionImport); typeDecl.Members.Add(functionMethod); } } // additional members, if provided by the event subscriber AddMembers(Item.Name, typeDecl, eventArgs.AdditionalMembers); CodeTypeDeclarationCollection typeDecls = new CodeTypeDeclarationCollection(); typeDecls.Add(typeDecl); return typeDecls; }