101 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			101 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Reflection;
 | |
| using System.Text;
 | |
| 
 | |
| namespace DevComponents.DotNetBar.Design
 | |
| {
 | |
|     internal static class ReflectionHelpers
 | |
|     {
 | |
|         public static object GetValueProperty(object owner, string propertyName, BindingFlags flags)
 | |
|         {
 | |
|             if (owner == null)
 | |
|                 return (object)null;
 | |
|             PropertyInfo propertyInfo = owner.GetType().GetProperty(propertyName, flags);
 | |
|             return ReflectionHelpers.GetValueProperty(owner, propertyInfo);
 | |
|         }
 | |
| 
 | |
|         public static object GetValueProperty(object owner, PropertyInfo propertyInfo)
 | |
|         {
 | |
|             if (owner == null || propertyInfo == (PropertyInfo)null)
 | |
|                 return (object)null;
 | |
|             return propertyInfo.GetValue(owner, (object[])null);
 | |
|         }
 | |
| 
 | |
|         public static PropertyInfo GetPropertyInfo(object owner, string propertyName, BindingFlags flags)
 | |
|         {
 | |
|             if (owner == null)
 | |
|                 return (PropertyInfo)null;
 | |
|             return ReflectionHelpers.GetPropertyInfo(owner.GetType(), propertyName, flags);
 | |
|         }
 | |
| 
 | |
|         public static object InvokeMethod(object owner, string nameMethod, BindingFlags flags, object[] args)
 | |
|         {
 | |
|             MethodInfo methodInfo = ReflectionHelpers.GetMethodInfo(owner, nameMethod, flags);
 | |
|             return ReflectionHelpers.InvokeMethod(owner, methodInfo, args);
 | |
|         }
 | |
| 
 | |
|         public static MethodInfo GetMethodInfo(object owner, string nameMethod, BindingFlags flags)
 | |
|         {
 | |
|             if (owner == null)
 | |
|                 return (MethodInfo)null;
 | |
|             return ReflectionHelpers.GetMethodInfo(owner.GetType(), nameMethod, flags);
 | |
|         }
 | |
| 
 | |
|         public static MethodInfo GetMethodInfo(Type type, string nameMethod, BindingFlags flags)
 | |
|         {
 | |
|             if (type == (Type)null)
 | |
|                 return (MethodInfo)null;
 | |
|             return type.GetMethod(nameMethod, flags);
 | |
|         }
 | |
|         public static object InvokeMethod(object owner, MethodInfo methodInfo, object[] args)
 | |
|         {
 | |
|             if (methodInfo == (MethodInfo)null || owner == null)
 | |
|                 return (object)null;
 | |
|             return methodInfo.Invoke(owner, args);
 | |
|         }
 | |
| 
 | |
|         public static void SetValueField(object owner, string nameField, BindingFlags flags, object value)
 | |
|         {
 | |
|             FieldInfo fieldInfo = ReflectionHelpers.GetFieldInfo(owner, nameField, flags);
 | |
|             ReflectionHelpers.SetValueField(owner, fieldInfo, value);
 | |
|         }
 | |
| 
 | |
|         public static void SetValueField(object owner, FieldInfo fieldInfo, object value)
 | |
|         {
 | |
|             if (owner == null || fieldInfo == (FieldInfo)null)
 | |
|                 return;
 | |
|             fieldInfo.SetValue(owner, value);
 | |
|         }
 | |
| 
 | |
|         public static FieldInfo GetFieldInfo(Type type, string nameField, BindingFlags flags)
 | |
|         {
 | |
|             if (type == (Type)null)
 | |
|                 return (FieldInfo)null;
 | |
|             return type.GetField(nameField, flags);
 | |
|         }
 | |
| 
 | |
|         public static FieldInfo GetFieldInfo(object owner, string nameField, BindingFlags flags)
 | |
|         {
 | |
|             if (owner == null)
 | |
|                 return (FieldInfo)null;
 | |
|             return ReflectionHelpers.GetFieldInfo(owner.GetType(), nameField, flags);
 | |
|         }
 | |
| 
 | |
|         public static ConstructorInfo GetConstructorInfo(Type type, Type[] args)
 | |
|         {
 | |
|             if (type == (Type)null)
 | |
|                 return (ConstructorInfo)null;
 | |
|             return type.GetConstructor(args);
 | |
|         }
 | |
| 
 | |
|         public static object GetValueField(object owner, string nameField, BindingFlags flags)
 | |
|         {
 | |
|             if (owner == null) return null;
 | |
|             FieldInfo fieldInfo = owner.GetType().GetField(nameField, flags);
 | |
|             if (fieldInfo == null) return null;
 | |
|             return fieldInfo.GetValue(owner);
 | |
|         }
 | |
|     }
 | |
| }
 |