-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathPropertyInfoExtensions.cs
More file actions
32 lines (28 loc) · 1.04 KB
/
PropertyInfoExtensions.cs
File metadata and controls
32 lines (28 loc) · 1.04 KB
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
using System;
using System.Linq;
using System.Reflection;
namespace Graphql.Extensions.FieldEnums.Types.Extensions
{
public static class PropertyInfoExtensions
{
private const BindingFlags DefaultLookup = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public;
public static PropertyInfo GetProperty
(
this Type type,
string name,
BindingFlags bindingAttr = DefaultLookup,
StringComparison comparisonType = StringComparison.Ordinal
)
{
return type.GetProperties(bindingAttr).SingleOrDefault(x => string.Equals(name, x.Name, comparisonType));
}
public static PropertyInfo EnsureDeclaringPropertyInfo(this PropertyInfo propertyInfo)
{
if (propertyInfo.DeclaringType == null || propertyInfo.ReflectedType == propertyInfo.DeclaringType)
{
return propertyInfo;
}
return propertyInfo.DeclaringType.GetProperty(propertyInfo.Name, DefaultLookup);
}
}
}