dimanche 21 juin 2020

using reflection to identify properties that are null or 0 for a web service application

I have a request entity that hits my endpoint. Let's say the entity is RequestEntity. It has certain Props of different types.

public class RequestEntity {
public RequestEntity(){
FriendList = new List<String>();
}

public string Name{get;set;}
public int Age{get;set;}
public FriendList{get;}
}

I want to operate on the entity only when a specific property is present and others are null. Is there any way for me to go through the object without having to write multiple if else blocks to check if only the required field is present and others are not. I thought of using reflection but I think it wont be a good idea as it is a webserver and reflection is slow. can anyone give any references or a better approach for it?





Aucun commentaire:

Enregistrer un commentaire