Ejemplo n.º 1
0
 /// <summary>create a type</summary>
 /// <param name="type"></param>
 /// <param name="constructorInfo"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public static Object CreateInstance(Type type, ConstructorInfo constructorInfo, Object[] parameters)
 {
     try
     {
         if (InvokeRequired(null, type))
         {
             GuiInteractive guiUtils = new GuiInteractive();
             return(guiUtils.ReflectionInvoke(constructorInfo, type, parameters, (constructorInfo == null)));
         }
         else
         {
             if (constructorInfo != null)
             {
                 return(constructorInfo.Invoke(parameters));
             }
             else //default constructor
             {
                 return(type.Assembly.CreateInstance(type.FullName));
             }
         }
     }
     catch (Exception e)
     {
         if (e is TargetInvocationException && e.InnerException != null)
         {
             throw e.InnerException;
         }
         else
         {
             throw e;
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>invoke snippet method</summary>
 /// <param name="assemblyHashCode"></param>
 /// <param name="methodInfo"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 public static Object InvokeSnippetMethod(int assemblyHashCode, MethodBase methodInfo, Object[] parameters)
 {
     try
     {
         if (IsGuiThreadExecution(assemblyHashCode))
         {
             GuiInteractive guiUtils = new GuiInteractive();
             return(guiUtils.ReflectionInvoke(methodInfo, null, parameters));
         }
         else
         {
             return(methodInfo.Invoke(null, parameters));
         }
     }
     catch (Exception e)
     {
         if (e is TargetInvocationException && e.InnerException != null)
         {
             throw e.InnerException;
         }
         else
         {
             throw e;
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>Get Property</summary>
 /// <param name="propInfo"></param>
 /// <param name="o"></param>
 /// <param name="index"></param>
 /// <returns></returns>
 public static Object GetPropertyValue(PropertyInfo propInfo, Object o, object[] index)
 {
     try
     {
         if (InvokeRequired(o, propInfo.ReflectedType))
         {
             GuiInteractive guiUtils = new GuiInteractive();
             return(guiUtils.ReflectionInvoke(propInfo, o, index));
         }
         else
         {
             return(propInfo.GetValue(o, index));
         }
     }
     catch (Exception e)
     {
         if (e is TargetInvocationException && e.InnerException != null)
         {
             throw e.InnerException;
         }
         else
         {
             throw e;
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>call method</summary>
 /// <param name="methodInfo"></param>
 /// <param name="value"></param>
 /// <param name="parameters"></param>
 /// <param name="alwaysGuiThread">if true,executed in GUI thread</param>
 /// <returns></returns>
 public static Object InvokeMethod(MethodBase methodInfo, Object obj, Object[] parameters, bool alwaysGuiThread)
 {
     try
     {
         if (InvokeRequired(obj, methodInfo.ReflectedType, alwaysGuiThread))
         {
             GuiInteractive guiUtils = new GuiInteractive();
             return(guiUtils.ReflectionInvoke(methodInfo, obj, parameters));
         }
         else
         {
             return(methodInfo.Invoke(obj, parameters));
         }
     }
     catch (Exception e)
     {
         if (e is TargetInvocationException && e.InnerException != null)
         {
             throw e.InnerException;
         }
         else
         {
             throw e;
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>Get field</summary>
 /// <param name="fieldInfo"></param>
 /// <param name="o"></param>
 /// <returns></returns>
 public static Object GetFieldValue(FieldInfo fieldInfo, Object o)
 {
     if (InvokeRequired(o, fieldInfo.ReflectedType))
     {
         GuiInteractive guiUtils = new GuiInteractive();
         return(guiUtils.ReflectionInvoke(fieldInfo, o, null));
     }
     else
     {
         return(fieldInfo.GetValue(o));
     }
 }