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