blob: 6364fa99109bf08113c7d5fcc4585fe51027a6ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
// -----------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Microsoft.Internal
{
internal static class AttributeServices
{
public static T[] GetAttributes<T>(this ICustomAttributeProvider attributeProvider) where T : class
{
return (T[])attributeProvider.GetCustomAttributes(typeof(T), false);
}
public static T[] GetAttributes<T>(this ICustomAttributeProvider attributeProvider, bool inherit) where T : class
{
return (T[])attributeProvider.GetCustomAttributes(typeof(T), inherit);
}
public static T GetFirstAttribute<T>(this ICustomAttributeProvider attributeProvider) where T : class
{
return GetAttributes<T>(attributeProvider).FirstOrDefault();
}
public static T GetFirstAttribute<T>(this ICustomAttributeProvider attributeProvider, bool inherit) where T : class
{
return GetAttributes<T>(attributeProvider, inherit).FirstOrDefault();
}
public static bool IsAttributeDefined<T>(this ICustomAttributeProvider attributeProvider) where T : class
{
return attributeProvider.IsDefined(typeof(T), false);
}
public static bool IsAttributeDefined<T>(this ICustomAttributeProvider attributeProvider, bool inherit) where T : class
{
return attributeProvider.IsDefined(typeof(T), inherit);
}
}
}
|