Common interface for the Room and Player classes
To make it easier to work with CustomProperties, I created a static class with extension methods. But these methods differ only in the type of the input object (Room or Player). Otherwise they are identical. It would be possible to make a generic method that takes T as input, where T : ICustomProperties
.
Example:
public static int GetMyProperty(this Room room) { return (int)room.CustomProperties["MyProperty"]; } public static int GetMyProperty(this Player player) { return (int)player.CustomProperties["MyProperty"]; }
I would like to replace it with the following:
public static int GetMyProperty<T>(this T roomOrPlayer) where T : ICustomProperties { return (int)roomOrPlayer.CustomProperties["MyProperty"]; } public interface ICustomProperties { public Hashtable CustomProperties {get;} }
I can add the interface I need to the Photon.Realtime
namespace myself and set it for the Room and Player classes. But when downloading a new version of the SDK, I will have to repeat this.
Could the developers add the ability to work with CustomProperties in the same way for both Room and Player.
Comments
-
Hi @Sergei,
Thank you for choosing Photon!
Unfortunately there is no shared interface between the two although as you observed "they use the custom properties in the same way".
I would keep code duplicated or I would extend both classes to your own custom classes where you add the interface and maybe other things and then you would have to do the casting every time.
0