Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / 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");
}
}
#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
- DataTemplate.cs
- SchemaImporter.cs
- TemplatedMailWebEventProvider.cs
- AssociatedControlConverter.cs
- SizeAnimationBase.cs
- ToolStripRenderer.cs
- SqlDependencyUtils.cs
- SoapAttributeAttribute.cs
- RoutedUICommand.cs
- XmlDataImplementation.cs
- TextElementCollectionHelper.cs
- PlainXmlWriter.cs
- ClientConvert.cs
- EntityTypeEmitter.cs
- wpf-etw.cs
- ScriptResourceMapping.cs
- UIElementHelper.cs
- SessionStateSection.cs
- ListView.cs
- WebPartsPersonalizationAuthorization.cs
- UniqueConstraint.cs
- DataGridViewAdvancedBorderStyle.cs
- AnimationLayer.cs
- DragEventArgs.cs
- ScriptManagerProxy.cs
- FormsIdentity.cs
- CodePropertyReferenceExpression.cs
- WSHttpBindingCollectionElement.cs
- OracleMonthSpan.cs
- WindowsListViewGroupSubsetLink.cs
- WebPartZoneCollection.cs
- Bold.cs
- CriticalFinalizerObject.cs
- ManagementObjectCollection.cs
- MethodToken.cs
- BuilderPropertyEntry.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- XmlToDatasetMap.cs
- NameScope.cs
- Rectangle.cs
- CqlParserHelpers.cs
- GeneratedView.cs
- WpfKnownType.cs
- InvalidProgramException.cs
- PenCursorManager.cs
- SchemaTableColumn.cs
- GradientStop.cs
- XmlProcessingInstruction.cs
- RenamedEventArgs.cs
- RectAnimationUsingKeyFrames.cs
- XmlConvert.cs
- MergeEnumerator.cs
- Transactions.cs
- SetterBaseCollection.cs
- DescendantBaseQuery.cs
- Set.cs
- OrthographicCamera.cs
- StaticDataManager.cs
- FormsAuthentication.cs
- DateTimeUtil.cs
- BamlTreeUpdater.cs
- AddInEnvironment.cs
- WebBrowserSiteBase.cs
- XmlNullResolver.cs
- FragmentQueryProcessor.cs
- FormViewDeletedEventArgs.cs
- XmlNodeComparer.cs
- DataGridViewRowContextMenuStripNeededEventArgs.cs
- SapiAttributeParser.cs
- ListCollectionView.cs
- ExpressionVisitor.cs
- DelegateHelpers.cs
- ActionFrame.cs
- PageRequestManager.cs
- FontSource.cs
- Literal.cs
- CodeDelegateCreateExpression.cs
- TextControlDesigner.cs
- ValueProviderWrapper.cs
- TeredoHelper.cs
- TCPClient.cs
- DataTableMapping.cs
- DateTime.cs
- ResourceContainer.cs
- ToolStripStatusLabel.cs
- WpfKnownMember.cs
- PenCursorManager.cs
- HashRepartitionStream.cs
- BitmapEncoder.cs
- ResourceDictionaryCollection.cs
- ServicePointManager.cs
- UIElementHelper.cs
- EntityContainerRelationshipSetEnd.cs
- Clause.cs
- ByteStack.cs
- FastPropertyAccessor.cs
- KeyTime.cs
- prompt.cs
- Directory.cs
- BamlStream.cs