Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / UI / WebParts / PersonalizableAttribute.cs / 1305376 / PersonalizableAttribute.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Reflection;
using System.Web;
using System.Web.Util;
///
/// Used to mark a property as personalizable.
///
[AttributeUsage(AttributeTargets.Property)]
public sealed class PersonalizableAttribute : Attribute {
internal static readonly Type PersonalizableAttributeType = typeof(PersonalizableAttribute);
private static readonly IDictionary PersonalizableTypeTable = Hashtable.Synchronized(new Hashtable());
///
/// Indicates that the property is not personalizable.
///
public static readonly PersonalizableAttribute NotPersonalizable = new PersonalizableAttribute(false);
///
/// Indicates that the property is personalizable.
///
public static readonly PersonalizableAttribute Personalizable = new PersonalizableAttribute(true);
///
/// Indicates that the property is personalizable and can be changed per user.
///
public static readonly PersonalizableAttribute UserPersonalizable = new PersonalizableAttribute(PersonalizationScope.User);
///
/// Indicates that the property is personalizable that can only be changed for all users.
///
public static readonly PersonalizableAttribute SharedPersonalizable = new PersonalizableAttribute(PersonalizationScope.Shared);
///
/// The default personalizable attribute for a property or type. The default
/// is to indicate that a property or type is not personalizable.
///
public static readonly PersonalizableAttribute Default = NotPersonalizable;
private bool _isPersonalizable;
private bool _isSensitive;
private PersonalizationScope _scope;
///
/// Initializes an instance of PersonalizableAttribute to indicate
/// a personalizable property.
/// By default personalized properties can be personalized per user.
///
public PersonalizableAttribute() : this(true, PersonalizationScope.User, false) {
}
///
/// Initializes an instance of PersonalizableAttribute with the
/// specified value.
///
public PersonalizableAttribute(bool isPersonalizable) : this(isPersonalizable, PersonalizationScope.User, false) {
}
///
/// Initializes an instance of PersonalizableAttribute to indicate
/// a personalizable property along with the specified personalization scope.
///
public PersonalizableAttribute(PersonalizationScope scope) : this(true, scope, false) {
}
///
/// Initializes an instance of PersonalizableAttribute to indicate
/// a personalizable property along with the specified personalization scope and sensitivity.
///
public PersonalizableAttribute(PersonalizationScope scope, bool isSensitive) : this(true, scope, isSensitive) {
}
///
///
/// Initializes an instance of PersonalizableAttribute with the specified values.
///
private PersonalizableAttribute(bool isPersonalizable, PersonalizationScope scope, bool isSensitive) {
Debug.Assert((isPersonalizable == true || isSensitive == false), "Only Personalizable properties can be sensitive");
_isPersonalizable = isPersonalizable;
_isSensitive = isSensitive;
if (_isPersonalizable) {
_scope = scope;
}
}
///
/// Whether the property or the type has been marked as personalizable.
///
public bool IsPersonalizable {
get {
return _isPersonalizable;
}
}
///
/// Whether the property or the type has been marked as sensitive.
///
public bool IsSensitive {
get {
return _isSensitive;
}
}
///
/// The personalization scope associated with the personalizable property.
/// This property only has meaning when IsPersonalizable is true.
///
public PersonalizationScope Scope {
get {
return _scope;
}
}
///
public override bool Equals(object obj) {
if (obj == this) {
return true;
}
PersonalizableAttribute other = obj as PersonalizableAttribute;
if (other != null) {
return (other.IsPersonalizable == IsPersonalizable) &&
(other.Scope == Scope) &&
(other.IsSensitive == IsSensitive);
}
return false;
}
///
public override int GetHashCode() {
return HashCodeCombiner.CombineHashCodes(_isPersonalizable.GetHashCode(), _scope.GetHashCode(),
_isSensitive.GetHashCode());
}
///
/// Returns the list of personalizable properties as a collection of
/// PropertyInfos for the specified type.
///
public static ICollection GetPersonalizableProperties(Type type) {
Debug.Assert(type != null);
PersonalizableTypeEntry typeEntry = (PersonalizableTypeEntry)PersonalizableTypeTable[type];
if (typeEntry == null) {
typeEntry = new PersonalizableTypeEntry(type);
PersonalizableTypeTable[type] = typeEntry;
}
return typeEntry.PropertyInfos;
}
///
/// Returns the list of personalizable properties as a collection of
/// PropertyInfos for the specified type.
///
internal static IDictionary GetPersonalizablePropertyEntries(Type type) {
Debug.Assert(type != null);
PersonalizableTypeEntry typeEntry = (PersonalizableTypeEntry)PersonalizableTypeTable[type];
if (typeEntry == null) {
typeEntry = new PersonalizableTypeEntry(type);
PersonalizableTypeTable[type] = typeEntry;
}
return typeEntry.PropertyEntries;
}
///
///
internal static IDictionary GetPersonalizablePropertyValues(Control control, PersonalizationScope scope, bool excludeSensitive) {
IDictionary propertyBag = null;
IDictionary propertyEntries = GetPersonalizablePropertyEntries(control.GetType());
if (propertyEntries.Count != 0) {
foreach (DictionaryEntry entry in propertyEntries) {
string name = (string)entry.Key;
PersonalizablePropertyEntry propEntry = (PersonalizablePropertyEntry)entry.Value;
if (excludeSensitive && propEntry.IsSensitive) {
continue;
}
if ((scope == PersonalizationScope.User) &&
(propEntry.Scope == PersonalizationScope.Shared)) {
continue;
}
if (propertyBag == null) {
propertyBag = new HybridDictionary(propertyEntries.Count, /* caseInsensitive */ false);
}
object value = FastPropertyAccessor.GetProperty(control, name, control.DesignMode);
propertyBag[name] = new Pair(propEntry.PropertyInfo, value);
}
}
if (propertyBag == null) {
propertyBag = new HybridDictionary(/* caseInsensitive */ false);
}
return propertyBag;
}
///
public override bool IsDefaultAttribute() {
return this.Equals(Default);
}
///
public override bool Match(object obj) {
if (obj == this) {
return true;
}
PersonalizableAttribute other = obj as PersonalizableAttribute;
if (other != null) {
return (other.IsPersonalizable == IsPersonalizable);
}
return false;
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Web.UI.WebControls.WebParts {
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Reflection;
using System.Web;
using System.Web.Util;
///
/// Used to mark a property as personalizable.
///
[AttributeUsage(AttributeTargets.Property)]
public sealed class PersonalizableAttribute : Attribute {
internal static readonly Type PersonalizableAttributeType = typeof(PersonalizableAttribute);
private static readonly IDictionary PersonalizableTypeTable = Hashtable.Synchronized(new Hashtable());
///
/// Indicates that the property is not personalizable.
///
public static readonly PersonalizableAttribute NotPersonalizable = new PersonalizableAttribute(false);
///
/// Indicates that the property is personalizable.
///
public static readonly PersonalizableAttribute Personalizable = new PersonalizableAttribute(true);
///
/// Indicates that the property is personalizable and can be changed per user.
///
public static readonly PersonalizableAttribute UserPersonalizable = new PersonalizableAttribute(PersonalizationScope.User);
///
/// Indicates that the property is personalizable that can only be changed for all users.
///
public static readonly PersonalizableAttribute SharedPersonalizable = new PersonalizableAttribute(PersonalizationScope.Shared);
///
/// The default personalizable attribute for a property or type. The default
/// is to indicate that a property or type is not personalizable.
///
public static readonly PersonalizableAttribute Default = NotPersonalizable;
private bool _isPersonalizable;
private bool _isSensitive;
private PersonalizationScope _scope;
///
/// Initializes an instance of PersonalizableAttribute to indicate
/// a personalizable property.
/// By default personalized properties can be personalized per user.
///
public PersonalizableAttribute() : this(true, PersonalizationScope.User, false) {
}
///
/// Initializes an instance of PersonalizableAttribute with the
/// specified value.
///
public PersonalizableAttribute(bool isPersonalizable) : this(isPersonalizable, PersonalizationScope.User, false) {
}
///
/// Initializes an instance of PersonalizableAttribute to indicate
/// a personalizable property along with the specified personalization scope.
///
public PersonalizableAttribute(PersonalizationScope scope) : this(true, scope, false) {
}
///
/// Initializes an instance of PersonalizableAttribute to indicate
/// a personalizable property along with the specified personalization scope and sensitivity.
///
public PersonalizableAttribute(PersonalizationScope scope, bool isSensitive) : this(true, scope, isSensitive) {
}
///
///
/// Initializes an instance of PersonalizableAttribute with the specified values.
///
private PersonalizableAttribute(bool isPersonalizable, PersonalizationScope scope, bool isSensitive) {
Debug.Assert((isPersonalizable == true || isSensitive == false), "Only Personalizable properties can be sensitive");
_isPersonalizable = isPersonalizable;
_isSensitive = isSensitive;
if (_isPersonalizable) {
_scope = scope;
}
}
///
/// Whether the property or the type has been marked as personalizable.
///
public bool IsPersonalizable {
get {
return _isPersonalizable;
}
}
///
/// Whether the property or the type has been marked as sensitive.
///
public bool IsSensitive {
get {
return _isSensitive;
}
}
///
/// The personalization scope associated with the personalizable property.
/// This property only has meaning when IsPersonalizable is true.
///
public PersonalizationScope Scope {
get {
return _scope;
}
}
///
public override bool Equals(object obj) {
if (obj == this) {
return true;
}
PersonalizableAttribute other = obj as PersonalizableAttribute;
if (other != null) {
return (other.IsPersonalizable == IsPersonalizable) &&
(other.Scope == Scope) &&
(other.IsSensitive == IsSensitive);
}
return false;
}
///
public override int GetHashCode() {
return HashCodeCombiner.CombineHashCodes(_isPersonalizable.GetHashCode(), _scope.GetHashCode(),
_isSensitive.GetHashCode());
}
///
/// Returns the list of personalizable properties as a collection of
/// PropertyInfos for the specified type.
///
public static ICollection GetPersonalizableProperties(Type type) {
Debug.Assert(type != null);
PersonalizableTypeEntry typeEntry = (PersonalizableTypeEntry)PersonalizableTypeTable[type];
if (typeEntry == null) {
typeEntry = new PersonalizableTypeEntry(type);
PersonalizableTypeTable[type] = typeEntry;
}
return typeEntry.PropertyInfos;
}
///
/// Returns the list of personalizable properties as a collection of
/// PropertyInfos for the specified type.
///
internal static IDictionary GetPersonalizablePropertyEntries(Type type) {
Debug.Assert(type != null);
PersonalizableTypeEntry typeEntry = (PersonalizableTypeEntry)PersonalizableTypeTable[type];
if (typeEntry == null) {
typeEntry = new PersonalizableTypeEntry(type);
PersonalizableTypeTable[type] = typeEntry;
}
return typeEntry.PropertyEntries;
}
///
///
internal static IDictionary GetPersonalizablePropertyValues(Control control, PersonalizationScope scope, bool excludeSensitive) {
IDictionary propertyBag = null;
IDictionary propertyEntries = GetPersonalizablePropertyEntries(control.GetType());
if (propertyEntries.Count != 0) {
foreach (DictionaryEntry entry in propertyEntries) {
string name = (string)entry.Key;
PersonalizablePropertyEntry propEntry = (PersonalizablePropertyEntry)entry.Value;
if (excludeSensitive && propEntry.IsSensitive) {
continue;
}
if ((scope == PersonalizationScope.User) &&
(propEntry.Scope == PersonalizationScope.Shared)) {
continue;
}
if (propertyBag == null) {
propertyBag = new HybridDictionary(propertyEntries.Count, /* caseInsensitive */ false);
}
object value = FastPropertyAccessor.GetProperty(control, name, control.DesignMode);
propertyBag[name] = new Pair(propEntry.PropertyInfo, value);
}
}
if (propertyBag == null) {
propertyBag = new HybridDictionary(/* caseInsensitive */ false);
}
return propertyBag;
}
///
public override bool IsDefaultAttribute() {
return this.Equals(Default);
}
///
public override bool Match(object obj) {
if (obj == this) {
return true;
}
PersonalizableAttribute other = obj as PersonalizableAttribute;
if (other != null) {
return (other.IsPersonalizable == IsPersonalizable);
}
return false;
}
}
}
// 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
- SiteMap.cs
- PrivateFontCollection.cs
- Translator.cs
- ServiceChannelManager.cs
- RegexCompiler.cs
- Sql8ExpressionRewriter.cs
- CursorConverter.cs
- TdsParser.cs
- Cloud.cs
- ConfigXmlAttribute.cs
- ReferentialConstraint.cs
- UserControl.cs
- AssemblyCache.cs
- LogicalExpressionEditor.cs
- SafeTimerHandle.cs
- OneOfTypeConst.cs
- SimplePropertyEntry.cs
- _FtpControlStream.cs
- SspiHelper.cs
- UnknownExceptionActionHelper.cs
- StandardOleMarshalObject.cs
- TypeDependencyAttribute.cs
- TripleDES.cs
- ObjectItemAssemblyLoader.cs
- SBCSCodePageEncoding.cs
- DataBoundControlAdapter.cs
- ProgressiveCrcCalculatingStream.cs
- HandlerWithFactory.cs
- ToolBarButton.cs
- ReflectionUtil.cs
- SQLBoolean.cs
- LambdaCompiler.Binary.cs
- DataGridParentRows.cs
- MouseCaptureWithinProperty.cs
- UInt16Converter.cs
- WebPartConnectVerb.cs
- TableParaClient.cs
- DynamicILGenerator.cs
- ClientProxyGenerator.cs
- ModuleConfigurationInfo.cs
- Crc32.cs
- ListViewItem.cs
- PenContext.cs
- LocalizationParserHooks.cs
- PropertyContainer.cs
- NodeLabelEditEvent.cs
- Pair.cs
- OleDbPermission.cs
- BitmapMetadataEnumerator.cs
- CompilerErrorCollection.cs
- Brush.cs
- Process.cs
- CodeDirectoryCompiler.cs
- IdentityVerifier.cs
- ASCIIEncoding.cs
- ExecutorLocksHeldException.cs
- Wildcard.cs
- CatalogZoneAutoFormat.cs
- DbConnectionPoolOptions.cs
- ListBindingConverter.cs
- Int32CAMarshaler.cs
- KeyFrames.cs
- MultipleViewProviderWrapper.cs
- QilScopedVisitor.cs
- HwndProxyElementProvider.cs
- DataSourceControl.cs
- FormattedTextSymbols.cs
- ExpressionBuilder.cs
- ProcessInputEventArgs.cs
- SystemException.cs
- Throw.cs
- PathStreamGeometryContext.cs
- HitTestWithGeometryDrawingContextWalker.cs
- EFColumnProvider.cs
- PropertyCondition.cs
- DirectoryNotFoundException.cs
- ProxyWebPartConnectionCollection.cs
- SqlDataSourceConfigureSortForm.cs
- StorageMappingItemLoader.cs
- CompiledELinqQueryState.cs
- TreeViewEvent.cs
- RecommendedAsConfigurableAttribute.cs
- DataSourceView.cs
- xamlnodes.cs
- HideDisabledControlAdapter.cs
- ApplicationActivator.cs
- FileDataSourceCache.cs
- SharedStatics.cs
- DataGridViewLinkColumn.cs
- PartialArray.cs
- AnnotationAuthorChangedEventArgs.cs
- LinqDataView.cs
- XmlWellformedWriter.cs
- FontDriver.cs
- DataPagerField.cs
- ADMembershipProvider.cs
- ModelUIElement3D.cs
- ControlValuePropertyAttribute.cs
- FileEnumerator.cs
- GridEntryCollection.cs