Friends,
I am asking this question with performance as main concern. But I would like to know other possible advantages / disadvantages for both approaches.
The question is: Since properties are converted to methods in IL, could there be significant performance penalty if properties are called instead of accessing fields directly (from within class)?
I am designing a transformation class (PersonalizationConstructor) whose whole purpose is to “construct domain entity” from IDataReader.
I am thinking to accept IDataReader in constructor of this class (PersonalizationConstructor) and have protected virtual properties to return data from IDataReader record set; like:
protected virtual string ProductFilterCriteria { get; set; }
I could have 15+ properties in one class for this implementation. This way, a property could be overridden to check if record set has “XXX” field before accessing from record set (I do not want to have such check as default implementation for all).
Is it good to have 15+ virtual properties in a class for implementing above case?
Please do not focus much on IDataReader. My main concern is:
Since properties are converted to methods in IL, could there be significant **performance penalty if properties are called instead of accessing fields directly (from within class)?**
I would be having something like this:
class MainSite
{
protected virtual string ProductFilterCriteria
{
get
{
return _source["ProductFilterCriteria"];
}
}
protected virtual string Abc
{
get
{
return _source["Abc"];
}
}
protected virtual string Def
{
get
{
return _source["Def"];
}
}
..... many properties
}
class VirtualSite : MainSite
{
protected override string ProductFilterCriteria
{
get
{
return null;
}
}
}