I have C# code running to compare pre and post-images in CRM to determine if a field changed (long story short: external process I can't control is updating every field on a record every time, even if fields haven't changed). I want to use the CRM GetAttributeValue(attributeName) to do it, but I want to do it dynamically when I may not know the field name. So, for example, I want to do this:
// pretend the value of firstname is not hard-coded but submitted on a form    
// (not really on a form, but just know it's not hard-coded like it is below.)
string fieldToCheck = "firstname"; 
if (preImage.GetAttributeValue<T>(fieldToCheck) != postImage.GetAttributeValue<T>(fieldToCheck))
{
  // do something here. I've tried something like the below, but it doesn't work with error "t is a variable but used like a type". 
  Type t = preImage.Attributes[fieldToCheck].GetType();
  var val = preImage.GetAttributeValue<t>(fieldToCheck);
}
The problem I'm having is that <T> could be different depending on the value of fieldToCheck. In the case of firstname it would be <string>, in the case of new_DateOpened it would be <DateTime>, etc. I must be having a brain spasm because I should be able to figure out how to dynamically get the value of T, but can't.
 
     
     
    