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
- TransformProviderWrapper.cs
- InputLanguageSource.cs
- XmlArrayItemAttributes.cs
- DbMetaDataFactory.cs
- HashMembershipCondition.cs
- DBSqlParserTable.cs
- UpdateManifestForBrowserApplication.cs
- MessageSecurityOverTcp.cs
- WsdlInspector.cs
- DesignerDataConnection.cs
- SqlComparer.cs
- FontStretches.cs
- ValueTypeFixupInfo.cs
- LicenseException.cs
- SignatureTargetIdManager.cs
- CacheForPrimitiveTypes.cs
- SamlSecurityToken.cs
- TextUtf8RawTextWriter.cs
- DiscoveryReference.cs
- HijriCalendar.cs
- Assign.cs
- XmlSchemas.cs
- WCFModelStrings.Designer.cs
- Visual3DCollection.cs
- FullTextBreakpoint.cs
- CacheMemory.cs
- ProgramNode.cs
- Pens.cs
- DecimalConstantAttribute.cs
- VisualBasicDesignerHelper.cs
- PackageProperties.cs
- WorkflowApplicationIdleEventArgs.cs
- SelectionEditingBehavior.cs
- SpecialFolderEnumConverter.cs
- SettingsAttributes.cs
- WindowsListView.cs
- DataGridViewCellEventArgs.cs
- PointF.cs
- ThreadStaticAttribute.cs
- WebBrowsableAttribute.cs
- CodeConditionStatement.cs
- codemethodreferenceexpression.cs
- TextProperties.cs
- IncrementalCompileAnalyzer.cs
- ConnectionPoint.cs
- XmlSerializer.cs
- TimeZone.cs
- MergeFilterQuery.cs
- OracleTimeSpan.cs
- TdsParserSafeHandles.cs
- MruCache.cs
- JobStaple.cs
- ASCIIEncoding.cs
- TypeNameConverter.cs
- JournalEntryListConverter.cs
- ISAPIRuntime.cs
- DBNull.cs
- Button.cs
- ContentPresenter.cs
- ExternalException.cs
- TranslateTransform.cs
- util.cs
- MultipartIdentifier.cs
- WindowsAltTab.cs
- AttributeEmitter.cs
- Debug.cs
- EntityDataSourceWrapper.cs
- InvalidPropValue.cs
- RectValueSerializer.cs
- BaseResourcesBuildProvider.cs
- CompiledRegexRunner.cs
- FontStretch.cs
- StyleSelector.cs
- DrawingGroup.cs
- BidOverLoads.cs
- XmlSchemaSequence.cs
- ForEachAction.cs
- RtfToken.cs
- SystemBrushes.cs
- DbTypeMap.cs
- BindingExpressionUncommonField.cs
- TextRangeBase.cs
- Link.cs
- ConditionCollection.cs
- FixedFlowMap.cs
- TypeLoadException.cs
- RegexWorker.cs
- TrustLevelCollection.cs
- SafeWaitHandle.cs
- Exception.cs
- TransformerInfoCollection.cs
- SoapEnumAttribute.cs
- SingleBodyParameterMessageFormatter.cs
- WebPartEventArgs.cs
- PhoneCallDesigner.cs
- EmissiveMaterial.cs
- StringFunctions.cs
- NumberEdit.cs
- OverrideMode.cs
- CancellableEnumerable.cs