Hello everyone, I’m currently working on a small little project and I’ve ran into a bit of an issue where shared models and logic are concerned, and I’m wondering how to resolve it, and what best practices around these issues might be.
I currently have a library (builds to .dll) that is referenced from both my Unity project and my Cloud Code solution. Inside of it I have a variety of data models, including enumerations for various things. Many of these data models also contain logic for things like validation. The idea was to have the same validation code be executable both client and server side.
So my project overall contains:
- SharedLibrary (containing models, enums, and validation logic)
- Unity Project (references SharedLibrary)
- Cloud Code Solution (references SharedLibrary)
An example of a data model might be the following
public enum PlayerType {
Type1 = 1,
Type2 = 2
...
}
public class PlayerData {
public DateTime lastUpdate { get; private set; }
public string profileName { get; private set; }
public PlayerType type { get; private set; }
public void setProfileName(string name) {
// Validation code
}
}
I ran into my problem the moment I generated the bindings for the cloud clode and noticed that my cloud code API bindings take the binding version of those data models, not the data models themselves (which I thought would be shared, but I suppose I was wrong). The result is that I cannot provide the data models from my shared library as parameters to the cloud code module functions I’ve exposed (despite them being the exact same models from the same dll), as it will reject it saying it cannot convert from one type to another (obviously because they are different since one is a generated binding).
So I suppose I have a two part question here.
- Is there a way to resolve this so that the models that I expose from my shared library can be used as the parameters for my cloud code module functions?
- What is the best practice with regards to this? Obviously my intent was to have the models and logic shared across both, from the same dll library, but wondering if that might not have been the best approach.
Thanks so much for your feedback!