Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- FilteredDataSetHelper.cs
- FilterQuery.cs
- AutoScrollHelper.cs
- StatusBarPanel.cs
- XmlCountingReader.cs
- ExceptionUtil.cs
- ComponentCollection.cs
- DirectionalLight.cs
- XsdSchemaFileEditor.cs
- AlphabeticalEnumConverter.cs
- SQLInt16Storage.cs
- EUCJPEncoding.cs
- PerformanceCounter.cs
- DataGridPageChangedEventArgs.cs
- ModelEditingScope.cs
- BaseCAMarshaler.cs
- FullTextState.cs
- CompositeFontInfo.cs
- DropShadowEffect.cs
- CroppedBitmap.cs
- CommandEventArgs.cs
- XsltQilFactory.cs
- User.cs
- Identity.cs
- Dispatcher.cs
- BrowserCapabilitiesFactory.cs
- ProcessHostServerConfig.cs
- ListItemParagraph.cs
- EventHandlingScope.cs
- UpdateCommand.cs
- CheckPair.cs
- StreamInfo.cs
- TextAnchor.cs
- CacheMemory.cs
- XpsPackagingException.cs
- SerializationException.cs
- SmiEventStream.cs
- Vector3DValueSerializer.cs
- ModuleConfigurationInfo.cs
- SiteMapNode.cs
- BaseHashHelper.cs
- CqlLexerHelpers.cs
- ImmComposition.cs
- TTSEngineProxy.cs
- CursorConverter.cs
- InitializationEventAttribute.cs
- ObjectComplexPropertyMapping.cs
- ArrayTypeMismatchException.cs
- StreamUpdate.cs
- PageSettings.cs
- SqlUserDefinedAggregateAttribute.cs
- ImageAutomationPeer.cs
- BackgroundWorker.cs
- PropertyStore.cs
- ErrorLog.cs
- ReflectionServiceProvider.cs
- HiddenFieldPageStatePersister.cs
- UshortList2.cs
- ValueExpressions.cs
- JavaScriptObjectDeserializer.cs
- Rectangle.cs
- WasHttpModulesInstallComponent.cs
- WindowsGraphicsWrapper.cs
- Scene3D.cs
- precedingquery.cs
- OfTypeExpression.cs
- NameNode.cs
- ApplicationServicesHostFactory.cs
- ConstraintCollection.cs
- TreeNode.cs
- LocalizabilityAttribute.cs
- CompiledRegexRunner.cs
- PropertyRecord.cs
- ManagedIStream.cs
- PostBackTrigger.cs
- PropertyRef.cs
- MDIWindowDialog.cs
- InteropBitmapSource.cs
- MethodCallTranslator.cs
- OracleRowUpdatingEventArgs.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- SymbolType.cs
- DataBindingList.cs
- ShapeTypeface.cs
- Separator.cs
- BidPrivateBase.cs
- ToolStripDropTargetManager.cs
- Parallel.cs
- CodeTypeParameterCollection.cs
- BuildProviderAppliesToAttribute.cs
- Signature.cs
- TransactionInterop.cs
- OleDbConnectionFactory.cs
- SmtpClient.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- HeaderedContentControl.cs
- AppearanceEditorPart.cs
- InputReferenceExpression.cs
- X509PeerCertificateElement.cs
- CapabilitiesState.cs