Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / Util / AttributeExtensions.cs / 1305376 / AttributeExtensions.cs
namespace System.Web.DynamicData.Util {
using System;
using System.Collections.Generic;
using System.Linq;
internal static class AttributeExtensions {
///
/// Gets the first attribute of a given time on the target AttributeCollection, or null.
///
/// The attribute type
/// The AttributeCollection object
///
internal static TAttribute FirstOrDefault(this System.ComponentModel.AttributeCollection attributes) where TAttribute : Attribute {
return attributes.OfType().FirstOrDefault();
}
internal static TResult GetAttributePropertyValue(this System.ComponentModel.AttributeCollection attributes, Func propertyGetter)
where TResult : class
where TAttribute : Attribute {
return attributes.GetAttributePropertyValue(propertyGetter, null);
}
internal static TResult GetAttributePropertyValue(this System.ComponentModel.AttributeCollection attributes, Func propertyGetter, TResult defaultValue)
where TAttribute : Attribute {
var attribute = attributes.FirstOrDefault();
return attribute.GetPropertyValue(propertyGetter, defaultValue);
}
///
/// Gets the property for a given attribute reference or returns null if the reference is null.
///
/// The attribute type
/// The type of the attribute's property
/// The attribute reference
/// The function to evaluate on the attribute
///
internal static TResult GetPropertyValue(this TAttribute attribute, Func propertyGetter)
where TResult : class
where TAttribute : Attribute {
return attribute.GetPropertyValue(propertyGetter, null);
}
///
/// Gets the property for a given attribute reference or returns the default value if the reference is null.
///
/// The attribute type
/// The type of the attribute's property
/// The attribute reference
/// The function to evaluate on the attribute
/// The default value to return if the attribute is null
///
internal static TResult GetPropertyValue(this TAttribute attribute, Func propertyGetter, TResult defaultValue)
where TAttribute : Attribute {
if (attribute != null) {
return propertyGetter(attribute);
}
else {
return defaultValue;
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Web.DynamicData.Util {
using System;
using System.Collections.Generic;
using System.Linq;
internal static class AttributeExtensions {
///
/// Gets the first attribute of a given time on the target AttributeCollection, or null.
///
/// The attribute type
/// The AttributeCollection object
///
internal static TAttribute FirstOrDefault(this System.ComponentModel.AttributeCollection attributes) where TAttribute : Attribute {
return attributes.OfType().FirstOrDefault();
}
internal static TResult GetAttributePropertyValue(this System.ComponentModel.AttributeCollection attributes, Func propertyGetter)
where TResult : class
where TAttribute : Attribute {
return attributes.GetAttributePropertyValue(propertyGetter, null);
}
internal static TResult GetAttributePropertyValue(this System.ComponentModel.AttributeCollection attributes, Func propertyGetter, TResult defaultValue)
where TAttribute : Attribute {
var attribute = attributes.FirstOrDefault();
return attribute.GetPropertyValue(propertyGetter, defaultValue);
}
///
/// Gets the property for a given attribute reference or returns null if the reference is null.
///
/// The attribute type
/// The type of the attribute's property
/// The attribute reference
/// The function to evaluate on the attribute
///
internal static TResult GetPropertyValue(this TAttribute attribute, Func propertyGetter)
where TResult : class
where TAttribute : Attribute {
return attribute.GetPropertyValue(propertyGetter, null);
}
///
/// Gets the property for a given attribute reference or returns the default value if the reference is null.
///
/// The attribute type
/// The type of the attribute's property
/// The attribute reference
/// The function to evaluate on the attribute
/// The default value to return if the attribute is null
///
internal static TResult GetPropertyValue(this TAttribute attribute, Func propertyGetter, TResult defaultValue)
where TAttribute : Attribute {
if (attribute != null) {
return propertyGetter(attribute);
}
else {
return defaultValue;
}
}
}
}
// 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
- BuildProvider.cs
- SafeMILHandle.cs
- OutputCacheSettingsSection.cs
- UrlMappingsModule.cs
- CurrentTimeZone.cs
- TypeGeneratedEventArgs.cs
- WebPartConnectionCollection.cs
- BaseTransportHeaders.cs
- OdbcConnectionOpen.cs
- EventLogPermission.cs
- AssemblyHash.cs
- XmlBaseWriter.cs
- EventProviderWriter.cs
- AppSettingsReader.cs
- DomainUpDown.cs
- PartialList.cs
- DebuggerAttributes.cs
- RMPermissions.cs
- EntityClientCacheKey.cs
- Underline.cs
- CompModSwitches.cs
- CacheForPrimitiveTypes.cs
- ResourceDescriptionAttribute.cs
- PriorityBindingExpression.cs
- TextRangeEditLists.cs
- SetIterators.cs
- DetailsViewPageEventArgs.cs
- PowerStatus.cs
- SqlConnectionPoolProviderInfo.cs
- XMLSyntaxException.cs
- MultiPropertyDescriptorGridEntry.cs
- KnownTypesHelper.cs
- ExtendedPropertyDescriptor.cs
- CodeGeneratorOptions.cs
- DataSet.cs
- dsa.cs
- CustomSignedXml.cs
- HMACRIPEMD160.cs
- DesignerTransactionCloseEvent.cs
- Bits.cs
- SqlMethodTransformer.cs
- CodeAccessPermission.cs
- Geometry.cs
- ByteStreamMessageEncodingElement.cs
- TextTreeTextElementNode.cs
- WsdlBuildProvider.cs
- DatePicker.cs
- Decimal.cs
- RectangleHotSpot.cs
- TdsParserStateObject.cs
- ResourceDictionaryCollection.cs
- MonthChangedEventArgs.cs
- WizardStepBase.cs
- SqlBulkCopyColumnMapping.cs
- BitmapEffectState.cs
- MatcherBuilder.cs
- SetStoryboardSpeedRatio.cs
- XmlDomTextWriter.cs
- XmlNodeChangedEventManager.cs
- StringValidatorAttribute.cs
- QuadraticBezierSegment.cs
- HtmlGenericControl.cs
- FactoryGenerator.cs
- Char.cs
- EntityDataSourceEntitySetNameItem.cs
- MobileListItem.cs
- ObjectDisposedException.cs
- EventLogPermissionEntry.cs
- StylusOverProperty.cs
- HyperLink.cs
- WorkflowServiceNamespace.cs
- TextBox.cs
- HelpInfo.cs
- ParserStreamGeometryContext.cs
- MimeTypePropertyAttribute.cs
- ContractInstanceProvider.cs
- SuppressIldasmAttribute.cs
- CharConverter.cs
- TreeNode.cs
- SoapFault.cs
- sortedlist.cs
- RuntimeEnvironment.cs
- OperationAbortedException.cs
- PromptStyle.cs
- ClientOptions.cs
- ObfuscateAssemblyAttribute.cs
- AutomationPropertyInfo.cs
- DbModificationCommandTree.cs
- InstanceKeyNotReadyException.cs
- WebPartDeleteVerb.cs
- DecimalAnimationUsingKeyFrames.cs
- HttpApplication.cs
- EventItfInfo.cs
- Panel.cs
- LinqDataSourceDeleteEventArgs.cs
- XmlTypeMapping.cs
- StagingAreaInputItem.cs
- Propagator.Evaluator.cs
- SystemResources.cs
- ArrayTypeMismatchException.cs