Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / System / Data / SqlClient / SqlUdtInfo.cs / 1305376 / SqlUdtInfo.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All Rights Reserved. // Information Contained Herein is Proprietary and Confidential. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.SqlClient { using System; using System.Collections; using System.Collections.Generic; using System.Data.Common; using System.Data.Sql; using System.Data.SqlTypes; using System.Diagnostics; using System.Text; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Reflection.Emit; using System.Security.Permissions; using Microsoft.SqlServer.Server; internal class SqlUdtInfo { internal readonly Microsoft.SqlServer.Server.Format SerializationFormat; internal readonly bool IsByteOrdered; internal readonly bool IsFixedLength; internal readonly int MaxByteSize; internal readonly string Name; internal readonly string ValidationMethodName; private SqlUdtInfo(Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute attr) { SerializationFormat = (Microsoft.SqlServer.Server.Format)attr.Format; IsByteOrdered = attr.IsByteOrdered; IsFixedLength = attr.IsFixedLength; MaxByteSize = attr.MaxByteSize; Name = attr.Name; ValidationMethodName= attr.ValidationMethodName; } internal static SqlUdtInfo GetFromType(Type target) { SqlUdtInfo udtAttr = TryGetFromType(target); if (udtAttr == null) { throw InvalidUdtException.Create(target, Res.SqlUdtReason_NoUdtAttribute); } return udtAttr; } // VSTFDEVDIV 479671: Type.GetCustomAttributes is an time-expensive call. // Improve UDT serialization performance by caching the resulted UDT type information using type-safe dictionary. // Use a per-thread cache, so we do not need to synchronize access to it [ThreadStatic] private static Dictionarym_types2UdtInfo; internal static SqlUdtInfo TryGetFromType(Type target) { if (m_types2UdtInfo == null) m_types2UdtInfo = new Dictionary (); SqlUdtInfo udtAttr = null; if (!m_types2UdtInfo.TryGetValue(target, out udtAttr)) { // query SqlUserDefinedTypeAttribute first time and cache the result object[] attr = target.GetCustomAttributes(typeof(Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute), false); if (attr != null && attr.Length == 1) { udtAttr = new SqlUdtInfo((Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute)attr[0]); } m_types2UdtInfo.Add(target, udtAttr); } return udtAttr; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All Rights Reserved. // Information Contained Herein is Proprietary and Confidential. // //[....] //[....] //----------------------------------------------------------------------------- namespace System.Data.SqlClient { using System; using System.Collections; using System.Collections.Generic; using System.Data.Common; using System.Data.Sql; using System.Data.SqlTypes; using System.Diagnostics; using System.Text; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Reflection.Emit; using System.Security.Permissions; using Microsoft.SqlServer.Server; internal class SqlUdtInfo { internal readonly Microsoft.SqlServer.Server.Format SerializationFormat; internal readonly bool IsByteOrdered; internal readonly bool IsFixedLength; internal readonly int MaxByteSize; internal readonly string Name; internal readonly string ValidationMethodName; private SqlUdtInfo(Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute attr) { SerializationFormat = (Microsoft.SqlServer.Server.Format)attr.Format; IsByteOrdered = attr.IsByteOrdered; IsFixedLength = attr.IsFixedLength; MaxByteSize = attr.MaxByteSize; Name = attr.Name; ValidationMethodName= attr.ValidationMethodName; } internal static SqlUdtInfo GetFromType(Type target) { SqlUdtInfo udtAttr = TryGetFromType(target); if (udtAttr == null) { throw InvalidUdtException.Create(target, Res.SqlUdtReason_NoUdtAttribute); } return udtAttr; } // VSTFDEVDIV 479671: Type.GetCustomAttributes is an time-expensive call. // Improve UDT serialization performance by caching the resulted UDT type information using type-safe dictionary. // Use a per-thread cache, so we do not need to synchronize access to it [ThreadStatic] private static Dictionarym_types2UdtInfo; internal static SqlUdtInfo TryGetFromType(Type target) { if (m_types2UdtInfo == null) m_types2UdtInfo = new Dictionary (); SqlUdtInfo udtAttr = null; if (!m_types2UdtInfo.TryGetValue(target, out udtAttr)) { // query SqlUserDefinedTypeAttribute first time and cache the result object[] attr = target.GetCustomAttributes(typeof(Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute), false); if (attr != null && attr.Length == 1) { udtAttr = new SqlUdtInfo((Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute)attr[0]); } m_types2UdtInfo.Add(target, udtAttr); } return udtAttr; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ArrangedElementCollection.cs
- TextDecorations.cs
- SoapAttributeAttribute.cs
- PenContext.cs
- ProfileGroupSettingsCollection.cs
- PeerNeighborManager.cs
- ObjectListCommandEventArgs.cs
- ManagementException.cs
- BinaryCommonClasses.cs
- VisualBasicDesignerHelper.cs
- RealProxy.cs
- SortKey.cs
- RemoteWebConfigurationHostStream.cs
- ArgumentOutOfRangeException.cs
- BinaryNode.cs
- processwaithandle.cs
- TemplateContentLoader.cs
- ChtmlCommandAdapter.cs
- Wizard.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- SerialStream.cs
- AssemblyBuilder.cs
- FloaterParaClient.cs
- ConfigurationLocation.cs
- CommonObjectSecurity.cs
- MemoryFailPoint.cs
- CodeLabeledStatement.cs
- NavigationPropertySingletonExpression.cs
- ADMembershipUser.cs
- ProxyAttribute.cs
- BCLDebug.cs
- CompensatableTransactionScopeActivity.cs
- HtmlHead.cs
- RectangleHotSpot.cs
- TraceSection.cs
- LineServicesRun.cs
- BindingMAnagerBase.cs
- PolyQuadraticBezierSegmentFigureLogic.cs
- GridItemPatternIdentifiers.cs
- TdsValueSetter.cs
- EditorPartCollection.cs
- ChildDocumentBlock.cs
- PropertyReferenceSerializer.cs
- WindowInteractionStateTracker.cs
- AttributeInfo.cs
- PolicyValidationException.cs
- BuildResultCache.cs
- XmlSchemaAll.cs
- BitmapMetadataEnumerator.cs
- _UncName.cs
- ValidationRuleCollection.cs
- Translator.cs
- FamilyMapCollection.cs
- Substitution.cs
- TypeInitializationException.cs
- SessionIDManager.cs
- StringArrayConverter.cs
- DataGridViewCheckBoxColumn.cs
- SmtpNegotiateAuthenticationModule.cs
- StringFormat.cs
- TypeLoadException.cs
- SQLInt64Storage.cs
- ContractMapping.cs
- UserThread.cs
- DataGridViewTextBoxCell.cs
- BodyWriter.cs
- ObjectDataSourceSelectingEventArgs.cs
- ComplexPropertyEntry.cs
- _UncName.cs
- AssemblyBuilder.cs
- GridViewUpdateEventArgs.cs
- XPathBinder.cs
- ToolBar.cs
- AccessDataSourceWizardForm.cs
- TextDecorationLocationValidation.cs
- Frame.cs
- ImageSource.cs
- RectangleGeometry.cs
- CompletionCallbackWrapper.cs
- BinaryReader.cs
- TraceInternal.cs
- WebPartManager.cs
- HGlobalSafeHandle.cs
- GeneralEndpointIdentity.cs
- Camera.cs
- BackgroundWorker.cs
- DataQuery.cs
- SoapAttributeOverrides.cs
- OpCodes.cs
- ConnectionConsumerAttribute.cs
- TextServicesCompartmentEventSink.cs
- TimeSpanValidator.cs
- NativeMethods.cs
- BrowserTree.cs
- IgnoreFileBuildProvider.cs
- SafeRightsManagementSessionHandle.cs
- ObjectAnimationUsingKeyFrames.cs
- CLRBindingWorker.cs
- DBSqlParserColumnCollection.cs
- WorkflowViewElement.cs