Hi,
I need to design this type, to be returned from a method.
Now this method (let's just call this method GetValue), should return either a single instance of this type, or a collection of instances from this type.
Here's some pseudo code to make things hopefully clearer:
The returned type's initial definition (later on i tried to make several modifications to it to make it suitable for my needs):
public class ResultField
{
public string FieldName { get; set;}
public string FieldValue { get; set;}
}
public class DataHandler
{
public ResultField/IEnumerable<ResultField> GetValue(someKey) // Returns either ResultField or a collection of it
{
// Some decision making code
if someKey is bla then return ResultField
else return IEnumerable of ResultField
}
}
And here's the hopefully somewhat improved version of ResultField (so no need to use a collection anymore):
public class ResultField
{
public string FieldName { get; set;}
public string FieldValue { get; set;}
public IEnumerable<ResultField> Rows {get; set;}
}
But i still don't really like this solution. It contains fields that might not be relevant (if a single instance is needed, Rows is irrelevant, and vice versa).
Then I thought maybe use Composite pattern here somehow... but i'm not really on to something satisfactory (factory maybe? :)) here.
Any suggestions?
P.S
I'm not versed into using the dynamic features of .net 4.0, so if dynamic might help here somehow, that would be great too.
Thanks,
Avi