Hi All, I am developing a library component which requires some global settings. Personally I don’t like to maintain an xml configuration file for this. An idea strikes for me that to write an abstract class with an abstract method which can override and set global setting by the implementers of this library. The abstract class will look like something like this.
public abstract class LibSetting
{
public int MaxCount { get; set; }
public abstract void SetCount();
}
The end users will implement this abstract class in their application is as follows.
public class MySetting : LibSetting
{
public override void SetCount()
{
MaxCount = 100;
}
}
To get the end user setting from my library, I am using following code.
public int ShowCount()
{
Assembly asm = Assembly.GetCallingAssembly();
IEnumerable types = asm.GetTypes().Where(t => t.IsClass && t.BaseType == typeof(LibSetting));
LibSetting setting =(LibSetting) asm.CreateInstance(types.First().FullName);
setting.SetCount();
return setting.MaxCount;
}
This will work perfectly. My doubt is that, is it feasible in architecture level of view? I think the performance of read an xml file and loading a class using reflection would be same ( I didn’t test it). So is this a good practice? Kindly advice me on this. Thanks and Regards, Kannan