Home
Options

My Extensions ??

This functions as a C3 program in LINQPad4
void Main()
{
var t = new Dictionary();
t.GetType().Implements().Dump();
}

// Define other methods and classes here
public static class TTTT
{
public static bool Implements(this Type type) where TInterface : class
{
var interfaceType = typeof(TInterface);

//if (!interfaceType.IsInterface) { throw new InvalidOperationException("Only interfaces can be implemented."); }

return (interfaceType.IsAssignableFrom(type));
}

}
But if i move the extension to "My Extensions" (other extensionmethods deleted for abbrevity):

public static class MyExtensions
{
// Write custom extension methods here. They will be available to all queries.
public static bool Implements(this Type type) where TInterface : class
{
var interfaceType = typeof(TInterface);

if (!interfaceType.IsInterface) { throw new InvalidOperationException("Only interfaces can be implemented."); }

return (interfaceType.IsAssignableFrom(type));
}

}
I get the error message:
"'System.Type' does not contain a definition for 'Implements' and no extension method 'Implements' accepting a first argument of type 'System.Type' could be found (press F4 to add a using directive or assembly reference)"

Am i doing something wrong?

Comments

  • Options
    Hmm.... Just discovered the problem....

    In the rest of "My Extensions" was a default(T) written as Default(T).....

    This caused that the "My Extensions" did not recompile and that the old compiled was used. That way the other extensions functioned, but the new one (Implements) did not....
Sign In or Register to comment.