1 //---------------------------------------------------------------------
2 // <copyright file="PropertyEmitterBase.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
12 using System.Collections.Generic;
13 using System.Data.Metadata.Edm;
14 using System.Diagnostics;
15 using System.Data.Entity.Design.SsdlGenerator;
16 using System.Data.Entity.Design.Common;
18 namespace System.Data.EntityModel.Emitters
20 internal abstract class PropertyEmitterBase : MetadataItemEmitter
22 private bool _declaringTypeUsesStandardBaseType;
23 protected PropertyEmitterBase(ClientApiGenerator generator, MetadataItem item, bool declaringTypeUsesStandardBaseType)
24 :base(generator, item)
26 Debug.Assert(item != null, "item is null");
27 _declaringTypeUsesStandardBaseType = declaringTypeUsesStandardBaseType;
31 /// This is where the derived classes supply their emit logic.
33 /// <param name="typeDecl">The CodeDom representation of the type that the property is being added to.</param>
34 protected abstract void EmitProperty(CodeTypeDeclaration typeDecl);
37 /// Validation logic specific to property emitters
39 protected override void Validate()
41 VerifyGetterAndSetterAccessibilityCompatability();
42 Generator.VerifyLanguageCaseSensitiveCompatibilityForProperty(Item as EdmMember);
46 /// The compiler ensures accessibility on a Setter/Getter is more restrictive than on the Property.
47 /// However accessibility modifiers are not well ordered. Internal and Protected don't go well together
48 /// because neither is more restrictive than others.
50 private void VerifyGetterAndSetterAccessibilityCompatability()
52 if (PropertyEmitter.GetGetterAccessibility(Item) == MemberAttributes.Assembly
53 && PropertyEmitter.GetSetterAccessibility(Item) == MemberAttributes.Family)
55 Generator.AddError(System.Data.Entity.Design.Strings.GeneratedPropertyAccessibilityConflict(Item.Name, "Internal", "Protected"),
56 ModelBuilderErrorCode.GeneratedPropertyAccessibilityConflict,
57 EdmSchemaErrorSeverity.Error, Item.DeclaringType.FullName, Item.Name);
59 else if (PropertyEmitter.GetGetterAccessibility(Item) == MemberAttributes.Family
60 && PropertyEmitter.GetSetterAccessibility(Item) == MemberAttributes.Assembly)
62 Generator.AddError(System.Data.Entity.Design.Strings.GeneratedPropertyAccessibilityConflict(Item.Name, "Protected", "Internal"),
63 ModelBuilderErrorCode.GeneratedPropertyAccessibilityConflict,
64 EdmSchemaErrorSeverity.Error, Item.DeclaringType.FullName, Item.Name);
71 /// Main method for Emitting property code.
73 /// <param name="typeDecl">The CodeDom representation of the type that the property is being added to.</param>
74 public void Emit(CodeTypeDeclaration typeDecl)
77 EmitProperty(typeDecl);
80 protected bool AncestorClassDefinesName(string name)
82 if (_declaringTypeUsesStandardBaseType && Utils.DoesTypeReserveMemberName(Item.DeclaringType, name, Generator.LanguageAppropriateStringComparer))
87 StructuralType baseType = Item.DeclaringType.BaseType as StructuralType;
88 if (baseType != null && baseType.Members.Contains(name))
96 public new EdmMember Item
100 return base.Item as EdmMember;