Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / System / Windows / UncommonField.cs / 1 / UncommonField.cs
using System; using System.Diagnostics; using System.Security.Permissions; using MS.Internal.WindowsBase; // for FriendAccessAllowed namespace System.Windows { ////// /// //CASRemoval:[StrongNameIdentityPermissionAttribute(SecurityAction.InheritanceDemand, PublicKey=Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)] [FriendAccessAllowed] // Built into Base, used by Core and Framework internal class UncommonField{ /// /// Create a new UncommonField. /// public UncommonField() : this(default(T)) { } ////// Create a new UncommonField. /// /// The default value of the field. public UncommonField(T defaultValue) { _defaultValue = defaultValue; _hasBeenSet = false; lock (DependencyProperty.Synchronized) { _globalIndex = DependencyProperty.GetUniqueGlobalIndex(null, null); DependencyProperty.RegisteredPropertyList.Add(); } } ////// Write the given value onto a DependencyObject instance. /// /// The DependencyObject on which to set the value. /// The value to set. public void SetValue(DependencyObject instance, T value) { if (instance != null) { EntryIndex entryIndex = instance.LookupEntry(_globalIndex); // Set the value if it's not the default, otherwise remove the value. if (!object.ReferenceEquals(value, _defaultValue)) { instance.SetEffectiveValue(entryIndex, null /* dp */, _globalIndex, null /* metadata */, value, BaseValueSourceInternal.Local); _hasBeenSet = true; } else { instance.UnsetEffectiveValue(entryIndex, null /* dp */, null /* metadata */); } } else { throw new ArgumentNullException("instance"); } } ////// Read the value of this field on a DependencyObject instance. /// /// The DependencyObject from which to get the value. ///public T GetValue(DependencyObject instance) { if (instance != null) { if (_hasBeenSet) { EntryIndex entryIndex = instance.LookupEntry(_globalIndex); if (entryIndex.Found) { object value = instance.EffectiveValues[entryIndex.Index].LocalValue; if (value != DependencyProperty.UnsetValue) { return (T)value; } } return _defaultValue; } else { return _defaultValue; } } else { throw new ArgumentNullException("instance"); } } /// /// Clear this field from the given DependencyObject instance. /// /// public void ClearValue(DependencyObject instance) { if (instance != null) { EntryIndex entryIndex = instance.LookupEntry(_globalIndex); instance.UnsetEffectiveValue(entryIndex, null /* dp */, null /* metadata */); } else { throw new ArgumentNullException("instance"); } } internal int GlobalIndex { get { return _globalIndex; } } #region Private Fields private T _defaultValue; private int _globalIndex; private bool _hasBeenSet; #endregion } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Diagnostics; using System.Security.Permissions; using MS.Internal.WindowsBase; // for FriendAccessAllowed namespace System.Windows { ////// /// //CASRemoval:[StrongNameIdentityPermissionAttribute(SecurityAction.InheritanceDemand, PublicKey=Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)] [FriendAccessAllowed] // Built into Base, used by Core and Framework internal class UncommonField{ /// /// Create a new UncommonField. /// public UncommonField() : this(default(T)) { } ////// Create a new UncommonField. /// /// The default value of the field. public UncommonField(T defaultValue) { _defaultValue = defaultValue; _hasBeenSet = false; lock (DependencyProperty.Synchronized) { _globalIndex = DependencyProperty.GetUniqueGlobalIndex(null, null); DependencyProperty.RegisteredPropertyList.Add(); } } ////// Write the given value onto a DependencyObject instance. /// /// The DependencyObject on which to set the value. /// The value to set. public void SetValue(DependencyObject instance, T value) { if (instance != null) { EntryIndex entryIndex = instance.LookupEntry(_globalIndex); // Set the value if it's not the default, otherwise remove the value. if (!object.ReferenceEquals(value, _defaultValue)) { instance.SetEffectiveValue(entryIndex, null /* dp */, _globalIndex, null /* metadata */, value, BaseValueSourceInternal.Local); _hasBeenSet = true; } else { instance.UnsetEffectiveValue(entryIndex, null /* dp */, null /* metadata */); } } else { throw new ArgumentNullException("instance"); } } ////// Read the value of this field on a DependencyObject instance. /// /// The DependencyObject from which to get the value. ///public T GetValue(DependencyObject instance) { if (instance != null) { if (_hasBeenSet) { EntryIndex entryIndex = instance.LookupEntry(_globalIndex); if (entryIndex.Found) { object value = instance.EffectiveValues[entryIndex.Index].LocalValue; if (value != DependencyProperty.UnsetValue) { return (T)value; } } return _defaultValue; } else { return _defaultValue; } } else { throw new ArgumentNullException("instance"); } } /// /// Clear this field from the given DependencyObject instance. /// /// public void ClearValue(DependencyObject instance) { if (instance != null) { EntryIndex entryIndex = instance.LookupEntry(_globalIndex); instance.UnsetEffectiveValue(entryIndex, null /* dp */, null /* metadata */); } else { throw new ArgumentNullException("instance"); } } internal int GlobalIndex { get { return _globalIndex; } } #region Private Fields private T _defaultValue; private int _globalIndex; private bool _hasBeenSet; #endregion } } // 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
- OleDbConnectionPoolGroupProviderInfo.cs
- xmlglyphRunInfo.cs
- __FastResourceComparer.cs
- ScriptResourceInfo.cs
- LayoutUtils.cs
- ProviderSettings.cs
- FieldBuilder.cs
- ActivityTrace.cs
- Clipboard.cs
- InvalidCommandTreeException.cs
- MarshalDirectiveException.cs
- SoundPlayerAction.cs
- precedingquery.cs
- StatusStrip.cs
- WorkerRequest.cs
- Merger.cs
- LineSegment.cs
- SolidBrush.cs
- DesignerActionItem.cs
- ListViewUpdatedEventArgs.cs
- TextContainerHelper.cs
- _ChunkParse.cs
- CommandSet.cs
- RecordConverter.cs
- CodeComment.cs
- Line.cs
- MatrixTransform.cs
- XslException.cs
- CodeParameterDeclarationExpressionCollection.cs
- StatusStrip.cs
- WebPartConnectionsConnectVerb.cs
- BuildProvider.cs
- QilIterator.cs
- HttpDictionary.cs
- CompiledQuery.cs
- TextBlockAutomationPeer.cs
- WebServiceMethodData.cs
- GridViewRowCollection.cs
- BamlLocalizableResource.cs
- EntityDataSourceContextCreatedEventArgs.cs
- _ConnectStream.cs
- ListDictionaryInternal.cs
- ArrayHelper.cs
- XmlSerializationReader.cs
- Path.cs
- TextProperties.cs
- SecurityException.cs
- XmlTextWriter.cs
- CompilerErrorCollection.cs
- CrossAppDomainChannel.cs
- TypeDefinition.cs
- AppDomainFactory.cs
- TextTreeInsertElementUndoUnit.cs
- InputBinding.cs
- XmlWellformedWriter.cs
- HitTestParameters.cs
- Calendar.cs
- MimeTypeAttribute.cs
- SoapFaultCodes.cs
- IxmlLineInfo.cs
- IntMinMaxAggregationOperator.cs
- ReadOnlyObservableCollection.cs
- SqlProviderManifest.cs
- FormViewCommandEventArgs.cs
- ArraySortHelper.cs
- LicenseContext.cs
- ExistsInCollection.cs
- RSAPKCS1SignatureFormatter.cs
- GridViewRowPresenterBase.cs
- AxImporter.cs
- SocketManager.cs
- UnicastIPAddressInformationCollection.cs
- DesigntimeLicenseContext.cs
- CachedTypeface.cs
- CompressionTracing.cs
- WebPartUserCapability.cs
- ButtonDesigner.cs
- HighContrastHelper.cs
- DbConnectionHelper.cs
- DrawingAttributesDefaultValueFactory.cs
- XmlMapping.cs
- BaseParser.cs
- _LocalDataStore.cs
- SourceSwitch.cs
- Int16Converter.cs
- PropertyFilterAttribute.cs
- CryptoConfig.cs
- PartitionerQueryOperator.cs
- XamlClipboardData.cs
- XmlWriterSettings.cs
- MD5HashHelper.cs
- InfoCardTrace.cs
- WebPartConnectVerb.cs
- Point3D.cs
- XmlReaderSettings.cs
- LinqDataSourceInsertEventArgs.cs
- ObjectStateFormatter.cs
- IndexedWhereQueryOperator.cs
- TextRange.cs
- XPathParser.cs