Delegate.CreateDelegate in so non static function
-
Hi, If i have Event in some class the contain a lot of function from its kink and i want each instance to check another term how can i get delegate to non static Methods? In the code the problem is in this line because the function need to be static but i need it to operate with the data inside of the instance: VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem), mi); (mi i MethodInfo the point to non static method). for example :
public class ValidationFunctionClass
{public int Id; public string Name; public bool Checked; public double Min; public double Max; public ValidSystem ValidSystemFunction;//Event #region List of condition functions public bool Nc(DuplexTSystem DTS) { return DTS.Nc>= Min && DTS.Nc <= Max; } public bool qr(DuplexTSystem DTS) { return DTS.qr >= Min && DTS.qr<= Max; } ....
}
And i want to have a list with all the condtions : other class:
class B
{public void InsertDataToList()
{
List<ValidationFunctionClass> m_ValidadtionFuncClass = new List<ValidationFunctionClass>();
System.Reflection.MethodInfo[] mi_Arr = typeof(ValidationFunctionClass).GetMethods();
int ind=0;
foreach (MethodInfo mi in mi_Arr)
{
ind++;
ValidationFunctionClass VFC = new ValidationFunctionClass();
VFC.Id = ind;
VFC.Name = mi.Name;
VFC.Checked = true;
VFC.Min = 0;
VFC.Max = 100;
VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem), mi);
m_ValidadtionFuncClass.Add(VFC);}
}
}
Can some when tell me what can i do this row VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem), mi); when the function is not static ? (Instance) Thanks for all your help... I need it...
-
Hi, If i have Event in some class the contain a lot of function from its kink and i want each instance to check another term how can i get delegate to non static Methods? In the code the problem is in this line because the function need to be static but i need it to operate with the data inside of the instance: VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem), mi); (mi i MethodInfo the point to non static method). for example :
public class ValidationFunctionClass
{public int Id; public string Name; public bool Checked; public double Min; public double Max; public ValidSystem ValidSystemFunction;//Event #region List of condition functions public bool Nc(DuplexTSystem DTS) { return DTS.Nc>= Min && DTS.Nc <= Max; } public bool qr(DuplexTSystem DTS) { return DTS.qr >= Min && DTS.qr<= Max; } ....
}
And i want to have a list with all the condtions : other class:
class B
{public void InsertDataToList()
{
List<ValidationFunctionClass> m_ValidadtionFuncClass = new List<ValidationFunctionClass>();
System.Reflection.MethodInfo[] mi_Arr = typeof(ValidationFunctionClass).GetMethods();
int ind=0;
foreach (MethodInfo mi in mi_Arr)
{
ind++;
ValidationFunctionClass VFC = new ValidationFunctionClass();
VFC.Id = ind;
VFC.Name = mi.Name;
VFC.Checked = true;
VFC.Min = 0;
VFC.Max = 100;
VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem), mi);
m_ValidadtionFuncClass.Add(VFC);}
}
}
Can some when tell me what can i do this row VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem), mi); when the function is not static ? (Instance) Thanks for all your help... I need it...
I Found the Solution, it's very simple, you neet to send the instance to the CreatreDelegate. in my case : VFC.ValidSystemFunction += (ValidSystem)Delegate.CreateDelegate(typeof(ValidSystem),VFC, mi);