I come from the JavaScript/TypeScript world and I'm learning some C#, just for fun. I am currently trying to do something I am very used to do in JS, which is having a payload that can change according to a variable inside a class. So, I tried the following:
namespace Shared.Commands
{
public class Command
{
public string clientUuid { get; set; }
public string type { get; set; }
public dynamic payload { get; set; }
}
}
So, in this example, I want to know which type payload
is based on the type
. I was wondering what would be alternatives to using dynamic
in this case, as I was looking at some articles and they mention that I should avoid using dynamic
as much as possible.
The point is: I am clueless as to how to implement this in any other way and would like some guidance. I would really appreciate any tips or examples.