Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- UserNameSecurityTokenAuthenticator.cs
- DependencyPropertyDescriptor.cs
- DataGridViewCellCancelEventArgs.cs
- QueryableDataSourceView.cs
- DataBinder.cs
- BaseValidator.cs
- RequestCache.cs
- SignatureDescription.cs
- ArrayItemReference.cs
- MethodCallExpression.cs
- TailCallAnalyzer.cs
- GroupPartitionExpr.cs
- WsdlBuildProvider.cs
- CloseCollectionAsyncResult.cs
- User.cs
- VisualStateGroup.cs
- TableSectionStyle.cs
- TTSEngineTypes.cs
- AVElementHelper.cs
- DrawListViewSubItemEventArgs.cs
- FixedPage.cs
- PropertyChangeTracker.cs
- HwndStylusInputProvider.cs
- Margins.cs
- BigInt.cs
- NeutralResourcesLanguageAttribute.cs
- RoleService.cs
- DetailsViewRowCollection.cs
- DecimalConstantAttribute.cs
- WindowsListViewGroupSubsetLink.cs
- DataGridViewCellStyle.cs
- RegexMatchCollection.cs
- ToolStripDropDownItem.cs
- RemotingHelper.cs
- CqlLexerHelpers.cs
- DBConcurrencyException.cs
- XPathConvert.cs
- RectangleConverter.cs
- ComponentCache.cs
- Selector.cs
- XmlSchemaDatatype.cs
- XmlObjectSerializerReadContext.cs
- X509Certificate2.cs
- EastAsianLunisolarCalendar.cs
- EntityModelSchemaGenerator.cs
- ConstantProjectedSlot.cs
- WhitespaceRuleLookup.cs
- CredentialCache.cs
- Unit.cs
- ScriptingScriptResourceHandlerSection.cs
- TypeUnloadedException.cs
- ExtractorMetadata.cs
- InputElement.cs
- XmlTextEncoder.cs
- ParseNumbers.cs
- TextContainerHelper.cs
- DtdParser.cs
- ElementFactory.cs
- WebExceptionStatus.cs
- ColorInterpolationModeValidation.cs
- FlagsAttribute.cs
- SQlBooleanStorage.cs
- QueryConverter.cs
- ConnectionInterfaceCollection.cs
- GeneralTransform.cs
- ScriptReferenceBase.cs
- FixedTextSelectionProcessor.cs
- WinEventHandler.cs
- WindowsMenu.cs
- EmptyStringExpandableObjectConverter.cs
- FreeFormPanel.cs
- DictionaryBase.cs
- translator.cs
- ArcSegment.cs
- StateItem.cs
- CollectionViewProxy.cs
- DeclaredTypeElement.cs
- DrawingState.cs
- CollectionEditVerbManager.cs
- CustomError.cs
- GreenMethods.cs
- SchemaTableOptionalColumn.cs
- CatalogZone.cs
- ObjectSecurity.cs
- XmlILConstructAnalyzer.cs
- Set.cs
- ColumnBinding.cs
- WebPart.cs
- Int64Converter.cs
- FormsAuthenticationUserCollection.cs
- ContextMenuStrip.cs
- OdbcStatementHandle.cs
- RoleBoolean.cs
- EraserBehavior.cs
- SyntaxCheck.cs
- StrokeCollection2.cs
- HtmlElement.cs
- VectorAnimationBase.cs
- CodePropertyReferenceExpression.cs
- Guid.cs