You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to create a tool with had the following structure at the beginning and would be easy to expand
-- parent command (has some 'global' options)
---- child command 1 (has some more 'global' options available for this and it's children + from parent command)
------ grandChild command 1 (has it's own options and arguments + from child command 1 + from parent command)
------ grandChild command 2 (has it's own options and arguments + from child command 1 + from parent command)
---- child command 2 (has some more 'global' options available for this and it's children + from parent command)
------ grandChild command 3 (has it's own options and arguments + from child command 2 + from parent command)
So i considered that inheritance with attribute api is the right call for me. I was consulting this sample.
I was expecting that something like this should work for me
In terms of code I had the following attributes on my ParentCommand: [Subcommand(typeof(ChildCommand))]
following on ChildCommand: [Command(Name = "childCommand"), Subcommand(typeof(GrandChildCommand1), typeof(GrandChildCommand2))])
and following on GrangChildCommands: [Command(Name = "grandChildCommand1/2")]
But after I tried to run it I got an error saying Subcommand cycle detected: trying to add command of model GrandChildCommand1 as its own direct or indirect subcommand, cause of the Attributes set like shown above.
When I made a deeper dive into the sample I undestood that inheritance is achieved via private field, so I was able to rewrite my case and started it correctly.
But now I'm curious what's the sense of having native C# inheritance in the first place, cause now my GrandChildCommands doesn't inherit on ChildCommand and can only inherit from ParentCommand (for some reason it doesn't fail that way), so I lose all benefits or OOP - I have to make all ChildCommand public to use them via private field, I can't use encapsulation and share most of the implementation in base class.
Moreover I don't understand why is it even an option to inherit from ParentCommand if I have ChildCommand (which inherits from ParentCommand) as well as a private field, and if I do the same manipulation with private field in ChildCommand I a can access ParentCommand's properties via it.
And also this type of 'inheritance' doesn't work with [required] attribute normally, cause it simply fails on child entities before it's been set with the help of reflection (I guess)
All in all, I didn't find an example of using native inheritance properly in samples and what I was able to create myself looks terrible, please tell me that I understood something wrong.
The text was updated successfully, but these errors were encountered:
I was trying to create a tool with had the following structure at the beginning and would be easy to expand
-- parent command (has some 'global' options)
---- child command 1 (has some more 'global' options available for this and it's children + from parent command)
------ grandChild command 1 (has it's own options and arguments + from child command 1 + from parent command)
------ grandChild command 2 (has it's own options and arguments + from child command 1 + from parent command)
---- child command 2 (has some more 'global' options available for this and it's children + from parent command)
------ grandChild command 3 (has it's own options and arguments + from child command 2 + from parent command)
So i considered that inheritance with attribute api is the right call for me. I was consulting this sample.
I was expecting that something like this should work for me
In terms of code I had the following attributes on my
ParentCommand
:[Subcommand(typeof(ChildCommand))]
following on
ChildCommand
:[Command(Name = "childCommand"), Subcommand(typeof(GrandChildCommand1), typeof(GrandChildCommand2))]
)and following on
GrangChildCommand
s:[Command(Name = "grandChildCommand1/2")]
But after I tried to run it I got an error saying
Subcommand cycle detected: trying to add command of model GrandChildCommand1 as its own direct or indirect subcommand
, cause of the Attributes set like shown above.When I made a deeper dive into the sample I undestood that inheritance is achieved via private field, so I was able to rewrite my case and started it correctly.
But now I'm curious what's the sense of having native C# inheritance in the first place, cause now my
GrandChildCommands
doesn't inherit onChildCommand
and can only inherit fromParentCommand
(for some reason it doesn't fail that way), so I lose all benefits or OOP - I have to make all ChildCommand public to use them via private field, I can't use encapsulation and share most of the implementation in base class.Moreover I don't understand why is it even an option to inherit from
ParentCommand
if I haveChildCommand
(which inherits fromParentCommand
) as well as a private field, and if I do the same manipulation with private field in ChildCommand I a can accessParentCommand
's properties via it.And also this type of 'inheritance' doesn't work with [required] attribute normally, cause it simply fails on child entities before it's been set with the help of reflection (I guess)
All in all, I didn't find an example of using native inheritance properly in samples and what I was able to create myself looks terrible, please tell me that I understood something wrong.
The text was updated successfully, but these errors were encountered: