I want a generic function that would work with types that have Top
, Bottom
, Right
and Rect
read-only properties - I have a lot of such classes in a third-party library.
I wrote this:
internal class MyTemplate<WhatType> {
internal static void Work( WhatType what )
{
int left = what.Left;
}
};
and I expect it to work - equivalent code in C++ would work okay. However C# objects:
error CS1061: 'WhatType' does not contain a definition for 'Left' and no extension method 'Left' accepting a first argument of type 'WhatType' could be found (are you missing a using directive or an assembly reference?)
I don't get it - why would it try to instantiate the template before I even call it? Of course, type WhatType
is not yet known and so no properties can be found.
What am I doing wrong and how do I fix that?