Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Data / Microsoft / SqlServer / Server / SmiMetaDataProperty.cs / 1305376 / SmiMetaDataProperty.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace Microsoft.SqlServer.Server {
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
// SmiMetaDataProperty defines an extended, optional property to be used on the SmiMetaData class
// This approach to adding properties is added combat the growing number of sparsely-used properties
// that are specially handled on the base classes
internal enum SmiPropertySelector {
DefaultFields = 0x0,
SortOrder = 0x1,
UniqueKey = 0x2,
}
// Simple collection for properties. Could extend to IDictionary support if needed in future.
internal class SmiMetaDataPropertyCollection {
private const int SelectorCount = 3; // number of elements in SmiPropertySelector
private SmiMetaDataProperty[] _properties;
private bool _isReadOnly;
internal static readonly SmiMetaDataPropertyCollection EmptyInstance;
// Singleton empty instances to ensure each property is always non-null
private static readonly SmiDefaultFieldsProperty __emptyDefaultFields = new SmiDefaultFieldsProperty(new List());
private static readonly SmiOrderProperty __emptySortOrder = new SmiOrderProperty(new List());
private static readonly SmiUniqueKeyProperty __emptyUniqueKey = new SmiUniqueKeyProperty(new List());
static SmiMetaDataPropertyCollection() {
EmptyInstance = new SmiMetaDataPropertyCollection();
EmptyInstance.SetReadOnly();
}
internal SmiMetaDataPropertyCollection() {
_properties = new SmiMetaDataProperty[SelectorCount];
_isReadOnly = false;
_properties[(int)SmiPropertySelector.DefaultFields] = __emptyDefaultFields;
_properties[(int)SmiPropertySelector.SortOrder] = __emptySortOrder;
_properties[(int)SmiPropertySelector.UniqueKey] = __emptyUniqueKey;
}
internal SmiMetaDataProperty this[SmiPropertySelector key] {
get {
return _properties[(int)key];
}
set {
if (null == value) {
throw ADP.InternalError(ADP.InternalErrorCode.InvalidSmiCall);
}
EnsureWritable();
_properties[(int)key] = value;
}
}
internal bool IsReadOnly {
get {
return _isReadOnly;
}
}
internal IEnumerable Values {
get {
return new List(_properties);
}
}
// Allow switching to read only, but not back.
internal void SetReadOnly() {
_isReadOnly = true;
}
private void EnsureWritable() {
if (IsReadOnly) {
throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
}
}
}
// Base class for properties
internal abstract class SmiMetaDataProperty {
internal abstract string TraceString();
}
// Property defining a list of column ordinals that define a unique key
internal class SmiUniqueKeyProperty : SmiMetaDataProperty {
private IList _columns;
internal SmiUniqueKeyProperty(IList columnIsKey) {
_columns = new List(columnIsKey).AsReadOnly();
}
// indexed by column ordinal indicating for each column whether it is key or not
internal bool this[int ordinal] {
get {
if (_columns.Count <= ordinal) {
return false;
}
else {
return _columns[ordinal];
}
}
}
[Conditional("DEBUG")]
internal void CheckCount(int countToMatch) {
Debug.Assert(0 == _columns.Count || countToMatch == _columns.Count,
"SmiDefaultFieldsProperty.CheckCount: DefaultFieldsProperty size (" + _columns.Count +
") not equal to checked size (" + countToMatch + ")" );
}
internal override string TraceString() {
string returnValue = "UniqueKey(";
bool delimit = false;
for (int columnOrd = 0; columnOrd < _columns.Count; columnOrd++) {
if (delimit) {
returnValue += ",";
}
else {
delimit = true;
}
if (_columns[columnOrd]) {
returnValue += columnOrd.ToString(CultureInfo.InvariantCulture);
}
}
returnValue += ")";
return returnValue;
}
}
// Property defining a sort order for a set of columns (by ordinal and ASC/DESC).
internal class SmiOrderProperty : SmiMetaDataProperty {
internal struct SmiColumnOrder {
internal int SortOrdinal;
internal SortOrder Order;
internal string TraceString() {
return String.Format(CultureInfo.InvariantCulture, "{0} {1}", SortOrdinal, Order);
}
}
private IList _columns;
internal SmiOrderProperty(IList columnOrders) {
_columns = new List(columnOrders).AsReadOnly();
}
// Readonly list of the columnorder instances making up the sort order
// order in list indicates precedence
internal SmiColumnOrder this[int ordinal] {
get {
if (_columns.Count <= ordinal) {
SmiColumnOrder order = new SmiColumnOrder();
order.Order = SortOrder.Unspecified;
order.SortOrdinal = -1;
return order;
}
else {
return _columns[ordinal];
}
}
}
[Conditional("DEBUG")]
internal void CheckCount(int countToMatch) {
Debug.Assert(0 == _columns.Count || countToMatch == _columns.Count,
"SmiDefaultFieldsProperty.CheckCount: DefaultFieldsProperty size (" + _columns.Count +
") not equal to checked size (" + countToMatch + ")" );
}
internal override string TraceString() {
string returnValue = "SortOrder(";
bool delimit = false;
foreach(SmiColumnOrder columnOrd in _columns) {
if (delimit) {
returnValue += ",";
}
else {
delimit = true;
}
if (System.Data.SqlClient.SortOrder.Unspecified != columnOrd.Order) {
returnValue += columnOrd.TraceString();
}
}
returnValue += ")";
return returnValue;
}
}
// property defining inheritance relationship(s)
internal class SmiDefaultFieldsProperty : SmiMetaDataProperty {
#region private fields
private IList _defaults;
#endregion
#region internal interface
internal SmiDefaultFieldsProperty(IList defaultFields) {
_defaults = new List(defaultFields).AsReadOnly();
}
internal bool this[int ordinal] {
get {
if (_defaults.Count <= ordinal) {
return false;
}
else {
return _defaults[ordinal];
}
}
}
[Conditional("DEBUG")]
internal void CheckCount(int countToMatch) {
Debug.Assert(0 == _defaults.Count || countToMatch == _defaults.Count,
"SmiDefaultFieldsProperty.CheckCount: DefaultFieldsProperty size (" + _defaults.Count +
") not equal to checked size (" + countToMatch + ")" );
}
internal override string TraceString() {
string returnValue = "DefaultFields(";
bool delimit = false;
for(int columnOrd = 0; columnOrd < _defaults.Count; columnOrd++) {
if (delimit) {
returnValue += ",";
}
else {
delimit = true;
}
if (_defaults[columnOrd]) {
returnValue += columnOrd;
}
}
returnValue += ")";
return returnValue;
}
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// [....]
// [....]
//-----------------------------------------------------------------------------
namespace Microsoft.SqlServer.Server {
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
// SmiMetaDataProperty defines an extended, optional property to be used on the SmiMetaData class
// This approach to adding properties is added combat the growing number of sparsely-used properties
// that are specially handled on the base classes
internal enum SmiPropertySelector {
DefaultFields = 0x0,
SortOrder = 0x1,
UniqueKey = 0x2,
}
// Simple collection for properties. Could extend to IDictionary support if needed in future.
internal class SmiMetaDataPropertyCollection {
private const int SelectorCount = 3; // number of elements in SmiPropertySelector
private SmiMetaDataProperty[] _properties;
private bool _isReadOnly;
internal static readonly SmiMetaDataPropertyCollection EmptyInstance;
// Singleton empty instances to ensure each property is always non-null
private static readonly SmiDefaultFieldsProperty __emptyDefaultFields = new SmiDefaultFieldsProperty(new List());
private static readonly SmiOrderProperty __emptySortOrder = new SmiOrderProperty(new List());
private static readonly SmiUniqueKeyProperty __emptyUniqueKey = new SmiUniqueKeyProperty(new List());
static SmiMetaDataPropertyCollection() {
EmptyInstance = new SmiMetaDataPropertyCollection();
EmptyInstance.SetReadOnly();
}
internal SmiMetaDataPropertyCollection() {
_properties = new SmiMetaDataProperty[SelectorCount];
_isReadOnly = false;
_properties[(int)SmiPropertySelector.DefaultFields] = __emptyDefaultFields;
_properties[(int)SmiPropertySelector.SortOrder] = __emptySortOrder;
_properties[(int)SmiPropertySelector.UniqueKey] = __emptyUniqueKey;
}
internal SmiMetaDataProperty this[SmiPropertySelector key] {
get {
return _properties[(int)key];
}
set {
if (null == value) {
throw ADP.InternalError(ADP.InternalErrorCode.InvalidSmiCall);
}
EnsureWritable();
_properties[(int)key] = value;
}
}
internal bool IsReadOnly {
get {
return _isReadOnly;
}
}
internal IEnumerable Values {
get {
return new List(_properties);
}
}
// Allow switching to read only, but not back.
internal void SetReadOnly() {
_isReadOnly = true;
}
private void EnsureWritable() {
if (IsReadOnly) {
throw System.Data.Common.ADP.InternalError(System.Data.Common.ADP.InternalErrorCode.InvalidSmiCall);
}
}
}
// Base class for properties
internal abstract class SmiMetaDataProperty {
internal abstract string TraceString();
}
// Property defining a list of column ordinals that define a unique key
internal class SmiUniqueKeyProperty : SmiMetaDataProperty {
private IList _columns;
internal SmiUniqueKeyProperty(IList columnIsKey) {
_columns = new List(columnIsKey).AsReadOnly();
}
// indexed by column ordinal indicating for each column whether it is key or not
internal bool this[int ordinal] {
get {
if (_columns.Count <= ordinal) {
return false;
}
else {
return _columns[ordinal];
}
}
}
[Conditional("DEBUG")]
internal void CheckCount(int countToMatch) {
Debug.Assert(0 == _columns.Count || countToMatch == _columns.Count,
"SmiDefaultFieldsProperty.CheckCount: DefaultFieldsProperty size (" + _columns.Count +
") not equal to checked size (" + countToMatch + ")" );
}
internal override string TraceString() {
string returnValue = "UniqueKey(";
bool delimit = false;
for (int columnOrd = 0; columnOrd < _columns.Count; columnOrd++) {
if (delimit) {
returnValue += ",";
}
else {
delimit = true;
}
if (_columns[columnOrd]) {
returnValue += columnOrd.ToString(CultureInfo.InvariantCulture);
}
}
returnValue += ")";
return returnValue;
}
}
// Property defining a sort order for a set of columns (by ordinal and ASC/DESC).
internal class SmiOrderProperty : SmiMetaDataProperty {
internal struct SmiColumnOrder {
internal int SortOrdinal;
internal SortOrder Order;
internal string TraceString() {
return String.Format(CultureInfo.InvariantCulture, "{0} {1}", SortOrdinal, Order);
}
}
private IList _columns;
internal SmiOrderProperty(IList columnOrders) {
_columns = new List(columnOrders).AsReadOnly();
}
// Readonly list of the columnorder instances making up the sort order
// order in list indicates precedence
internal SmiColumnOrder this[int ordinal] {
get {
if (_columns.Count <= ordinal) {
SmiColumnOrder order = new SmiColumnOrder();
order.Order = SortOrder.Unspecified;
order.SortOrdinal = -1;
return order;
}
else {
return _columns[ordinal];
}
}
}
[Conditional("DEBUG")]
internal void CheckCount(int countToMatch) {
Debug.Assert(0 == _columns.Count || countToMatch == _columns.Count,
"SmiDefaultFieldsProperty.CheckCount: DefaultFieldsProperty size (" + _columns.Count +
") not equal to checked size (" + countToMatch + ")" );
}
internal override string TraceString() {
string returnValue = "SortOrder(";
bool delimit = false;
foreach(SmiColumnOrder columnOrd in _columns) {
if (delimit) {
returnValue += ",";
}
else {
delimit = true;
}
if (System.Data.SqlClient.SortOrder.Unspecified != columnOrd.Order) {
returnValue += columnOrd.TraceString();
}
}
returnValue += ")";
return returnValue;
}
}
// property defining inheritance relationship(s)
internal class SmiDefaultFieldsProperty : SmiMetaDataProperty {
#region private fields
private IList _defaults;
#endregion
#region internal interface
internal SmiDefaultFieldsProperty(IList defaultFields) {
_defaults = new List(defaultFields).AsReadOnly();
}
internal bool this[int ordinal] {
get {
if (_defaults.Count <= ordinal) {
return false;
}
else {
return _defaults[ordinal];
}
}
}
[Conditional("DEBUG")]
internal void CheckCount(int countToMatch) {
Debug.Assert(0 == _defaults.Count || countToMatch == _defaults.Count,
"SmiDefaultFieldsProperty.CheckCount: DefaultFieldsProperty size (" + _defaults.Count +
") not equal to checked size (" + countToMatch + ")" );
}
internal override string TraceString() {
string returnValue = "DefaultFields(";
bool delimit = false;
for(int columnOrd = 0; columnOrd < _defaults.Count; columnOrd++) {
if (delimit) {
returnValue += ",";
}
else {
delimit = true;
}
if (_defaults[columnOrd]) {
returnValue += columnOrd;
}
}
returnValue += ")";
return returnValue;
}
#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
- StringSorter.cs
- CodeTypeMemberCollection.cs
- OleDbConnectionFactory.cs
- HwndHostAutomationPeer.cs
- DataGridViewTopLeftHeaderCell.cs
- SerializableAttribute.cs
- EdmProperty.cs
- ColumnWidthChangingEvent.cs
- TimeZoneInfo.cs
- BoundColumn.cs
- DataGridViewCellPaintingEventArgs.cs
- WriteableBitmap.cs
- Margins.cs
- WebPartConnectVerb.cs
- HttpModulesSection.cs
- ImageListUtils.cs
- DataGridDesigner.cs
- MaterializeFromAtom.cs
- HttpBrowserCapabilitiesBase.cs
- BlurBitmapEffect.cs
- PenThread.cs
- Vector3dCollection.cs
- FlowLayout.cs
- Scheduler.cs
- XmlElementAttribute.cs
- VScrollProperties.cs
- ConfigurationSettings.cs
- WebPartsSection.cs
- DataGridViewImageColumn.cs
- SessionState.cs
- RowToParametersTransformer.cs
- WizardSideBarListControlItem.cs
- Point.cs
- RootProfilePropertySettingsCollection.cs
- Encoder.cs
- BindingCollection.cs
- CryptoApi.cs
- EdmRelationshipRoleAttribute.cs
- BitmapEffectInput.cs
- CollectionChangedEventManager.cs
- CompositeClientFormatter.cs
- GridPattern.cs
- DesignerAdapterUtil.cs
- Int32CollectionValueSerializer.cs
- DoubleLinkList.cs
- DataGridViewRowStateChangedEventArgs.cs
- IPPacketInformation.cs
- LayoutUtils.cs
- OleDbParameterCollection.cs
- SelectionItemProviderWrapper.cs
- EncodingStreamWrapper.cs
- PersonalizationProvider.cs
- DataGridViewCellParsingEventArgs.cs
- DataViewSettingCollection.cs
- UnSafeCharBuffer.cs
- Screen.cs
- IListConverters.cs
- ComEventsInfo.cs
- VariantWrapper.cs
- DbgUtil.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- BoundField.cs
- WebPartAuthorizationEventArgs.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- InputMethodStateTypeInfo.cs
- ReturnType.cs
- MsmqInputMessagePool.cs
- BezierSegment.cs
- ResourceReader.cs
- CodeTypeReferenceCollection.cs
- ZipIOExtraFieldPaddingElement.cs
- RegisteredExpandoAttribute.cs
- StateChangeEvent.cs
- WebPartsPersonalization.cs
- coordinatorscratchpad.cs
- HttpHandlerActionCollection.cs
- SystemPens.cs
- HttpChannelHelper.cs
- ConstNode.cs
- ConfigurationElement.cs
- DataPagerFieldCollection.cs
- AccessibleObject.cs
- XmlMemberMapping.cs
- StandardToolWindows.cs
- CoTaskMemHandle.cs
- WinEventWrap.cs
- IfElseDesigner.xaml.cs
- ThreadStaticAttribute.cs
- ScrollBarRenderer.cs
- SiteMapNode.cs
- UIElementPropertyUndoUnit.cs
- QueryOperationResponseOfT.cs
- ConnectionPoint.cs
- CalendarDateRange.cs
- HostingEnvironmentSection.cs
- WindowsTreeView.cs
- WinFormsSpinner.cs
- Bold.cs
- CornerRadiusConverter.cs
- EventProxy.cs