Based on my Scenario I have implemented Snippet
public static bool ArePropertiesEqual<T>(T entity, params (string propertyName, object constantValue)[] propertyValues)
{
Type entityType = typeof(T);
List<string> notMatchedProperties = new List<string>();
Dictionary<string, object> propertyValuesDict = propertyValues.ToDictionary(pair => pair.propertyName, pair => pair.constantValue);
foreach (var propertyValue in propertyValuesDict)
{
var property = entityType.GetProperty(propertyValue.Key);
//if propertie is going to be null
if (property == null)
{
throw new ArgumentException($"Property '{propertyValue.Key}' not found in type {entityType.Name}");
}
var entityValue = property.GetValue(entity);
if (!object.Equals(entityValue, propertyValue.Value))
{
StalwartError.affirm($"{entityValue} is Un-matched Value", StatusCodes.Status400BadRequest);
}
}
return true;
}
Do implementation Guys if any issue has placed in my snippet ... :-)