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. Where to hand over the instance of my plugin dll class to another class

Where to hand over the instance of my plugin dll class to another class

Scheduled Pinned Locked Moved C#
cssdesign
5 Posts 3 Posters 18 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.
  • A Offline
    A Offline
    AtaChris
    wrote on last edited by
    #1

    MyPluginDllClass
    {
    //Fields

    //Properties

    MyClass _myClass {get; set} = new(this); //this does not work !!!

    //Ctor
    public MyPluginDllClass
    {
    //do sth
    }

    //Member Functions
    public void Test1()
    {
    //do sth
    }

    }

    public MyClass
    {

    MyPluginDllClass \_instanceMyPluginDllClass;
    
    public MyClass(MyPluginDllClass param)
    {
    
    	\_instanceMyPluginDllClass = param;
    
    }
    
    
    //Member Functions
    public void Test2()
    {
        \_instanceMyPluginDllClass.Test1();
    }
    

    }

    Hello, for being able to see all properties in the UI of MyPluginDllClass I would have to instantiate MyClass as shown above in the properties area of MyPluginDllClass as follows:

    MyClass _myClass {get; set} = new(this);

    But this does not work, "this" seems to be unknown at this moment in time. The goal is to use all member functions and properties of MyPluginDllClass within MyClass and to make all properties of MyClass visible in the property grid of the UI of the main application. Any Ideas, hints what I am doing wrong or why this is the case. I do not have access to the code of the main application. MyPluginDllClass ist the interface to the main application.

    OriginalGriffO 1 Reply Last reply
    0
    • A AtaChris

      MyPluginDllClass
      {
      //Fields

      //Properties

      MyClass _myClass {get; set} = new(this); //this does not work !!!

      //Ctor
      public MyPluginDllClass
      {
      //do sth
      }

      //Member Functions
      public void Test1()
      {
      //do sth
      }

      }

      public MyClass
      {

      MyPluginDllClass \_instanceMyPluginDllClass;
      
      public MyClass(MyPluginDllClass param)
      {
      
      	\_instanceMyPluginDllClass = param;
      
      }
      
      
      //Member Functions
      public void Test2()
      {
          \_instanceMyPluginDllClass.Test1();
      }
      

      }

      Hello, for being able to see all properties in the UI of MyPluginDllClass I would have to instantiate MyClass as shown above in the properties area of MyPluginDllClass as follows:

      MyClass _myClass {get; set} = new(this);

      But this does not work, "this" seems to be unknown at this moment in time. The goal is to use all member functions and properties of MyPluginDllClass within MyClass and to make all properties of MyClass visible in the property grid of the UI of the main application. Any Ideas, hints what I am doing wrong or why this is the case. I do not have access to the code of the main application. MyPluginDllClass ist the interface to the main application.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      You can't use new(this) in a property initializer as the initializer would require the whole object to be initialised by that point, and that cannot be the case because the constructor has not been called yet. And obviously, the constructor can't be called until all property and field initializers are complete! So you would end up with a deadlock: the instance can't be created because to create the instance you need access to the fully constructed instance! :laugh: What you can do is move the initializer to the constructor:

      public class Bar
          {
          public Bar(Foo foo) { }
          }
      public class Foo
          {
          public Bar bar  {get; set;}
          public Foo ()
          {
          	bar = new(this);
          }
      }
      

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        You can't use new(this) in a property initializer as the initializer would require the whole object to be initialised by that point, and that cannot be the case because the constructor has not been called yet. And obviously, the constructor can't be called until all property and field initializers are complete! So you would end up with a deadlock: the instance can't be created because to create the instance you need access to the fully constructed instance! :laugh: What you can do is move the initializer to the constructor:

        public class Bar
            {
            public Bar(Foo foo) { }
            }
        public class Foo
            {
            public Bar bar  {get; set;}
            public Foo ()
            {
            	bar = new(this);
            }
        }
        

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        While I appreciate all the syntactic shortcuts Anders and friends are giving us in the C# language, I feel it's getting a bit ridiculous. We're quickly approaching a point where the shortcuts are making the code unreadable and harder to understand for noobs in favor of making it faster to type. I suspect the new shortcut is giving the OP trouble in understanding what's going on.

        Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

        OriginalGriffO 1 Reply Last reply
        0
        • D Dave Kreskowiak

          While I appreciate all the syntactic shortcuts Anders and friends are giving us in the C# language, I feel it's getting a bit ridiculous. We're quickly approaching a point where the shortcuts are making the code unreadable and harder to understand for noobs in favor of making it faster to type. I suspect the new shortcut is giving the OP trouble in understanding what's going on.

          Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          I agree - the same thing happened to C++ to the point where it's almost unreadable now.

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          D 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            I agree - the same thing happened to C++ to the point where it's almost unreadable now.

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            LOL. I think that's the primary reason why I don't do C++ anymore. That and someone has to pick up my code and maintain it after I'm gone and it's easier to find a C# dev (or Java dev we can convert) than it is to find a C++ dev for the team I'm on.

            Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles. Dave Kreskowiak

            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