-
Notifications
You must be signed in to change notification settings - Fork 14
Customize generated models in client side
Signalgo visual studio extenstion allows to customize generated models client side. Let's consider, for example, we have server side a LanguaGeInfo class with "Id" and "Name" properties. How can I add client side a new property "IsEdited"? If we change something server side we loose everything client side because the VS extension re-creates all services references from zero. With ModelMap attribute (a SignalGo magic) we can do this!!
In this tutorial we will change generated models and keep the ability to re-generate services.
Create ModelsMap folder in the same client project where signalgo generates the services from the server.
Add the class in ModelsMap folder for which you want to customize its model. For example, we use the LanguageInfo class. Add then a LanguageInfoMap.cs in the new ModelsMap folder.
Use ModelMapp attribute over your LanguageInfoMap class and make the class inherits from the original (server defined) LanguageInfo class (you can use the name you want, but it's easier to simply add Map at the end of original name)
Source example:
[ModelMapp(typeof(LanguageInfo))]
public class LanguageInfoMap : LanguageInfo
{
private bool _IsEdited;
public bool IsEdited
{
get
{
return _IsEdited;
}
set
{
if (_IsEdited != value)
{
_IsEdited = value;
OnPropertyChanged(nameof(IsEdited));
}
}
}
}
Now you can use the extension to update your referenced services from server. To do this right click on the folder of yuor generated services (it's located into the "Connected Services" folder. Then click "Update Signalgo Service".
After the update you will see your LanguageInfo class has this new IsEdited property client side but not server side! That's easy!