Added hammock project to debug streaming issues
[pithos-ms-client] / trunk / hammock / src / net35 / Hammock / Extensions / ReflectionExtensions.cs
1 using System.Collections.Generic;
2 using System.Reflection;
3
4 namespace Hammock.Extensions
5 {
6     internal static class ReflectionExtensions
7     {
8         public static IEnumerable<T> GetCustomAttributes<T>(this PropertyInfo info, bool inherit)
9             where T : class
10         {
11             var attributes = info.GetCustomAttributes(typeof (T), inherit);
12             return attributes.ToEnumerable<T>();
13         }
14
15         public static object GetValue(this object instance, string property)
16         {
17             var info = instance.GetType().GetProperty(property);
18             if (info != null)
19             {
20                 var value = info.GetValue(instance, null);
21                 return value;
22             }
23             return null; 
24         }
25
26         public static void SetValue(this object instance, string property, object value)
27         {
28             var info = instance.GetType().GetProperty(property);
29             info.SetValue(instance, value, null);
30         }
31     }
32 }