Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Delegate.CreateDelegate in so non static function

Delegate.CreateDelegate in so non static function

Scheduled Pinned Locked Moved C#
helpquestiontutorial
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bonzaiholding
    wrote on last edited by
    #1

    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...

    B 1 Reply Last reply
    0
    • B bonzaiholding

      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...

      B Offline
      B Offline
      bonzaiholding
      wrote on last edited by
      #2

      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);

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups