There is a fundamental misunderstanding of source vs compiled code here. The field name you give an object in source only has meaning
at coding time – the fact you called that variable 'fileReaderObj' is only relevant at compile time, at runtime that information is not present.
What you're doing sounds like it could be replaced by using an existing entity management system (like NHibernate), but if you are doing it yourself for good reason: you need to store a
runtime reference, either in the object or in a hash map that you look up into whenever you try to get one. For example:
Dictionary<string, FileReader> cache = new Dictionary<string, FileReader>();
FileReader GetFileReader(string key){
FileReader r;
if(!cache.TryGetValue(key, out r)) cache[key] = r = new FileReader(key);
return r;
}
void SomeMethod(){
FileReader fileReaderObj = GetFileReader("test");
}
Note that the key is set at
runtime to a string, not a field name. (Depending on what 'test' is you might need to pass it as well, if the FileReader needs information within that object.)