I have the following code in my program: This code will iterate through hundreds of thousands of records and i therefore need to look to see if it can be improved:
private void FillObjectTypes(Type type, ElementMapping mapping )
{
foreach (var fieldMapping in mapping.FieldMappings.Values.Where(mpng => mpng.ConversionType == ConversionType.InferFromPropertyType))
{
fieldMapping.PropertyType = ReflectionUtils.GetPropertyType(type, fieldMapping.PropertyName);
}
mapping.FieldMappingsTypesSet = true;
}
Any idea to an improvement of the code will be highly appreciated. My main question being how the lambda expression will affect performance.
And the code for the reflection below:
public static Type GetPropertyType(Type objectType, string propertyName)
{
CheckCache(objectType);
try
{
return propertiesByType[objectType][propertyName].PropertyType;
}
catch(KeyNotFoundException excp)
{
throw new KeyNotFoundException($"Failed to find property:'{propertyName}' in object type:'{objectType.Name}'",excp);
}
}