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 Dictionary m_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 Dictionary m_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
- RijndaelManagedTransform.cs
- AnnotationResource.cs
- DeclaredTypeValidatorAttribute.cs
- DataGridViewCellPaintingEventArgs.cs
- ObjectHandle.cs
- CardSpaceSelector.cs
- HealthMonitoringSection.cs
- InvokeMemberBinder.cs
- RijndaelManagedTransform.cs
- HttpInputStream.cs
- QilLoop.cs
- Point4D.cs
- RenderingBiasValidation.cs
- OSFeature.cs
- SecurityRuntime.cs
- MailDefinition.cs
- DbProviderSpecificTypePropertyAttribute.cs
- Control.cs
- cookiecollection.cs
- CodeChecksumPragma.cs
- Soap.cs
- GcHandle.cs
- NestPullup.cs
- XmlAggregates.cs
- KoreanCalendar.cs
- OrderByBuilder.cs
- FunctionGenerator.cs
- Condition.cs
- XmlSchemaAll.cs
- LocalizabilityAttribute.cs
- MenuItem.cs
- BulletedList.cs
- XmlNavigatorFilter.cs
- DiscoveryDefaults.cs
- XmlSiteMapProvider.cs
- RectValueSerializer.cs
- SpotLight.cs
- DateTime.cs
- MatrixTransform.cs
- WorkflowRuntimeSection.cs
- ApplicationInfo.cs
- XamlVector3DCollectionSerializer.cs
- HtmlAnchor.cs
- QilUnary.cs
- DataGridViewCellMouseEventArgs.cs
- SqlTriggerContext.cs
- WmlObjectListAdapter.cs
- Cursor.cs
- OutputCache.cs
- WebPartEditorCancelVerb.cs
- XsltFunctions.cs
- AttachedPropertyBrowsableAttribute.cs
- RoutedEventValueSerializer.cs
- ProfileSettings.cs
- IDReferencePropertyAttribute.cs
- SystemResourceHost.cs
- MbpInfo.cs
- SqlProfileProvider.cs
- PixelFormatConverter.cs
- OdbcReferenceCollection.cs
- UnsupportedPolicyOptionsException.cs
- COM2ICategorizePropertiesHandler.cs
- SizeFConverter.cs
- TypeExtension.cs
- MarshalByRefObject.cs
- PropertyValueUIItem.cs
- SecurityHelper.cs
- FullTextLine.cs
- PrintControllerWithStatusDialog.cs
- ParseHttpDate.cs
- FixedSOMTableRow.cs
- SevenBitStream.cs
- Win32KeyboardDevice.cs
- SuppressIldasmAttribute.cs
- DataGridViewCellValidatingEventArgs.cs
- StoryFragments.cs
- HyperLink.cs
- CreateUserWizard.cs
- ForwardPositionQuery.cs
- HwndSourceParameters.cs
- NativeMethods.cs
- XslVisitor.cs
- TypedColumnHandler.cs
- XmlAnyElementAttributes.cs
- DriveInfo.cs
- SystemNetworkInterface.cs
- BufferBuilder.cs
- InputReportEventArgs.cs
- IsolatedStoragePermission.cs
- Style.cs
- BackoffTimeoutHelper.cs
- WorkflowPageSetupDialog.cs
- EmbeddedObject.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs
- XmlExceptionHelper.cs
- BufferedStream.cs
- XPathChildIterator.cs
- StringOutput.cs
- RoleManagerEventArgs.cs
- DataServiceQueryContinuation.cs