I created an interface IRequest:
public interface IRequest
{
[DataMember(IsRequired = true)]
string EndUserIp { get; set; }
[DataMember(IsRequired = true)]
string TokenId { get; set; }
[DataMember(IsRequired = true)]
string ClientId { get; set; }
[DataMember(IsRequired = true)]
int TokenAgencyId { get; set; }
[DataMember(IsRequired = true)]
int TokenMemberId { get; set; }
}
and I implemented this in several classes; Now I need to check all the properties:
public static bool ValidateCommon(IRequest request)
{
if (string.IsNullOrWhiteSpace(request.ClientId))
throw new BusinessServiceException(ErrorType.InvalidRequest, "ClientId can not be null or Empty");
if (string.IsNullOrWhiteSpace(request.TokenId))
throw new BusinessServiceException(ErrorType.InValidSession, "TokenID should not be Null or Empty");
if (!IsValidTokenId(request.TokenId))
throw new BusinessServiceException(ErrorType.InValidSession, "TokenID is not in correct Format");
if (string.IsNullOrWhiteSpace(request.EndUserIp))
throw new BusinessServiceException(ErrorType.InValidIpAddress, "IP Address should not be Null or Empty");
if (!IsValidIp(request.EndUserIp))
throw new BusinessServiceException(ErrorType.InValidIpAddress, "IP Address is not in correct Format");
if (request.TokenAgencyId < 0)
throw new BusinessServiceException(ErrorType.InvalidRequest, "TokenAgencyId should be positive Integer");
if (request.TokenMemberId <= 0)
throw new BusinessServiceException(ErrorType.InvalidRequest, "TokenMemberId should be positive Integer");
return true;
}
But I do not want to write this method again and again. So what is the right approach to do the same?
Rohit source
share