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 / AttachedPropertyBrowsableForTypeAttribute.cs / 1 / AttachedPropertyBrowsableForTypeAttribute.cs
namespace System.Windows
{
using System;
///
/// This class declares that an attached property is browsable only
/// for dependency objects that derive from the given type. If more
/// than one type is specified, the property is browsable if any type
/// matches (logical or). The type may also be an interface.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class AttachedPropertyBrowsableForTypeAttribute : AttachedPropertyBrowsableAttribute
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Creates a new AttachedPropertyBrowsableForTypeAttribute. Provide the type
/// you want the attached property to be browsable for. Multiple
/// attributes may be used to provide support for more than one
/// type.
///
public AttachedPropertyBrowsableForTypeAttribute(Type targetType)
{
if (targetType == null) throw new ArgumentNullException("targetType");
_targetType = targetType;
}
//-----------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
///
/// Returns the type passed into the constructor.
///
public Type TargetType
{
get
{
return _targetType;
}
}
///
/// For AllowMultiple attributes, TypeId must be unique for
/// each unique instance. The default returns the type, which
/// is only correct for AllowMultiple == false.
///
public override object TypeId
{
get
{
return this;
}
}
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
///
/// Overrides Object.Equals to implement correct equality semantics for this
/// attribute.
///
public override bool Equals(object obj)
{
AttachedPropertyBrowsableForTypeAttribute other = obj as AttachedPropertyBrowsableForTypeAttribute;
if (other == null) return false;
return _targetType == other._targetType;
}
///
/// Overrides Object.GetHashCode to implement correct hashing semantics.
///
public override int GetHashCode()
{
return _targetType.GetHashCode();
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
///
/// Returns true if the dependency object passed to the method is a type,
/// subtype or implememts the interface of any of the the types contained
/// in this object.
///
internal override bool IsBrowsable(DependencyObject d, DependencyProperty dp)
{
if (d == null) throw new ArgumentNullException("d");
if (dp == null) throw new ArgumentNullException("dp");
// Get the dependency object type for our target type.
// We cannot assume the user didn't do something wrong and
// feed us a type that is not a dependency object, but that is
// rare enough that it is worth the try/catch here rather than
// a double IsAssignableFrom (one here, and one in DependencyObjectType).
// We still use a flag here rather than checking for a null
// _dTargetType so that a bad property that throws won't consistently
// slow the system down with ArgumentExceptions.
if (!_dTargetTypeChecked)
{
try
{
_dTargetType = DependencyObjectType.FromSystemType(_targetType);
}
catch(ArgumentException)
{
}
_dTargetTypeChecked = true;
}
if (_dTargetType != null && _dTargetType.IsInstanceOfType(d))
{
return true;
}
return false;
}
///
/// Returns true if a browsable match is true if any one of multiple
/// instances of the same type return true for IsBrowsable. We override
/// this to return true because any one of a successfull match for
/// IsBrowsable is accepted.
///
internal override bool UnionResults
{
get
{
return true;
}
}
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
private Type _targetType;
private DependencyObjectType _dTargetType;
private bool _dTargetTypeChecked;
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Windows
{
using System;
///
/// This class declares that an attached property is browsable only
/// for dependency objects that derive from the given type. If more
/// than one type is specified, the property is browsable if any type
/// matches (logical or). The type may also be an interface.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
public sealed class AttachedPropertyBrowsableForTypeAttribute : AttachedPropertyBrowsableAttribute
{
//------------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
///
/// Creates a new AttachedPropertyBrowsableForTypeAttribute. Provide the type
/// you want the attached property to be browsable for. Multiple
/// attributes may be used to provide support for more than one
/// type.
///
public AttachedPropertyBrowsableForTypeAttribute(Type targetType)
{
if (targetType == null) throw new ArgumentNullException("targetType");
_targetType = targetType;
}
//-----------------------------------------------------
//
// Public Properties
//
//-----------------------------------------------------
///
/// Returns the type passed into the constructor.
///
public Type TargetType
{
get
{
return _targetType;
}
}
///
/// For AllowMultiple attributes, TypeId must be unique for
/// each unique instance. The default returns the type, which
/// is only correct for AllowMultiple == false.
///
public override object TypeId
{
get
{
return this;
}
}
//------------------------------------------------------
//
// Public Methods
//
//-----------------------------------------------------
///
/// Overrides Object.Equals to implement correct equality semantics for this
/// attribute.
///
public override bool Equals(object obj)
{
AttachedPropertyBrowsableForTypeAttribute other = obj as AttachedPropertyBrowsableForTypeAttribute;
if (other == null) return false;
return _targetType == other._targetType;
}
///
/// Overrides Object.GetHashCode to implement correct hashing semantics.
///
public override int GetHashCode()
{
return _targetType.GetHashCode();
}
//------------------------------------------------------
//
// Internal Methods
//
//------------------------------------------------------
///
/// Returns true if the dependency object passed to the method is a type,
/// subtype or implememts the interface of any of the the types contained
/// in this object.
///
internal override bool IsBrowsable(DependencyObject d, DependencyProperty dp)
{
if (d == null) throw new ArgumentNullException("d");
if (dp == null) throw new ArgumentNullException("dp");
// Get the dependency object type for our target type.
// We cannot assume the user didn't do something wrong and
// feed us a type that is not a dependency object, but that is
// rare enough that it is worth the try/catch here rather than
// a double IsAssignableFrom (one here, and one in DependencyObjectType).
// We still use a flag here rather than checking for a null
// _dTargetType so that a bad property that throws won't consistently
// slow the system down with ArgumentExceptions.
if (!_dTargetTypeChecked)
{
try
{
_dTargetType = DependencyObjectType.FromSystemType(_targetType);
}
catch(ArgumentException)
{
}
_dTargetTypeChecked = true;
}
if (_dTargetType != null && _dTargetType.IsInstanceOfType(d))
{
return true;
}
return false;
}
///
/// Returns true if a browsable match is true if any one of multiple
/// instances of the same type return true for IsBrowsable. We override
/// this to return true because any one of a successfull match for
/// IsBrowsable is accepted.
///
internal override bool UnionResults
{
get
{
return true;
}
}
//-----------------------------------------------------
//
// Private Fields
//
//------------------------------------------------------
private Type _targetType;
private DependencyObjectType _dTargetType;
private bool _dTargetTypeChecked;
}
}
// 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
- SystemIPv6InterfaceProperties.cs
- SessionState.cs
- XmlElementList.cs
- ConfigXmlElement.cs
- XmlRootAttribute.cs
- ShortcutKeysEditor.cs
- _HeaderInfo.cs
- DataSvcMapFile.cs
- RSAPKCS1KeyExchangeDeformatter.cs
- HandoffBehavior.cs
- ServerValidateEventArgs.cs
- ScriptHandlerFactory.cs
- NavigationProperty.cs
- ProtocolsConfigurationHandler.cs
- StringFunctions.cs
- MethodImplAttribute.cs
- StreamGeometry.cs
- XmlAttributeOverrides.cs
- CodeStatement.cs
- XmlSubtreeReader.cs
- NotificationContext.cs
- DictionarySectionHandler.cs
- Message.cs
- DrawingContextWalker.cs
- AuthenticationService.cs
- ProxyManager.cs
- CapabilitiesPattern.cs
- RuntimeComponentFilter.cs
- Misc.cs
- SnapshotChangeTrackingStrategy.cs
- ApplicationFileParser.cs
- DependencyPropertyKey.cs
- SQLGuid.cs
- ByteBufferPool.cs
- ObjectViewFactory.cs
- DataExpression.cs
- TrackBar.cs
- GridViewSelectEventArgs.cs
- LocatorPartList.cs
- CodeNamespaceImport.cs
- InvalidFilterCriteriaException.cs
- TypeHelper.cs
- IndentTextWriter.cs
- Parameter.cs
- UrlPropertyAttribute.cs
- DurableInstancingOptions.cs
- ObjectItemAssemblyLoader.cs
- TypeDefinition.cs
- SessionIDManager.cs
- UserPreferenceChangingEventArgs.cs
- IProvider.cs
- ListInitExpression.cs
- TextRangeAdaptor.cs
- PointCollectionValueSerializer.cs
- InternalConfigEventArgs.cs
- HttpServerVarsCollection.cs
- ProxyManager.cs
- TimelineGroup.cs
- ConversionHelper.cs
- IsolatedStorageFile.cs
- Process.cs
- NamedPipeConnectionPoolSettings.cs
- ThreadStartException.cs
- RegexGroupCollection.cs
- DBAsyncResult.cs
- SimpleTextLine.cs
- RequestStatusBarUpdateEventArgs.cs
- UserNamePasswordValidationMode.cs
- ColumnWidthChangingEvent.cs
- SocketElement.cs
- WebPartCatalogCloseVerb.cs
- ErrorRuntimeConfig.cs
- DecimalConverter.cs
- DataGridViewControlCollection.cs
- CanonicalizationDriver.cs
- control.ime.cs
- InheritanceContextChangedEventManager.cs
- DataGridTextBox.cs
- followingsibling.cs
- QuaternionAnimation.cs
- OracleNumber.cs
- AuthenticationSection.cs
- ToolStripDesignerUtils.cs
- StyleModeStack.cs
- ToolboxDataAttribute.cs
- InitializingNewItemEventArgs.cs
- ObjectIDGenerator.cs
- KeyValuePair.cs
- UnsafeNativeMethods.cs
- XamlSerializerUtil.cs
- odbcmetadatafactory.cs
- WaitHandleCannotBeOpenedException.cs
- ButtonField.cs
- ToolStripPanelSelectionGlyph.cs
- Subtree.cs
- List.cs
- CompilerState.cs
- ChooseAction.cs
- SrgsText.cs
- DataPager.cs