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
- ScrollViewer.cs
- PropertyBuilder.cs
- DbDataReader.cs
- NamespaceEmitter.cs
- ManipulationLogic.cs
- SizeAnimationClockResource.cs
- ArrangedElementCollection.cs
- BooleanProjectedSlot.cs
- WebPartsSection.cs
- QilIterator.cs
- UriScheme.cs
- CodeTypeMember.cs
- XmlSchemaSubstitutionGroup.cs
- FileDialogCustomPlaces.cs
- XmlQueryContext.cs
- RoleService.cs
- OpacityConverter.cs
- CFStream.cs
- BamlRecordWriter.cs
- CollectionViewGroupInternal.cs
- MemberAccessException.cs
- CdpEqualityComparer.cs
- XslAst.cs
- XmlNodeChangedEventArgs.cs
- XmlSchemaInfo.cs
- SettingsAttributeDictionary.cs
- PtsHelper.cs
- MetadataSerializer.cs
- DataGridViewSelectedRowCollection.cs
- Button.cs
- PipeStream.cs
- DrawingAttributeSerializer.cs
- mediaclock.cs
- ComboBoxAutomationPeer.cs
- DocumentViewerBaseAutomationPeer.cs
- IconEditor.cs
- DependentTransaction.cs
- SqlCharStream.cs
- SecurityTokenValidationException.cs
- Message.cs
- BufferAllocator.cs
- StringBuilder.cs
- XmlHelper.cs
- EventLogPermissionEntryCollection.cs
- SchemaCollectionCompiler.cs
- ObjectConverter.cs
- ReflectionPermission.cs
- AccessorTable.cs
- Stylesheet.cs
- DelegatedStream.cs
- FileSystemWatcher.cs
- MenuItemCollection.cs
- RoleManagerSection.cs
- ProfessionalColors.cs
- GridLengthConverter.cs
- CheckedListBox.cs
- OdbcConnectionStringbuilder.cs
- ItemsControl.cs
- ComboBoxRenderer.cs
- WebHttpSecurityElement.cs
- SystemWebCachingSectionGroup.cs
- HttpCachePolicy.cs
- Renderer.cs
- ChtmlTextWriter.cs
- BufferedStream.cs
- SignatureDescription.cs
- ExpressionContext.cs
- VectorValueSerializer.cs
- ProfileGroupSettings.cs
- DbProviderFactory.cs
- BasePattern.cs
- NameSpaceExtractor.cs
- Application.cs
- TemplateKey.cs
- ValuePatternIdentifiers.cs
- WebEventTraceProvider.cs
- XXXInfos.cs
- SmiEventSink_Default.cs
- DataObject.cs
- SqlWebEventProvider.cs
- PerformanceCounterCategory.cs
- WebPartTransformerCollection.cs
- MachineKeyValidationConverter.cs
- Cursors.cs
- ProfileModule.cs
- SafeBitVector32.cs
- XamlWrappingReader.cs
- QilInvoke.cs
- ThemeableAttribute.cs
- Cloud.cs
- InfoCardKeyedHashAlgorithm.cs
- CommonXSendMessage.cs
- HTMLTextWriter.cs
- ServiceElementCollection.cs
- SwitchElementsCollection.cs
- ZipIOExtraFieldZip64Element.cs
- Adorner.cs
- DiscoveryVersionConverter.cs
- ContentFilePart.cs
- ToolStripContentPanelDesigner.cs