-
Notifications
You must be signed in to change notification settings - Fork 0
Convert
Miguel Bernard edited this page Jun 21, 2021
·
4 revisions
To simplify the usage of the library while providing strong consistency and typing many types support implicit cast to their less safe counterpart.
// NonEmptyString to string
string s = new NonEmptyString("SomeValue");
// CloudEvent<T> to CloudEvent
CloudEvent ce = new CloudEvent<UserCreated>(...);
CloudEvent<T> also supports strong casting to a different type. However, beware that feature can cause runtime errors as there no way for the compiler to determine if the types are compatible at compile time. Use at your own risk.
// assuming that UserCreated and UserModified inherit from IEvent
var userCreated = new CloudEvent<UserCreated>(new UserCreated());
var userCreatedAsIEvent = c.Cast<IEvent>();
var userModified = new CloudEvent<UserModified>(new UserModified());
var list = new List<CloudEvent<IEvent>>();
list.Add(userCreatedAsIEvent);
list.Add(userModified.Cast<IEvent>());IEvent userCreated = new UserCreated();
var ceIEvent = new CloudEvent<IEvent>(userCreated);
var ceUserCreated = ceIEvent.Cast<UserCreated>();