If your really implement Parse the way it can parse into any type (which is hard to believe, but let's assume if does it for some type(s)), I would expect it does this:
IPatternMatch matchUri =
Response.Uri = matchUri.Parse<system.uri>();
</system.uri>
That is, the generic parameter should be known statically at the moment of compilation. I think this defeats the purpose of your design; and it means your whole design is wrong as you slightly misunderstood generics and mix it with OOP
late binding (which one can assume looking at your last code line which would not compile).
This can be also seen from the fact that you Result property is of the base type
Object
and depends on the
System.Type ResultType
. If you used generic approach for this type, whole interface should be generic:
interface IPatternMatch<T>
{
bool Match(string html);
T Parse();
T Result { get; }
}
class IntegerMatch : IPatternMatch<int>
{
bool Match(string html) { return int.TryParse(html, out FResult); }
int IPatternMatch<int>Parse() { }
int IPatternMatch<int>Result { get { return FResult; } }
int FResult;
}
class UriMatch : IPatternMatch<System.Uri>
{ }
Is this idea enough for you to implement your desired behavior?
From my comments in the code you should see the interface should be changed.
That would work; and I don't see how your design could work. I cannot "fix" it though, because you did not explain your ultimate goal or general idea, because your explanation of "what you want" was "contaminated" with "how to do it". If you explained the "pure" idea or requirements, I would probably be able to offer a reasonable design.
—SA