c# - Call a generic extension method on another generic extension method's parameter -


i'm doing asp.net mvc 3, , i'm setting couple extension methods working enums. 1 of them fancy tostring() looks [description] attribute, , other builds selectlist enum use html.dropdownlist(). both of these methods in same static class.

public static selectlist toselectlist<tenum>(this tenum? enumval) tenum : struct {     var values = tenum e in enum.getvalues(typeof(tenum)) select new { id = e, name = e.getdescription() };     selectlist list = new selectlist(values, "id", "name", enumval);     return list; }  public static string getdescription<tenum>(this tenum? enumval) tenum : struct {     //some reflection fetches [description] attribute, or returns enumval.tostring() if isn't defined. } 

but compiler squawks name = e.getdescription(), stating that...

'tenum' not contain definition 'getdescription' , no extension method 'getdescription' accepting first argument of type 'tenum' found (are missing using directive or assembly reference?)

this doesn't come huge surprise, i'm not sure how compiler recognize getdescription() valid extension method enumval parameter of toselectlist(). realize make work moving guts of getdescription() private static method, , making extension method wrapper that, chaining generic extension methods seems ought know how properly.

e not nullable struct; it's struct. getdescription takes nullable struct.

either make e nullable, or make non-nullable version of getdescription.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -