I am looking for help to see if there is any better way to write code. I need to instantiate different implementation based on some value, but somehow I feel that I can write xyz property in more generic way
Here is the simple representation of my code
public class A
{
string p1;
IEnumerable<B> b;
}
public interface Ix
{
...
}
public class x1 : Ix
{
...
}
public class x2 : Ix
{
...
}
public class C
{
public C()
{
_a = GetA();
}
public List<Ix> xyz
{
get
{
if (_a.b == "sometype")
{
return _a.b.ToList().Select(r => new x1(r) as Ix).ToList();
}
else
{
return _a.b.ToList().Select(r => new x2(r) as Ix).ToList();
}
}
}
}
Please let me know if I can write xyz property in better way?
Thanks in advance.