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
- SafePEFileHandle.cs
- ClipboardData.cs
- EntityStoreSchemaGenerator.cs
- DefaultBindingPropertyAttribute.cs
- ConfigXmlSignificantWhitespace.cs
- EntityDataSourceValidationException.cs
- XmlSerializationWriter.cs
- ResourceDefaultValueAttribute.cs
- DataTableTypeConverter.cs
- InlineObject.cs
- LambdaCompiler.ControlFlow.cs
- Odbc32.cs
- XPathScanner.cs
- DebugControllerThread.cs
- BitStack.cs
- RegexGroupCollection.cs
- Marshal.cs
- ScriptHandlerFactory.cs
- WebConfigurationHost.cs
- VScrollBar.cs
- Utilities.cs
- TdsParserStaticMethods.cs
- SystemResourceKey.cs
- TextElementAutomationPeer.cs
- NullableDecimalAverageAggregationOperator.cs
- TextOutput.cs
- ObjectContextServiceProvider.cs
- HostSecurityManager.cs
- ListDesigner.cs
- AssemblyContextControlItem.cs
- RenameRuleObjectDialog.cs
- FormViewPageEventArgs.cs
- ConditionValidator.cs
- SymDocumentType.cs
- DockPattern.cs
- XmlSchemaSimpleTypeRestriction.cs
- SynchronizationLockException.cs
- WebPartTracker.cs
- SqlConnectionPoolProviderInfo.cs
- TableLayout.cs
- XPathCompiler.cs
- EntryPointNotFoundException.cs
- Pts.cs
- LinqExpressionNormalizer.cs
- SerializationException.cs
- RegisteredDisposeScript.cs
- FloatUtil.cs
- StreamFormatter.cs
- AttachedPropertyBrowsableAttribute.cs
- Constants.cs
- FreezableDefaultValueFactory.cs
- Nullable.cs
- CodeCompiler.cs
- StorageAssociationTypeMapping.cs
- OdbcInfoMessageEvent.cs
- ToolStripButton.cs
- Screen.cs
- XmlSortKeyAccumulator.cs
- XPathNavigatorReader.cs
- SafeRightsManagementQueryHandle.cs
- ComponentChangedEvent.cs
- DispatcherHookEventArgs.cs
- DoWhileDesigner.xaml.cs
- ExceptionHandlers.cs
- OdbcEnvironmentHandle.cs
- Int64Storage.cs
- infer.cs
- CodeCatchClause.cs
- UIElementParaClient.cs
- SafeHandles.cs
- QueryableFilterRepeater.cs
- FileLoadException.cs
- UrlMappingCollection.cs
- COM2IDispatchConverter.cs
- WarningException.cs
- Int16AnimationBase.cs
- InstanceData.cs
- Tool.cs
- TextCharacters.cs
- PageTheme.cs
- log.cs
- AdornerLayer.cs
- SqlTopReducer.cs
- ViewStateModeByIdAttribute.cs
- PermissionToken.cs
- FixedPageProcessor.cs
- StringHandle.cs
- SQLConvert.cs
- MachineKeyConverter.cs
- RelationHandler.cs
- TextEffect.cs
- RadioButtonDesigner.cs
- ReliableOutputConnection.cs
- SecureStringHasher.cs
- UrlPath.cs
- BufferModesCollection.cs
- PointAnimation.cs
- QilLiteral.cs
- ReaderContextStackData.cs
- FrameworkContentElement.cs