Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataWeb / Design / system / Data / EntityModel / Emitters / MetadataItemEmitter.cs / 1 / MetadataItemEmitter.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //---------------------------------------------------------------------using System; using System.Collections.Generic; using System.Text; using System.Data.Metadata.Edm; using System.Diagnostics; using System.CodeDom; using System.Reflection; namespace System.Data.EntityModel.Emitters { internal abstract class MetadataItemEmitter : Emitter { private MetadataItem _item; protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item) :base(generator) { Debug.Assert(item != null, "item is null"); _item = item; } protected MetadataItem Item { get { return _item; } } ////// Emitter-specific validation here /// protected abstract void Validate(); #region Operations for Getting Accessibility private const string CodeGenerationValueAccessibilityInternal = "Internal"; private const string CodeGenerationValueAccessibilityProtected = "Protected"; private const string CodeGenerationValueAccessibilityPublic = "Public"; private const string CodeGenerationValueAccessibilityPrivate = "Private"; #region Protected Block protected static MemberAttributes AccessibilityFromGettersAndSetters(EdmMember property) { MemberAttributes scope = MemberAttributes.Private; MemberAttributes getter = GetGetterAccessibility(property); if (IsLeftMoreAccessableThanRight(getter, scope)) { scope = getter; } MemberAttributes setter = GetSetterAccessibility(property); if (IsLeftMoreAccessableThanRight(setter, scope)) { scope = setter; } return scope; } protected static MemberAttributes GetGetterAccessibility(EdmMember item) { return GetAccessibilityValue(item, XmlConstants.GetterAccess); } protected static MemberAttributes GetSetterAccessibility(EdmMember item) { return GetAccessibilityValue(item, XmlConstants.SetterAccess); } protected static MemberAttributes GetEntitySetPropertyAccessibility(EntitySet item) { return GetAccessibilityValue(item, XmlConstants.GetterAccess); } protected static MemberAttributes GetEntityTypeAccessibility(EntityType item) { return GetAccessibilityValue(item, XmlConstants.TypeAccess); } protected static int GetAccessibilityRank(MemberAttributes accessibility) { Debug.Assert(accessibility == MemberAttributes.Private || accessibility == MemberAttributes.Public || accessibility == MemberAttributes.Assembly || accessibility == MemberAttributes.Family, "this method is intended to deal with only single access attributes"); switch (accessibility) { case MemberAttributes.Public: return 0; case MemberAttributes.Assembly: return 1; case MemberAttributes.Family: return 2; default: Debug.Assert(accessibility == MemberAttributes.Private, "did a new type get added?"); return 3; } } protected static TypeAttributes GetTypeAccessibilityValue(MetadataItem item) { TypeAttributes accessibilty = TypeAttributes.Public; MetadataProperty metadataProperty; if (item.MetadataProperties.TryGetValue(Utils.GetFullyQualifiedCodeGenerationAttributeName(XmlConstants.TypeAccess), false, out metadataProperty)) { accessibilty = GetCodeAccessibilityTypeAttribute(metadataProperty.Value.ToString()); } return accessibilty; } #endregion Protected #region Private Block private static MemberAttributes GetAccessibilityValue(MetadataItem item, string attribute) { MemberAttributes accessibilty = MemberAttributes.Public; MetadataProperty metadataProperty; if (item.MetadataProperties.TryGetValue(Utils.GetFullyQualifiedCodeGenerationAttributeName(attribute), false, out metadataProperty)) { accessibilty = GetCodeAccessibilityMemberAttribute(metadataProperty.Value.ToString()); } return accessibilty; } private static MemberAttributes GetCodeAccessibilityMemberAttribute(string accessibility) { Debug.Assert(accessibility != null, "why does accessibility == null?"); switch (accessibility) { case CodeGenerationValueAccessibilityInternal: return MemberAttributes.Assembly; case CodeGenerationValueAccessibilityPrivate: return MemberAttributes.Private; case CodeGenerationValueAccessibilityProtected: return MemberAttributes.Family; default: Debug.Assert(accessibility == CodeGenerationValueAccessibilityPublic, "found an accessibility other than " + CodeGenerationValueAccessibilityPublic); return MemberAttributes.Public; } } ////// Given a MemberAttribute, returns a string representation used in CSDL. /// For e.g: MemebrAttribtue.Family is Protected in our csdl, (protected in C#, Family in VB) /// Inverse of the method above (GetCodeAccessibilityMemberAttribute) /// protected static string GetAccessibilityCsdlStringFromMemberAttribute(MemberAttributes attribute) { switch (attribute) { case MemberAttributes.Assembly: return CodeGenerationValueAccessibilityInternal; case MemberAttributes.Private: return CodeGenerationValueAccessibilityPrivate; case MemberAttributes.Family: return CodeGenerationValueAccessibilityProtected; default: Debug.Assert(attribute == MemberAttributes.Public, "found MemberAttribute other than " + CodeGenerationValueAccessibilityPublic); return CodeGenerationValueAccessibilityPublic; } } private static bool IsLeftMoreAccessableThanRight(MemberAttributes left, MemberAttributes right) { return GetAccessibilityRank(left) < GetAccessibilityRank(right); } private static TypeAttributes GetCodeAccessibilityTypeAttribute(string accessibility) { Debug.Assert(accessibility != null, "why does accessibility == null?"); if (accessibility == CodeGenerationValueAccessibilityInternal || accessibility == CodeGenerationValueAccessibilityProtected) { return TypeAttributes.NotPublic; } else { Debug.Assert(accessibility == CodeGenerationValueAccessibilityPublic, "found an accessibility other than " + CodeGenerationValueAccessibilityPublic); return TypeAttributes.Public; } } #endregion Private #endregion Operations for getting Accessibility } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //---------------------------------------------------------------------using System; using System.Collections.Generic; using System.Text; using System.Data.Metadata.Edm; using System.Diagnostics; using System.CodeDom; using System.Reflection; namespace System.Data.EntityModel.Emitters { internal abstract class MetadataItemEmitter : Emitter { private MetadataItem _item; protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item) :base(generator) { Debug.Assert(item != null, "item is null"); _item = item; } protected MetadataItem Item { get { return _item; } } ////// Emitter-specific validation here /// protected abstract void Validate(); #region Operations for Getting Accessibility private const string CodeGenerationValueAccessibilityInternal = "Internal"; private const string CodeGenerationValueAccessibilityProtected = "Protected"; private const string CodeGenerationValueAccessibilityPublic = "Public"; private const string CodeGenerationValueAccessibilityPrivate = "Private"; #region Protected Block protected static MemberAttributes AccessibilityFromGettersAndSetters(EdmMember property) { MemberAttributes scope = MemberAttributes.Private; MemberAttributes getter = GetGetterAccessibility(property); if (IsLeftMoreAccessableThanRight(getter, scope)) { scope = getter; } MemberAttributes setter = GetSetterAccessibility(property); if (IsLeftMoreAccessableThanRight(setter, scope)) { scope = setter; } return scope; } protected static MemberAttributes GetGetterAccessibility(EdmMember item) { return GetAccessibilityValue(item, XmlConstants.GetterAccess); } protected static MemberAttributes GetSetterAccessibility(EdmMember item) { return GetAccessibilityValue(item, XmlConstants.SetterAccess); } protected static MemberAttributes GetEntitySetPropertyAccessibility(EntitySet item) { return GetAccessibilityValue(item, XmlConstants.GetterAccess); } protected static MemberAttributes GetEntityTypeAccessibility(EntityType item) { return GetAccessibilityValue(item, XmlConstants.TypeAccess); } protected static int GetAccessibilityRank(MemberAttributes accessibility) { Debug.Assert(accessibility == MemberAttributes.Private || accessibility == MemberAttributes.Public || accessibility == MemberAttributes.Assembly || accessibility == MemberAttributes.Family, "this method is intended to deal with only single access attributes"); switch (accessibility) { case MemberAttributes.Public: return 0; case MemberAttributes.Assembly: return 1; case MemberAttributes.Family: return 2; default: Debug.Assert(accessibility == MemberAttributes.Private, "did a new type get added?"); return 3; } } protected static TypeAttributes GetTypeAccessibilityValue(MetadataItem item) { TypeAttributes accessibilty = TypeAttributes.Public; MetadataProperty metadataProperty; if (item.MetadataProperties.TryGetValue(Utils.GetFullyQualifiedCodeGenerationAttributeName(XmlConstants.TypeAccess), false, out metadataProperty)) { accessibilty = GetCodeAccessibilityTypeAttribute(metadataProperty.Value.ToString()); } return accessibilty; } #endregion Protected #region Private Block private static MemberAttributes GetAccessibilityValue(MetadataItem item, string attribute) { MemberAttributes accessibilty = MemberAttributes.Public; MetadataProperty metadataProperty; if (item.MetadataProperties.TryGetValue(Utils.GetFullyQualifiedCodeGenerationAttributeName(attribute), false, out metadataProperty)) { accessibilty = GetCodeAccessibilityMemberAttribute(metadataProperty.Value.ToString()); } return accessibilty; } private static MemberAttributes GetCodeAccessibilityMemberAttribute(string accessibility) { Debug.Assert(accessibility != null, "why does accessibility == null?"); switch (accessibility) { case CodeGenerationValueAccessibilityInternal: return MemberAttributes.Assembly; case CodeGenerationValueAccessibilityPrivate: return MemberAttributes.Private; case CodeGenerationValueAccessibilityProtected: return MemberAttributes.Family; default: Debug.Assert(accessibility == CodeGenerationValueAccessibilityPublic, "found an accessibility other than " + CodeGenerationValueAccessibilityPublic); return MemberAttributes.Public; } } ////// Given a MemberAttribute, returns a string representation used in CSDL. /// For e.g: MemebrAttribtue.Family is Protected in our csdl, (protected in C#, Family in VB) /// Inverse of the method above (GetCodeAccessibilityMemberAttribute) /// protected static string GetAccessibilityCsdlStringFromMemberAttribute(MemberAttributes attribute) { switch (attribute) { case MemberAttributes.Assembly: return CodeGenerationValueAccessibilityInternal; case MemberAttributes.Private: return CodeGenerationValueAccessibilityPrivate; case MemberAttributes.Family: return CodeGenerationValueAccessibilityProtected; default: Debug.Assert(attribute == MemberAttributes.Public, "found MemberAttribute other than " + CodeGenerationValueAccessibilityPublic); return CodeGenerationValueAccessibilityPublic; } } private static bool IsLeftMoreAccessableThanRight(MemberAttributes left, MemberAttributes right) { return GetAccessibilityRank(left) < GetAccessibilityRank(right); } private static TypeAttributes GetCodeAccessibilityTypeAttribute(string accessibility) { Debug.Assert(accessibility != null, "why does accessibility == null?"); if (accessibility == CodeGenerationValueAccessibilityInternal || accessibility == CodeGenerationValueAccessibilityProtected) { return TypeAttributes.NotPublic; } else { Debug.Assert(accessibility == CodeGenerationValueAccessibilityPublic, "found an accessibility other than " + CodeGenerationValueAccessibilityPublic); return TypeAttributes.Public; } } #endregion Private #endregion Operations for getting Accessibility } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SecurityRequiresReviewAttribute.cs
- BinaryWriter.cs
- AddressUtility.cs
- FaultHandlingFilter.cs
- PaintEvent.cs
- TextDecorationLocationValidation.cs
- CompositeFontParser.cs
- SignedPkcs7.cs
- PageWrapper.cs
- DataGridLengthConverter.cs
- SimpleApplicationHost.cs
- TypographyProperties.cs
- EmptyEnumerator.cs
- CanonicalizationDriver.cs
- HMACMD5.cs
- SubqueryRules.cs
- CultureMapper.cs
- RectAnimation.cs
- WindowsGraphicsWrapper.cs
- NameValueConfigurationCollection.cs
- EncryptedType.cs
- RenderDataDrawingContext.cs
- GeneralTransform3DCollection.cs
- HtmlShimManager.cs
- QilXmlWriter.cs
- XmlAnyAttributeAttribute.cs
- WithStatement.cs
- ConfigXmlReader.cs
- ThrowHelper.cs
- StringUtil.cs
- RepeatBehavior.cs
- PagedDataSource.cs
- XXXOnTypeBuilderInstantiation.cs
- COM2ICategorizePropertiesHandler.cs
- DataGridViewBindingCompleteEventArgs.cs
- OutputCacheModule.cs
- wgx_sdk_version.cs
- XsltLibrary.cs
- PathTooLongException.cs
- EncodingFallbackAwareXmlTextWriter.cs
- IImplicitResourceProvider.cs
- InvokeMethodActivity.cs
- NetCodeGroup.cs
- ForeignKeyConstraint.cs
- StringAnimationUsingKeyFrames.cs
- IndicFontClient.cs
- HandleRef.cs
- Soap.cs
- Debug.cs
- Identifier.cs
- XmlSchemaAttributeGroup.cs
- odbcmetadatacollectionnames.cs
- SendActivityEventArgs.cs
- SafeEventLogWriteHandle.cs
- MouseEvent.cs
- StyleSelector.cs
- ServiceThrottle.cs
- Baml2006Reader.cs
- ChildrenQuery.cs
- ChildTable.cs
- SrgsOneOf.cs
- InvalidPrinterException.cs
- XpsSerializationException.cs
- GetCardDetailsRequest.cs
- ColorKeyFrameCollection.cs
- LogReserveAndAppendState.cs
- UnicodeEncoding.cs
- RequestStatusBarUpdateEventArgs.cs
- CellParaClient.cs
- SyntaxCheck.cs
- IriParsingElement.cs
- LineVisual.cs
- WorkflowRuntime.cs
- SpellCheck.cs
- ListViewItemMouseHoverEvent.cs
- WS2007FederationHttpBindingElement.cs
- ChangePasswordAutoFormat.cs
- KeyedHashAlgorithm.cs
- X509CertificateValidator.cs
- SHA256Cng.cs
- ManagedWndProcTracker.cs
- FrameAutomationPeer.cs
- ObjectSet.cs
- MimeFormatter.cs
- TranslateTransform.cs
- LinkedList.cs
- DataSourceSelectArguments.cs
- CreateBookmarkScope.cs
- TransformedBitmap.cs
- HtmlTableCell.cs
- RegexWriter.cs
- TextTreeTextBlock.cs
- XappLauncher.cs
- Grid.cs
- LayoutEvent.cs
- EdmComplexTypeAttribute.cs
- SpellerError.cs
- PlatformNotSupportedException.cs
- SecurityContext.cs
- XmlWrappingReader.cs