It's difficult to tell what your use case is exactly, but here is another angle on your question that may help. I'm assuming that all of the classes you can specify in your config have the same property (i.e. name
). If this is the case, you could have all of the classes implement the same interface, then you don't need to worry about the class name. For example:
Your interface:
public interface IName
{
string Name { get; set; }
}
A class that uses the interface:
public class Something : IName
{
public string Name { get; set; }
public string AnotherProperty { get; set; }
}
And a method that uses any object that implements the IName
interface:
public void DoSomething(IName input)
{
Console.WriteLine(input.Name);
}
So now you can call the method without having to worry about class names:
var someObject = new Something();
someObject.Name = "Bob";
DoSomething(someObject);