Hello,
I’m making a C# ressource / framework and I came across this problematic ExpandoObject
/dynamic
type. So I made a Shared dll with my entities, just one named User
below.
public class User
{
public int Id { get; set; }
public string Test { get; set; }
}
The code is very simple on the client side we have a command that triggers when the command /callback is typed but I receive a dynamic or ExpandoObject. So when I want to access a property it is not typed. I tried a soft cast which result in a null reference and a hard (so it throw an exception).
RegisterCommand("callback", new Action<int, List<object>, string>((source, args, raw) =>
{
TriggerServerEvent("eventTestClientCallback", new Action<dynamic>((arg) =>
{
Debug.WriteLine($"receive from eventTestClientCallback {arg.Id}, {arg.Test}");
}));
}), false);
The server side just send an User with both property set.
private void eventTestClient([FromSource] Player player)
{
User user = new User();
user.Id = 1;
user.Test = "woah";
player.TriggerEvent("playerTest", user);
}
The thing is that I’d like to have a strongly typed object, a lot of people just say to serialize/deserialize the object with JSON just ot have it typed.
So here are my questions :
- Are objects castable somehow without the use of any serializer/deserializer or mapper ?
- Is this “feature” worked on or already suggested or impossible to implement ?
Thank you for reading.