本文整理汇总了C#中System.Attribute.Where方法的典型用法代码示例。如果您正苦于以下问题:C# Attribute.Where方法的具体用法?C# Attribute.Where怎么用?C# Attribute.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Attribute
的用法示例。
在下文中一共展示了Attribute.Where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAppliedAttributes
private static Attribute[] GetAppliedAttributes(Type memberType, Attribute[] attributes)
{
if (!memberType.IsCollection())
return attributes;
PerKeyAttribute perKey = null;
PerValueAttribute perValue = null;
var isDictionary = memberType.IsImplementerOfRawGeneric(typeof(IDictionary<,>));
for (int i = 0; i < attributes.Length; i++)
{
var attr = attributes[i];
var perItem = attr as PerItemAttribute;
if (perItem != null)
{
if (isDictionary)
{
Debug.LogError("PerItem should be applied on lists or arrays, not dictionaries!");
return null;
}
if (perItem.ExplicitAttributes == null)
return null;
return attributes.Where(x => !perItem.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray();
}
if (!isDictionary)
continue;
if (perKey != null && perValue != null)
break;
if (perKey == null)
perKey = attr as PerKeyAttribute;
if (perValue == null)
perValue = attr as PerValueAttribute;
}
if (perKey == null && perValue == null)
return attributes;
if (perKey != null && perValue != null &&
(perKey.ExplicitAttributes == null || perValue.ExplicitAttributes == null))
{
Debug.LogError("Confusion: If you use both PerKey and PerValue, then you should explictly mention which attributes are applied per key and which per value! (Info: MemberType ({0}) Attributes({1})".FormatWith(memberType.GetNiceName(), string.Join(", ", attributes.Select(x=>x.GetType().Name).ToArray())));
return null;
}
if (perKey != null)
{
if (perKey.ExplicitAttributes != null)
attributes = attributes.Where(x => !perKey.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray();
else
attributes = new Attribute[] { perKey };
}
if (perValue != null)
{
if (perValue.ExplicitAttributes != null)
attributes = attributes.Where(x => !perValue.ExplicitAttributes.Contains(x.GetType().Name.Replace("Attribute", ""))).ToArray();
else
attributes = new Attribute[] { perValue };
}
return attributes;
}