Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / CompMod / System / ComponentModel / ExtendedPropertyDescriptor.cs / 1 / ExtendedPropertyDescriptor.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.ComponentModel {
using Microsoft.Win32;
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Security.Permissions;
///
///
///
/// This class wraps an PropertyDescriptor with something that looks like a property. It
/// allows you to treat extended properties the same as regular properties.
///
///
[HostProtection(SharedState = true)]
internal sealed class ExtendedPropertyDescriptor : PropertyDescriptor {
private readonly ReflectPropertyDescriptor extenderInfo; // the extender property
private readonly IExtenderProvider provider; // the guy providing it
///
/// Creates a new extended property info. Callers can then treat this as
/// a standard property.
///
public ExtendedPropertyDescriptor(ReflectPropertyDescriptor extenderInfo, Type receiverType, IExtenderProvider provider, Attribute[] attributes)
: base(extenderInfo, attributes) {
Debug.Assert(extenderInfo != null, "ExtendedPropertyDescriptor must have extenderInfo");
Debug.Assert(provider != null, "ExtendedPropertyDescriptor must have provider");
ArrayList attrList = new ArrayList(AttributeArray);
attrList.Add(ExtenderProvidedPropertyAttribute.Create(extenderInfo, receiverType, provider));
if (extenderInfo.IsReadOnly) {
attrList.Add(ReadOnlyAttribute.Yes);
}
Attribute[] temp = new Attribute[attrList.Count];
attrList.CopyTo(temp, 0);
AttributeArray = temp;
this.extenderInfo = extenderInfo;
this.provider = provider;
}
public ExtendedPropertyDescriptor(PropertyDescriptor extender, Attribute[] attributes) : base(extender, attributes) {
Debug.Assert(extender != null, "The original PropertyDescriptor must be non-null");
ExtenderProvidedPropertyAttribute attr = extender.Attributes[typeof(ExtenderProvidedPropertyAttribute)] as ExtenderProvidedPropertyAttribute;
Debug.Assert(attr != null, "The original PropertyDescriptor does not have an ExtenderProvidedPropertyAttribute");
ReflectPropertyDescriptor reflectDesc = attr.ExtenderProperty as ReflectPropertyDescriptor;
Debug.Assert(reflectDesc != null, "The original PropertyDescriptor has an invalid ExtenderProperty");
this.extenderInfo = reflectDesc;
this.provider = attr.Provider;
}
///
/// Determines if the the component will allow its value to be reset.
///
public override bool CanResetValue(object comp) {
return extenderInfo.ExtenderCanResetValue(provider, comp);
}
///
/// Retrieves the type of the component this PropertyDescriptor is bound to.
///
public override Type ComponentType {
get {
return extenderInfo.ComponentType;
}
}
///
/// Determines if the property can be written to.
///
public override bool IsReadOnly {
get {
return Attributes[typeof(ReadOnlyAttribute)].Equals(ReadOnlyAttribute.Yes);
}
}
///
/// Retrieves the data type of the property.
///
public override Type PropertyType {
get {
return extenderInfo.ExtenderGetType(provider);
}
}
///
/// Retrieves the display name of the property. This is the name that will
/// be displayed in a properties window. This will be the same as the property
/// name for most properties.
///
public override string DisplayName {
get {
string name = base.DisplayName;
DisplayNameAttribute displayNameAttr = Attributes[typeof(DisplayNameAttribute)] as DisplayNameAttribute;
if (displayNameAttr == null || displayNameAttr.IsDefaultAttribute()) {
ISite site = GetSite(provider);
if (site != null) {
string providerName = site.Name;
if (providerName != null && providerName.Length > 0) {
name = SR.GetString(SR.MetaExtenderName, name, providerName);
}
}
}
return name;
}
}
///
/// Retrieves the value of the property for the given component. This will
/// throw an exception if the component does not have this property.
///
public override object GetValue(object comp) {
return extenderInfo.ExtenderGetValue(provider, comp);
}
///
/// Resets the value of this property on comp to the default value.
///
public override void ResetValue(object comp) {
extenderInfo.ExtenderResetValue(provider, comp, this);
}
///
/// Sets the value of this property on the given component.
///
public override void SetValue(object component, object value) {
extenderInfo.ExtenderSetValue(provider, component, value, this);
}
///
/// Determines if this property should be persisted. A property is
/// to be persisted if it is marked as persistable through a
/// PersistableAttribute, and if the property contains something other
/// than the default value. Note, however, that this method will
/// return true for design time properties as well, so callers
/// should also check to see if a property is design time only before
/// persisting to runtime storage.
///
public override bool ShouldSerializeValue(object comp) {
return extenderInfo.ExtenderShouldSerializeValue(provider, comp);
}
/*
The following code has been removed to fix FXCOP violations. The code
is left here incase it needs to be resurrected in the future.
///
/// Creates a new extended property info. Callers can then treat this as
/// a standard property.
///
public ExtendedPropertyDescriptor(ReflectPropertyDescriptor extenderInfo, Type receiverType, IExtenderProvider provider) : this(extenderInfo, receiverType, provider, null) {
}
///
/// Retrieves the object that is providing this extending property.
///
public IExtenderProvider Provider {
get {
return provider;
}
}
*/
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.ComponentModel {
using Microsoft.Win32;
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Security.Permissions;
///
///
///
/// This class wraps an PropertyDescriptor with something that looks like a property. It
/// allows you to treat extended properties the same as regular properties.
///
///
[HostProtection(SharedState = true)]
internal sealed class ExtendedPropertyDescriptor : PropertyDescriptor {
private readonly ReflectPropertyDescriptor extenderInfo; // the extender property
private readonly IExtenderProvider provider; // the guy providing it
///
/// Creates a new extended property info. Callers can then treat this as
/// a standard property.
///
public ExtendedPropertyDescriptor(ReflectPropertyDescriptor extenderInfo, Type receiverType, IExtenderProvider provider, Attribute[] attributes)
: base(extenderInfo, attributes) {
Debug.Assert(extenderInfo != null, "ExtendedPropertyDescriptor must have extenderInfo");
Debug.Assert(provider != null, "ExtendedPropertyDescriptor must have provider");
ArrayList attrList = new ArrayList(AttributeArray);
attrList.Add(ExtenderProvidedPropertyAttribute.Create(extenderInfo, receiverType, provider));
if (extenderInfo.IsReadOnly) {
attrList.Add(ReadOnlyAttribute.Yes);
}
Attribute[] temp = new Attribute[attrList.Count];
attrList.CopyTo(temp, 0);
AttributeArray = temp;
this.extenderInfo = extenderInfo;
this.provider = provider;
}
public ExtendedPropertyDescriptor(PropertyDescriptor extender, Attribute[] attributes) : base(extender, attributes) {
Debug.Assert(extender != null, "The original PropertyDescriptor must be non-null");
ExtenderProvidedPropertyAttribute attr = extender.Attributes[typeof(ExtenderProvidedPropertyAttribute)] as ExtenderProvidedPropertyAttribute;
Debug.Assert(attr != null, "The original PropertyDescriptor does not have an ExtenderProvidedPropertyAttribute");
ReflectPropertyDescriptor reflectDesc = attr.ExtenderProperty as ReflectPropertyDescriptor;
Debug.Assert(reflectDesc != null, "The original PropertyDescriptor has an invalid ExtenderProperty");
this.extenderInfo = reflectDesc;
this.provider = attr.Provider;
}
///
/// Determines if the the component will allow its value to be reset.
///
public override bool CanResetValue(object comp) {
return extenderInfo.ExtenderCanResetValue(provider, comp);
}
///
/// Retrieves the type of the component this PropertyDescriptor is bound to.
///
public override Type ComponentType {
get {
return extenderInfo.ComponentType;
}
}
///
/// Determines if the property can be written to.
///
public override bool IsReadOnly {
get {
return Attributes[typeof(ReadOnlyAttribute)].Equals(ReadOnlyAttribute.Yes);
}
}
///
/// Retrieves the data type of the property.
///
public override Type PropertyType {
get {
return extenderInfo.ExtenderGetType(provider);
}
}
///
/// Retrieves the display name of the property. This is the name that will
/// be displayed in a properties window. This will be the same as the property
/// name for most properties.
///
public override string DisplayName {
get {
string name = base.DisplayName;
DisplayNameAttribute displayNameAttr = Attributes[typeof(DisplayNameAttribute)] as DisplayNameAttribute;
if (displayNameAttr == null || displayNameAttr.IsDefaultAttribute()) {
ISite site = GetSite(provider);
if (site != null) {
string providerName = site.Name;
if (providerName != null && providerName.Length > 0) {
name = SR.GetString(SR.MetaExtenderName, name, providerName);
}
}
}
return name;
}
}
///
/// Retrieves the value of the property for the given component. This will
/// throw an exception if the component does not have this property.
///
public override object GetValue(object comp) {
return extenderInfo.ExtenderGetValue(provider, comp);
}
///
/// Resets the value of this property on comp to the default value.
///
public override void ResetValue(object comp) {
extenderInfo.ExtenderResetValue(provider, comp, this);
}
///
/// Sets the value of this property on the given component.
///
public override void SetValue(object component, object value) {
extenderInfo.ExtenderSetValue(provider, component, value, this);
}
///
/// Determines if this property should be persisted. A property is
/// to be persisted if it is marked as persistable through a
/// PersistableAttribute, and if the property contains something other
/// than the default value. Note, however, that this method will
/// return true for design time properties as well, so callers
/// should also check to see if a property is design time only before
/// persisting to runtime storage.
///
public override bool ShouldSerializeValue(object comp) {
return extenderInfo.ExtenderShouldSerializeValue(provider, comp);
}
/*
The following code has been removed to fix FXCOP violations. The code
is left here incase it needs to be resurrected in the future.
///
/// Creates a new extended property info. Callers can then treat this as
/// a standard property.
///
public ExtendedPropertyDescriptor(ReflectPropertyDescriptor extenderInfo, Type receiverType, IExtenderProvider provider) : this(extenderInfo, receiverType, provider, null) {
}
///
/// Retrieves the object that is providing this extending property.
///
public IExtenderProvider Provider {
get {
return provider;
}
}
*/
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RefType.cs
- DBAsyncResult.cs
- TransformedBitmap.cs
- DiscardableAttribute.cs
- MethodRental.cs
- TextStore.cs
- DropDownButton.cs
- Select.cs
- _NTAuthentication.cs
- NonVisualControlAttribute.cs
- BookmarkUndoUnit.cs
- CompiledQueryCacheEntry.cs
- KeyboardEventArgs.cs
- TraceHwndHost.cs
- KeyManager.cs
- VisualTreeUtils.cs
- PreservationFileWriter.cs
- DataGridViewBindingCompleteEventArgs.cs
- TypeRefElement.cs
- TrackingLocationCollection.cs
- PostBackTrigger.cs
- CodeMethodMap.cs
- SubpageParaClient.cs
- EntityException.cs
- PaperSize.cs
- XamlNamespaceHelper.cs
- SqlUtils.cs
- CodeMemberProperty.cs
- ValidationRule.cs
- DataGrid.cs
- PeerNameRecordCollection.cs
- TabItemAutomationPeer.cs
- ResourceWriter.cs
- SequenceFullException.cs
- RegexGroupCollection.cs
- Point.cs
- ScriptControlDescriptor.cs
- SaveFileDialog.cs
- ControlParameter.cs
- FileLevelControlBuilderAttribute.cs
- ExpressionUtilities.cs
- DataShape.cs
- DataObject.cs
- XmlSchema.cs
- SplineKeyFrames.cs
- ProfileGroupSettingsCollection.cs
- XmlKeywords.cs
- ArraySegment.cs
- WindowsSysHeader.cs
- PropertyDescriptorCollection.cs
- TrackingServices.cs
- processwaithandle.cs
- DataGridViewDataConnection.cs
- InkCanvas.cs
- XmlAnyAttributeAttribute.cs
- ComponentCommands.cs
- ContentAlignmentEditor.cs
- ListenerSessionConnection.cs
- BindingManagerDataErrorEventArgs.cs
- LocatorManager.cs
- StoragePropertyMapping.cs
- Pair.cs
- ArrangedElement.cs
- SafeHandle.cs
- DivideByZeroException.cs
- X509CertificateRecipientServiceCredential.cs
- _NegoStream.cs
- PropertyChangeTracker.cs
- UITypeEditor.cs
- QilStrConcatenator.cs
- HttpFileCollectionBase.cs
- BitStack.cs
- WindowsToolbar.cs
- QueryResult.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- SoapAttributeOverrides.cs
- ClientTargetCollection.cs
- BookmarkEventArgs.cs
- XmlWriterTraceListener.cs
- DetailsViewDeletedEventArgs.cs
- SchemaImporter.cs
- ReaderWriterLock.cs
- ApplicationServicesHostFactory.cs
- FileDialogCustomPlacesCollection.cs
- SpnEndpointIdentity.cs
- _Connection.cs
- ColumnMapCopier.cs
- MessageContractExporter.cs
- HtmlTable.cs
- ContractHandle.cs
- SecurityContext.cs
- WebReferencesBuildProvider.cs
- BitmapPalettes.cs
- EventBookmark.cs
- CachedFontFamily.cs
- ChannelManager.cs
- MarshalDirectiveException.cs
- OdbcConnectionPoolProviderInfo.cs
- InputScopeNameConverter.cs
- CanonicalFontFamilyReference.cs