Dynamically find the parameter to be passed as <T> to a generic method
- by Codex
A generic method is defined as follows:
private static T GetComparisonObject<T>(ComparisonAttribute attribute, object objectToParse)
{
// Perform a some action
return (T)resultObject;
}
The method is invoked as follows:
var srcObjectToCompare = GetComparisonObject<DynamicType>(attributeToCompare, srcObject);
The type for which the method needs to be invoked is configured in the config file as:
<add attributename ="Count" attributetype ="MemberInformation" attributeparam ="Count" type="System.Int32" comparertype="ditCreditEMGTestAutomationDifferenceEngine.Comparers.TypeComparer, ditCreditEMGTestAutomationDifferenceEngine.dll" />
The token that is passed in < for the generic methods has to be the type for which the method is being invoked. From the type key configuration in the XML, an instance of Type represnting the type can be created{i.e. Type.GetType("System.Int32")}, but how can the Type Definition be generated which can then be passed to the the Generic method?
Hope am not missing something elementary here!! :-O
Thanks in advance.