aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/CompilerServices/CompilerServices.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-12-14 17:20:54 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-12-14 17:20:54 +0100
commit28a9515ed47471f6e61166f33d5397679aa06b2f (patch)
tree542b9f7dbcbf6ec9fff5fcb67a21c88cbe47c1a4 /src/CompilerServices/CompilerServices.cs
parentbdd6f9a1db93cbe52ad35e17d909fd8eb28368d5 (diff)
property less bindings in template handling
Diffstat (limited to 'src/CompilerServices/CompilerServices.cs')
-rw-r--r--src/CompilerServices/CompilerServices.cs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs
index 8f587d39..731d1b5e 100644
--- a/src/CompilerServices/CompilerServices.cs
+++ b/src/CompilerServices/CompilerServices.cs
@@ -631,6 +631,33 @@ namespace Crow
return GetExtensionMethods (Assembly.GetExecutingAssembly(), t)
.Where (em => em.Name == methodName).FirstOrDefault ();
}
+
+ public static MemberInfo getMemberInfoWithReflexion(object instance, string member){
+ return instance.GetType ().GetMember (member).FirstOrDefault();
+ }
+ public static object getValueWithReflexion(object instance, MemberInfo mi){
+ object tmp = null;
+ Type dstType = null;
+ if (mi == null)
+ return null;
+ if (mi.MemberType == MemberTypes.Property) {
+ PropertyInfo pi = mi as PropertyInfo;
+ tmp = pi.GetValue (instance);
+ dstType = pi.PropertyType;
+ }
+ if (mi.MemberType == MemberTypes.Field) {
+ FieldInfo fi = mi as FieldInfo;
+ tmp = fi.GetValue (instance);
+ dstType = fi.FieldType;
+ }
+ if (tmp != null)
+ return tmp;
+ if (dstType == typeof(string))
+ return "";
+ if (dstType.IsValueType)
+ return Activator.CreateInstance (dstType);
+ return null;
+ }
}
}