Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / ndp / fx / src / DataEntity / System / Data / Metadata / ObjectHelper.cs / 1 / ObjectHelper.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] //--------------------------------------------------------------------- using System.Data.Mapping; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Data.Common.Utils; using System.IO; namespace System.Data.Metadata.Edm { ////// Helper Class for EDM Metadata - this class contains all the helper methods /// which needs access to internal methods. The other partial class contains all /// helper methods which just uses public methods/properties. The reason why we /// did this for allowing view gen to happen at compile time - all the helper /// methods that view gen or mapping uses are in the other helper class. Rest of the /// methods are in this class /// internal static partial class Helper { #region Fields // List of all the static empty list used all over the code internal static readonly ReadOnlyCollection> EmptyKeyValueStringObjectList = new ReadOnlyCollection >(new KeyValuePair [0]); internal static readonly ReadOnlyCollection EmptyStringList = new ReadOnlyCollection (new string[0]); internal static readonly ReadOnlyCollection EmptyFacetDescriptionEnumerable = new ReadOnlyCollection (new FacetDescription[0]); internal static readonly ReadOnlyCollection EmptyEdmFunctionReadOnlyCollection = new ReadOnlyCollection (new EdmFunction[0]); internal static readonly ReadOnlyCollection EmptyPrimitiveTypeReadOnlyCollection = new ReadOnlyCollection (new PrimitiveType[0]); internal static readonly KeyValuePair [] EmptyKeyValueStringObjectArray = new KeyValuePair [0]; internal const char PeriodSymbol = '.'; internal const char CommaSymbol = ','; #endregion #region Methods /// /// Returns the single error message from the list of errors /// /// ///static internal string CombineErrorMessage(IEnumerable errors) { Debug.Assert(errors != null); StringBuilder sb = new StringBuilder(System.Environment.NewLine); int count = 0; foreach (System.Data.Metadata.Edm.EdmSchemaError error in errors) { //Don't append a new line at the beginning of the messages if ((count++) != 0) { sb.Append(System.Environment.NewLine); } sb.Append(error.ToString()); } Debug.Assert(count!=0, "Empty Error List"); return sb.ToString(); } /// /// Returns the single error message from the list of errors /// /// ///static internal string CombineErrorMessage(IEnumerable errors) { StringBuilder sb = new StringBuilder(System.Environment.NewLine); int count = 0; foreach (EdmItemError error in errors) { // Only add the new line if this is not the first error if ((count++) != 0) { sb.Append(System.Environment.NewLine); } sb.Append(error.Message); } return sb.ToString(); } // requires: enumerations must have the same number of members // effects: returns paired enumeration values internal static IEnumerable > PairEnumerations (IBaseList left, IEnumerable right) { IEnumerator leftEnumerator = left.GetEnumerator(); IEnumeratorrightEnumerator = right.GetEnumerator(); while (leftEnumerator.MoveNext() && rightEnumerator.MoveNext()) { yield return new KeyValuePair((T)leftEnumerator.Current, rightEnumerator.Current); } yield break; } /// /// Returns a model (C-Space) typeusage for the given typeusage. if the type is already in c-space, it returns /// the given typeusage. The typeUsage returned is created by invoking the provider service to map from provider /// specific type to model type. /// /// typeusage ///the respective Model (C-Space) typeusage static internal TypeUsage GetModelTypeUsage(TypeUsage typeUsage) { return typeUsage.GetModelTypeUsage(); } ////// Returns a model (C-Space) typeusage for the given member typeusage. if the type is already in c-space, it returns /// the given typeusage. The typeUsage returned is created by invoking the provider service to map from provider /// specific type to model type. /// /// EdmMember ///the respective Model (C-Space) typeusage static internal TypeUsage GetModelTypeUsage(EdmMember member) { return GetModelTypeUsage(member.TypeUsage); } ////// Checks if the edm type in the cspace type usage maps to some sspace type (called it S1). If S1 is equivalent or /// promotable to the store type in sspace type usage, then it creates a new type usage with S1 and copies all facets /// if necessary /// /// Edm property containing the cspace member type information /// edm property containing the sspace member type information /// name of the mapping file from which this information was loaded from /// lineInfo containing the line information about the cspace and sspace property mapping /// List of parsing errors - we need to add any new error to this list /// store item collection ///internal static TypeUsage ValidateAndConvertTypeUsage(EdmProperty edmProperty, EdmProperty columnProperty, Xml.IXmlLineInfo lineInfo, string sourceLocation, List parsingErrors, StoreItemCollection storeItemCollection) { Debug.Assert(edmProperty.TypeUsage.EdmType.DataSpace == DataSpace.CSpace, "cspace property must have a cspace type"); Debug.Assert(columnProperty.TypeUsage.EdmType.DataSpace == DataSpace.SSpace, "sspace type usage must have a sspace type"); Debug.Assert(Helper.IsPrimitiveType(edmProperty.TypeUsage.EdmType), "cspace property must contain a primitive type"); Debug.Assert(Helper.IsPrimitiveType(columnProperty.TypeUsage.EdmType), "sspace property must contain a primitive type"); TypeUsage mappedStoreType = ValidateAndConvertTypeUsage(edmProperty, lineInfo, sourceLocation, edmProperty.TypeUsage, columnProperty.TypeUsage, parsingErrors, storeItemCollection); return mappedStoreType; } internal static TypeUsage ValidateAndConvertTypeUsage(EdmMember edmMember, Xml.IXmlLineInfo lineInfo, string sourceLocation, TypeUsage cspaceType, TypeUsage sspaceType, List parsingErrors, StoreItemCollection storeItemCollection) { // if we are already C-Space, dont call the provider. this can happen for functions. TypeUsage modelEquivalentSspace = sspaceType; if (sspaceType.EdmType.DataSpace == DataSpace.SSpace) { modelEquivalentSspace = sspaceType.GetModelTypeUsage(); } // check that cspace type is subtype of c-space equivalent type from the ssdl definition if (TypeSemantics.IsSubTypeOf(cspaceType, modelEquivalentSspace)) { return modelEquivalentSspace; } return null; } /// /// Checks whether the given primitive type is present in the list of promotion types /// /// /// ///internal static int IsPromotableTo(IList promotionTypes, PrimitiveType primitiveType) { for (int i = 0; i < promotionTypes.Count; i++) { if (Object.ReferenceEquals(promotionTypes[i], primitiveType)) { return i; } } return -1; } #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] //--------------------------------------------------------------------- using System.Data.Mapping; using System.Diagnostics; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Text; using System.Data.Common.Utils; using System.IO; namespace System.Data.Metadata.Edm { ////// Helper Class for EDM Metadata - this class contains all the helper methods /// which needs access to internal methods. The other partial class contains all /// helper methods which just uses public methods/properties. The reason why we /// did this for allowing view gen to happen at compile time - all the helper /// methods that view gen or mapping uses are in the other helper class. Rest of the /// methods are in this class /// internal static partial class Helper { #region Fields // List of all the static empty list used all over the code internal static readonly ReadOnlyCollection> EmptyKeyValueStringObjectList = new ReadOnlyCollection >(new KeyValuePair [0]); internal static readonly ReadOnlyCollection EmptyStringList = new ReadOnlyCollection (new string[0]); internal static readonly ReadOnlyCollection EmptyFacetDescriptionEnumerable = new ReadOnlyCollection (new FacetDescription[0]); internal static readonly ReadOnlyCollection EmptyEdmFunctionReadOnlyCollection = new ReadOnlyCollection (new EdmFunction[0]); internal static readonly ReadOnlyCollection EmptyPrimitiveTypeReadOnlyCollection = new ReadOnlyCollection (new PrimitiveType[0]); internal static readonly KeyValuePair [] EmptyKeyValueStringObjectArray = new KeyValuePair [0]; internal const char PeriodSymbol = '.'; internal const char CommaSymbol = ','; #endregion #region Methods /// /// Returns the single error message from the list of errors /// /// ///static internal string CombineErrorMessage(IEnumerable errors) { Debug.Assert(errors != null); StringBuilder sb = new StringBuilder(System.Environment.NewLine); int count = 0; foreach (System.Data.Metadata.Edm.EdmSchemaError error in errors) { //Don't append a new line at the beginning of the messages if ((count++) != 0) { sb.Append(System.Environment.NewLine); } sb.Append(error.ToString()); } Debug.Assert(count!=0, "Empty Error List"); return sb.ToString(); } /// /// Returns the single error message from the list of errors /// /// ///static internal string CombineErrorMessage(IEnumerable errors) { StringBuilder sb = new StringBuilder(System.Environment.NewLine); int count = 0; foreach (EdmItemError error in errors) { // Only add the new line if this is not the first error if ((count++) != 0) { sb.Append(System.Environment.NewLine); } sb.Append(error.Message); } return sb.ToString(); } // requires: enumerations must have the same number of members // effects: returns paired enumeration values internal static IEnumerable > PairEnumerations (IBaseList left, IEnumerable right) { IEnumerator leftEnumerator = left.GetEnumerator(); IEnumeratorrightEnumerator = right.GetEnumerator(); while (leftEnumerator.MoveNext() && rightEnumerator.MoveNext()) { yield return new KeyValuePair((T)leftEnumerator.Current, rightEnumerator.Current); } yield break; } /// /// Returns a model (C-Space) typeusage for the given typeusage. if the type is already in c-space, it returns /// the given typeusage. The typeUsage returned is created by invoking the provider service to map from provider /// specific type to model type. /// /// typeusage ///the respective Model (C-Space) typeusage static internal TypeUsage GetModelTypeUsage(TypeUsage typeUsage) { return typeUsage.GetModelTypeUsage(); } ////// Returns a model (C-Space) typeusage for the given member typeusage. if the type is already in c-space, it returns /// the given typeusage. The typeUsage returned is created by invoking the provider service to map from provider /// specific type to model type. /// /// EdmMember ///the respective Model (C-Space) typeusage static internal TypeUsage GetModelTypeUsage(EdmMember member) { return GetModelTypeUsage(member.TypeUsage); } ////// Checks if the edm type in the cspace type usage maps to some sspace type (called it S1). If S1 is equivalent or /// promotable to the store type in sspace type usage, then it creates a new type usage with S1 and copies all facets /// if necessary /// /// Edm property containing the cspace member type information /// edm property containing the sspace member type information /// name of the mapping file from which this information was loaded from /// lineInfo containing the line information about the cspace and sspace property mapping /// List of parsing errors - we need to add any new error to this list /// store item collection ///internal static TypeUsage ValidateAndConvertTypeUsage(EdmProperty edmProperty, EdmProperty columnProperty, Xml.IXmlLineInfo lineInfo, string sourceLocation, List parsingErrors, StoreItemCollection storeItemCollection) { Debug.Assert(edmProperty.TypeUsage.EdmType.DataSpace == DataSpace.CSpace, "cspace property must have a cspace type"); Debug.Assert(columnProperty.TypeUsage.EdmType.DataSpace == DataSpace.SSpace, "sspace type usage must have a sspace type"); Debug.Assert(Helper.IsPrimitiveType(edmProperty.TypeUsage.EdmType), "cspace property must contain a primitive type"); Debug.Assert(Helper.IsPrimitiveType(columnProperty.TypeUsage.EdmType), "sspace property must contain a primitive type"); TypeUsage mappedStoreType = ValidateAndConvertTypeUsage(edmProperty, lineInfo, sourceLocation, edmProperty.TypeUsage, columnProperty.TypeUsage, parsingErrors, storeItemCollection); return mappedStoreType; } internal static TypeUsage ValidateAndConvertTypeUsage(EdmMember edmMember, Xml.IXmlLineInfo lineInfo, string sourceLocation, TypeUsage cspaceType, TypeUsage sspaceType, List parsingErrors, StoreItemCollection storeItemCollection) { // if we are already C-Space, dont call the provider. this can happen for functions. TypeUsage modelEquivalentSspace = sspaceType; if (sspaceType.EdmType.DataSpace == DataSpace.SSpace) { modelEquivalentSspace = sspaceType.GetModelTypeUsage(); } // check that cspace type is subtype of c-space equivalent type from the ssdl definition if (TypeSemantics.IsSubTypeOf(cspaceType, modelEquivalentSspace)) { return modelEquivalentSspace; } return null; } /// /// Checks whether the given primitive type is present in the list of promotion types /// /// /// ///internal static int IsPromotableTo(IList promotionTypes, PrimitiveType primitiveType) { for (int i = 0; i < promotionTypes.Count; i++) { if (Object.ReferenceEquals(promotionTypes[i], primitiveType)) { return i; } } return -1; } #endregion } } // 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
- Help.cs
- DataGridDetailsPresenter.cs
- BulletChrome.cs
- HwndSourceParameters.cs
- OdbcConnectionOpen.cs
- RoutedCommand.cs
- RegexCaptureCollection.cs
- WindowCollection.cs
- RedistVersionInfo.cs
- SmiEventSink_DeferedProcessing.cs
- ControlBindingsCollection.cs
- ChildDocumentBlock.cs
- EditingCommands.cs
- UInt64.cs
- Transform3DGroup.cs
- ACE.cs
- UnmanagedHandle.cs
- Brush.cs
- latinshape.cs
- DataColumnMappingCollection.cs
- ControlPaint.cs
- StringFunctions.cs
- ManagedIStream.cs
- SqlPersonalizationProvider.cs
- TTSEngineProxy.cs
- ListParaClient.cs
- ProgressBarRenderer.cs
- UnSafeCharBuffer.cs
- PeekCompletedEventArgs.cs
- InternalReceiveMessage.cs
- HttpCacheVary.cs
- Exception.cs
- WindowsAuthenticationEventArgs.cs
- LinqDataSourceView.cs
- TCPListener.cs
- SecurityUtils.cs
- TypeReference.cs
- Dictionary.cs
- DateTimeValueSerializer.cs
- ADRole.cs
- FixUp.cs
- sqlstateclientmanager.cs
- ManualResetEvent.cs
- UnsafeNativeMethods.cs
- ParseNumbers.cs
- dbenumerator.cs
- Size3D.cs
- HttpCapabilitiesBase.cs
- PathSegmentCollection.cs
- MasterPageCodeDomTreeGenerator.cs
- AxisAngleRotation3D.cs
- MenuItem.cs
- JavaScriptSerializer.cs
- ToolboxComponentsCreatingEventArgs.cs
- Transform.cs
- StaticFileHandler.cs
- ZipIOModeEnforcingStream.cs
- WindowsTreeView.cs
- ByteAnimationBase.cs
- Shared.cs
- DoubleUtil.cs
- RijndaelManaged.cs
- TileModeValidation.cs
- Track.cs
- HtmlInputRadioButton.cs
- ControlValuePropertyAttribute.cs
- SystemTcpStatistics.cs
- ButtonBase.cs
- XmlNullResolver.cs
- ClientConfigPaths.cs
- XmlSchemaException.cs
- CompiledAction.cs
- GenericsInstances.cs
- Material.cs
- WebReferenceCollection.cs
- CodeExporter.cs
- WizardStepBase.cs
- DataGridViewCellParsingEventArgs.cs
- QuaternionValueSerializer.cs
- PrivilegedConfigurationManager.cs
- TemplatedWizardStep.cs
- PreservationFileReader.cs
- ReceiveMessageRecord.cs
- FormConverter.cs
- FirstMatchCodeGroup.cs
- C14NUtil.cs
- XPathQueryGenerator.cs
- ListViewSelectEventArgs.cs
- CodeTypeConstructor.cs
- TabControl.cs
- XmlSchemaSimpleContentExtension.cs
- PropertyInformation.cs
- WSMessageEncoding.cs
- WinEventWrap.cs
- OptimalBreakSession.cs
- SqlFormatter.cs
- TextSelectionProcessor.cs
- BitStream.cs
- DataGridViewLinkCell.cs
- SmiRequestExecutor.cs