Simple Code Advice
When you do code, please avoid declaring not read only variables as a private property for a class. For example:

If your user reports a bug, then when you want to search the root cause of the problem, it will be challenging because it is very hard to check.

Suggestion
For maintainability purposes, always remember the KISS (Keep It Simple Stupid) principle. So for solving that problem, this is how I do it:
internal class RoomReservationHelper
{
private readonly IPluginExecutionContext _context;
private readonly IOrganizationService _service;
private readonly IOrganizationServiceFactory _serviceFactory;
public RoomReservationHelper(IPluginExecutionContext context,
IOrganizationServiceFactory serviceFactory, IOrganizationService service)
{
_context = context;
_serviceFactory = serviceFactory;
_service = service;
}
public void Execute()
{
var roomReservation = (Entity)_context.InputParameters["Target"];
var resvNo = roomReservation.Attributes["gent_name"].ToString();
var anotherRoomReservations = GetRelatedRoomReservation(roomReservation);
}
private Entity[] GetRelatedRoomReservation(Entity roomReservation)
{
var name = roomReservation.Attributes["gent_name"].ToString();
var number = .Attributes["gent_roomnumber"].ToString();
...
}
}
The Changes?
- We define variables when it's needed.
- We break 1 function into a smaller function. Make it more clear, more readable.
- All the property of the class is read-only, so this makes sure your class is thread-safe.
Leave a comment
Your comment is sent privately to the author and isn't published on the site.