From: Argiris K. <be...@us...> - 2005-11-17 15:06:39
|
Update of /cvsroot/magicajax/magicajax/Core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24166/Core Added Files: Util.cs Log Message: Helper methods for the framework. --- NEW FILE: Util.cs --- using System; using System.Collections; using System.Web.UI; namespace MagicAjax { /// <summary> /// Helper methods intented to be used internally be the framework. /// </summary> internal class Util { /// <summary> /// Call a private method from the given object. /// </summary> /// <param name="instance"></param> /// <param name="type"></param> /// <param name="methodName"></param> /// <param name="parameters"></param> /// <returns></returns> public static object CallPrivateMethod (object instance, Type type, string methodName, params object[] parameters) { return type.GetMethod(methodName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).Invoke(instance, parameters); } public static void SetPrivateField (object instance, Type type, string fieldName, object value) { type.GetField(fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).SetValue(instance, value); } public static object GetPrivateField (object instance, Type type, string fieldName) { return type.GetField(fieldName, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic).GetValue(instance); } public static ArrayList GetChildControlsOfType (Control parentControl, Type type, bool onlyVisible) { ArrayList list = new ArrayList(); for (int i=0; i < parentControl.Controls.Count; i++) { Control con = parentControl.Controls[i]; if (onlyVisible && !con.Visible) continue; if ( type.IsInstanceOfType(con) ) list.Add (con); list.AddRange (GetChildControlsOfType(con, type, onlyVisible)); } return list; } private Util() { } } } |