本文整理汇总了C#中Attribute.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# Attribute.OfType方法的具体用法?C# Attribute.OfType怎么用?C# Attribute.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Attribute
的用法示例。
在下文中一共展示了Attribute.OfType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheAttributes
private void CacheAttributes(Attribute[] attributes)
{
DataType = attributes.OfType<DataTypeAttribute>().FirstOrDefault();
Display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
DisplayColumn = attributes.OfType<DisplayColumnAttribute>().FirstOrDefault();
DisplayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
DisplayName = attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
Editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
#if false
HiddenInput = attributes.OfType<HiddenInputAttribute>().FirstOrDefault();
#endif
ReadOnly = attributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
Required = attributes.OfType<RequiredAttribute>().FirstOrDefault();
ScaffoldColumn = attributes.OfType<ScaffoldColumnAttribute>().FirstOrDefault();
var uiHintAttributes = attributes.OfType<UIHintAttribute>();
// Developer note: this loop is explicitly unrolled because Linq lambdas methods are not
// [SecuritySafeCritical] and generate security exceptions accessing DataAnnotations types.
UIHintAttribute bestUIHint = null;
foreach (UIHintAttribute uiHintAttribute in uiHintAttributes)
{
string presentationLayer = uiHintAttribute.PresentationLayer;
if (String.Equals(presentationLayer, "MVC", StringComparison.OrdinalIgnoreCase))
{
bestUIHint = uiHintAttribute;
break;
}
if (bestUIHint == null && String.IsNullOrEmpty(presentationLayer))
{
bestUIHint = uiHintAttribute;
}
}
UIHint = bestUIHint;
if (DisplayFormat == null && DataType != null)
{
DisplayFormat = DataType.DisplayFormat;
}
}
示例2: CachedDataAnnotationsMetadataAttributes
public CachedDataAnnotationsMetadataAttributes(Attribute[] attributes)
{
DataType = attributes.OfType<DataTypeAttribute>().FirstOrDefault();
Display = attributes.OfType<DisplayAttribute>().FirstOrDefault();
DisplayColumn = attributes.OfType<DisplayColumnAttribute>().FirstOrDefault();
DisplayFormat = attributes.OfType<DisplayFormatAttribute>().FirstOrDefault();
DisplayName = attributes.OfType<DisplayNameAttribute>().FirstOrDefault();
Editable = attributes.OfType<EditableAttribute>().FirstOrDefault();
HiddenInput = attributes.OfType<HiddenInputAttribute>().FirstOrDefault();
ReadOnly = attributes.OfType<ReadOnlyAttribute>().FirstOrDefault();
Required = attributes.OfType<RequiredAttribute>().FirstOrDefault();
ScaffoldColumn = attributes.OfType<ScaffoldColumnAttribute>().FirstOrDefault();
var uiHintAttributes = attributes.OfType<UIHintAttribute>();
UIHint = uiHintAttributes.FirstOrDefault(a => String.Equals(a.PresentationLayer, "MVC", StringComparison.OrdinalIgnoreCase))
?? uiHintAttributes.FirstOrDefault(a => String.IsNullOrEmpty(a.PresentationLayer));
if (DisplayFormat == null && DataType != null)
{
DisplayFormat = DataType.DisplayFormat;
}
}