Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / System / Windows / UncommonField.cs / 1305600 / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SecurityDocument.cs
- ObjectIDGenerator.cs
- Oid.cs
- SQLMoney.cs
- JournalEntryListConverter.cs
- ModulesEntry.cs
- DragEventArgs.cs
- UpdateCommand.cs
- XmlSerializationWriter.cs
- DirectoryNotFoundException.cs
- CompressEmulationStream.cs
- ViewCellSlot.cs
- IgnoreFileBuildProvider.cs
- RealProxy.cs
- PreviewPageInfo.cs
- ConditionalExpression.cs
- MarkupWriter.cs
- TreeIterator.cs
- RemotingServices.cs
- CacheDependency.cs
- Missing.cs
- ReferenceList.cs
- FormsAuthenticationEventArgs.cs
- ContentPlaceHolder.cs
- odbcmetadatacollectionnames.cs
- PathFigure.cs
- WorkflowFileItem.cs
- ElementHostPropertyMap.cs
- SR.cs
- DbProviderFactories.cs
- SqlParameter.cs
- RenderingBiasValidation.cs
- WorkflowOperationBehavior.cs
- PlatformNotSupportedException.cs
- NumberFormatter.cs
- DataGridViewRowErrorTextNeededEventArgs.cs
- PerfService.cs
- WebPartUtil.cs
- AvTraceDetails.cs
- SynchronizationContext.cs
- RSAPKCS1KeyExchangeFormatter.cs
- FunctionDescription.cs
- GridViewRow.cs
- SessionEndingCancelEventArgs.cs
- OrderPreservingSpoolingTask.cs
- StartUpEventArgs.cs
- PerformanceCounterCategory.cs
- Vector.cs
- CompensatableTransactionScopeActivityDesigner.cs
- BezierSegment.cs
- WinEventWrap.cs
- CompressStream.cs
- TableLayoutStyleCollection.cs
- HitTestWithGeometryDrawingContextWalker.cs
- InstanceDataCollection.cs
- CalendarKeyboardHelper.cs
- ServiceEndpointElement.cs
- Tuple.cs
- XmlProcessingInstruction.cs
- StandardBindingElement.cs
- _Win32.cs
- MediaContext.cs
- Point.cs
- SessionStateModule.cs
- SmtpFailedRecipientsException.cs
- OperationResponse.cs
- StringExpressionSet.cs
- UpdatePanelTriggerCollection.cs
- PageSetupDialog.cs
- CompiledQuery.cs
- ExcCanonicalXml.cs
- RichTextBox.cs
- SqlDataSourceCache.cs
- RichTextBoxAutomationPeer.cs
- EntityDataSourceDesigner.cs
- XmlDocumentSurrogate.cs
- SQLGuidStorage.cs
- RSACryptoServiceProvider.cs
- AxImporter.cs
- X509CertificateInitiatorClientCredential.cs
- userdatakeys.cs
- ImageConverter.cs
- IIS7UserPrincipal.cs
- Pair.cs
- DataGridViewCell.cs
- Baml2006ReaderContext.cs
- dbdatarecord.cs
- HtmlUtf8RawTextWriter.cs
- DispatcherOperation.cs
- Size.cs
- RootCodeDomSerializer.cs
- XmlAnyElementAttributes.cs
- FileResponseElement.cs
- ClientCultureInfo.cs
- TabletDevice.cs
- IsolatedStoragePermission.cs
- Int32.cs
- StylusDevice.cs
- Buffer.cs
- IdentityReference.cs