C
C#2y ago
Ownix

❔ Is there a pattern for having a single collection of different object types?

This is my sample code https://dotnetfiddle.net/ffV3vY I have a WorkflowCommand a ScheduledWorkflowCommanddepending on their type they are executed in different ways. I would like to have a collection of them I can pass around and enumerate.
Help Creating List of two types | C# Online Compiler | .NET Fiddle
Help Creating List of two types | Test your C# code online with .NET Fiddle code editor.
5 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ownix
OwnixOP2y ago
@TeBeClone Can you fork the fiddle and show me? Or are you saying its as simple as: Before:
public class ScheduledWorkflowCommand
// ...
public class ScheduledWorkflowCommand
// ...
after
public class ScheduledWorkflowCommand : WorkflowCommand
// ...
public class ScheduledWorkflowCommand : WorkflowCommand
// ...
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Ownix
OwnixOP2y ago
@TeBeClone I think I have a working example now: https://dotnetfiddle.net/drzai7 Question, is there a way to take an existing command (public class Command2 : WorkflowCommand) and convert it to a ScheduledWorkflowCommand without defining a new class?
[Fork] Help Creating List of two types | C# Online Compiler | .NET ...
[Fork] Help Creating List of two types | Test your C# code online with .NET Fiddle code editor.
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.

Did you find this page helpful?