Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
pluginbase.Helpers.Extensions.ReflectionExtensions Class Reference

Classes

class  UnifiedVariable
 

Public Member Functions

delegate void UnifiedSetter (object obj, object val)
 
delegate object UnifiedGetter (object obj)
 

Static Public Member Functions

static IEnumerable
< UnifiedVariable
GetMemberVars (this Type type, BindingFlags binding, Predicate< MemberInfo > predicate)
 Gets the members vars (Fields and Properties) of a type More...
 
static IEnumerable
< UnifiedVariable
GetAllMemberVars (this Type type, Predicate< MemberInfo > predicate)
 Gets all member vars, including privates, of each class More...
 
static IEnumerable< Type > GetImplementingClasses (this Type type)
 Gets all classes and superclasses, starting from the top-level class and going to base class More...
 
static IEnumerable< MethodInfo > GetAllMethods (this Type type, Predicate< MethodInfo > predicate)
 Finds all methods in a type, included private ones, that satisfy the predicate More...
 
static IEnumerable< MethodInfo > GetAllMethods (this Type type)
 

Member Function Documentation

static IEnumerable<UnifiedVariable> pluginbase.Helpers.Extensions.ReflectionExtensions.GetAllMemberVars ( this Type  type,
Predicate< MemberInfo >  predicate 
)
static

Gets all member vars, including privates, of each class

Returns
The all member variables.
Parameters
typeType.
predicatePredicate.
90  {
91  const BindingFlags BINDINGS = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
92 
93  //To get all member types, we need to dive into each implementation of the type
94  var vars = new HashSet<UnifiedVariable>();
95 
96  foreach(var subtype in GetImplementingClasses(type))
97  {
98  foreach(var member in GetMemberVars(subtype, BINDINGS, predicate))
99  {
100  if (vars.Add(member))
101  yield return member;
102  }
103  }
104  }
static IEnumerable< Type > GetImplementingClasses(this Type type)
Gets all classes and superclasses, starting from the top-level class and going to base class ...
Definition: ReflectionExtensions.cs:111
static IEnumerable< UnifiedVariable > GetMemberVars(this Type type, BindingFlags binding, Predicate< MemberInfo > predicate)
Gets the members vars (Fields and Properties) of a type
Definition: ReflectionExtensions.cs:47
static IEnumerable<MethodInfo> pluginbase.Helpers.Extensions.ReflectionExtensions.GetAllMethods ( this Type  type,
Predicate< MethodInfo >  predicate 
)
static

Finds all methods in a type, included private ones, that satisfy the predicate

Returns
The all methods.
Parameters
typeType.
predicatePredicate.
128  {
129  const BindingFlags BINDINGS = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
130 
131  foreach(var cls in GetImplementingClasses(type))
132  {
133  foreach(var method in cls.GetMethods(BINDINGS))
134  {
135  if (method.DeclaringType == cls && predicate(method))
136  {
137  yield return method;
138  }
139  }
140  }
141  }
static IEnumerable< Type > GetImplementingClasses(this Type type)
Gets all classes and superclasses, starting from the top-level class and going to base class ...
Definition: ReflectionExtensions.cs:111
static IEnumerable<MethodInfo> pluginbase.Helpers.Extensions.ReflectionExtensions.GetAllMethods ( this Type  type)
static
144  {
145  return GetAllMethods(type, x => true);
146  }
static IEnumerable< MethodInfo > GetAllMethods(this Type type, Predicate< MethodInfo > predicate)
Finds all methods in a type, included private ones, that satisfy the predicate
Definition: ReflectionExtensions.cs:127
static IEnumerable<Type> pluginbase.Helpers.Extensions.ReflectionExtensions.GetImplementingClasses ( this Type  type)
static

Gets all classes and superclasses, starting from the top-level class and going to base class

Returns
The implementing classes.
Parameters
typeType.
112  {
113  Type curr = type;
114  do
115  {
116  yield return curr;
117  curr = curr.BaseType;
118  } while(curr != null);
119  }
static IEnumerable<UnifiedVariable> pluginbase.Helpers.Extensions.ReflectionExtensions.GetMemberVars ( this Type  type,
BindingFlags  binding,
Predicate< MemberInfo >  predicate 
)
static

Gets the members vars (Fields and Properties) of a type

Returns
The member variables.
Parameters
typeType.
bindingBinding.
predicatePredicate.
48  {
49  foreach(var prop in type.GetProperties(binding).Where(x => predicate(x)))
50  {
51  var realProp = prop.DeclaringType.GetProperty(prop.Name, binding);
52  var getMethod = realProp.GetGetMethod(true);
53  yield return new UnifiedVariable
54  {
55  Type = realProp.PropertyType,
56  Member = realProp,
57  Setter = realProp.GetSetMethod(true) != null ? (o,v) => realProp.SetValue(o, v, null) : (UnifiedSetter)null,
58  Getter = (o) => realProp.GetValue(o, null),
59  IsPrivate = getMethod.IsPrivate,
60  IsProtected = getMethod.IsFamily,
61  IsReadonly = false,
62  IsField = false
63  };
64  }
65 
66  foreach(var field in type.GetFields(binding).Where(x => predicate(x)))
67  {
68  var realField = field.DeclaringType.GetField(field.Name, binding);
69  yield return new UnifiedVariable
70  {
71  Type = realField.FieldType,
72  Member = realField,
73  Setter = realField.SetValue,
74  Getter = realField.GetValue,
75  IsPrivate = realField.IsPrivate,
76  IsReadonly = realField.IsInitOnly,
77  IsProtected = realField.IsFamily,
78  IsField = true,
79  };
80  }
81  }
delegate void UnifiedSetter(object obj, object val)
delegate object pluginbase.Helpers.Extensions.ReflectionExtensions.UnifiedGetter ( object  obj)
delegate void pluginbase.Helpers.Extensions.ReflectionExtensions.UnifiedSetter ( object  obj,
object  val 
)

The documentation for this class was generated from the following file: