c# - Convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.IList<>' -


in model account have property this

public list<string> roles { get; set; } 

later on want property convert ilist<iapplicationuserrole<role>>, have function

 public ilist<iapplicationuserrole<role>> roles     {                 {             return _account.roles; // how convert in specific type intended.          }     } 

here iapplicationuserrole

public interface iapplicationuserrole<trolemodel> : irole<string>     trolemodel : entitymodel {     trolemodel role { get; set; }      string name { get; set; } } 

i newbie thing. looking forward help.

say have implementing class like:

public class applicationuserrole : iapplicationuserrole<t> t : role {     public applicationuserrole()     {     }     public user user { get; set; }     public t role { get; set; } } 

then, you'd this:

public ilist<iapplicationuserrole<role>> roles {         {         return _account.roles             .select(r => new applicationuserrole { role = roleservice.findrolebyname(r) })             .cast<iapplicationuserrole<role>>()             .tolist();      } } 

where roleservice way of building role instance role name (which above r)

note: being said, there catch in above implementation. since roles property should not data access operations. so, in case, should create method instead of property.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -