c# - Generics appear not to be the same in class and method -



c# - Generics appear not to be the same in class and method -

i asked question before set on hold because problem 'simple' conversion problem. me isn't. first time seek work generics.

i have class code here without errors:

internal class gridbox<t> : boxbase // t : new() { public gridbox(grid grid, gridboxview view, messageboxicon icon, string caption, observablecollection<t> datasource, messageboxbutton button) : base(grid, icon, caption, button) { view = view; datasource = datasource; } public gridboxview view { get; set; } public observablecollection<t> datasource { get; set; } }

next utilize class pass lot of info between different classes starting code below:

public static t show<t>(dependencyobject sender, messageboxicon icon, string caption, observablecollection<t> datasource, messageboxbutton button) t : icomparable<t>, new() { window window = window.getwindow(sender); grid grid = extensions.findchild<grid>(window); gridboxview gridbox = new gridboxview(); homecoming gridbox.show<t>(new gridbox<t>(grid, gridbox, icon, caption, datasource, button)); }

this code can compiled without errors. right if where t : icomparable<t> needed utilize t within method , , new() needed utilize @ new gridbox<t>? again, first time experimenting generics.

the above code calls show<t> below here:

internal class gridboxviewmodel<t> : boxbaseviewmodel // t : new() { public t show<t>(gridbox<t> gridbox) { // set content item datasource = gridbox.datasource; // set visual items , block excecution code addview(gridbox.grid, gridbox.view, gridbox.icon, gridbox.caption, gridbox.button); // homecoming value homecoming selecteditem; } public observablecollection<t> datasource { get; set; } public t selecteditem { get; set; } }

here problems start. datasource = gridbox.datasource gives error can't convert system.collections.objectmodel.observablecollection<t> system.collections.objectmodel.observablecollection<t> appears me same. both referring same class library [c:\program files (x86)\reference assemblies\microsoft\framework\.netframework\v4.5\system.dll].

the sec problem return selecteditem;. error here pretty much same bit different tho. can't convert 't' 't [controls\viewmodels\gridboxviewmodel.cs(6)]'.

the obvious reason me t @ internal class gridboxviewmodel<t> : boxbaseviewmodel isn't same t @ public t show<t>(gridbox<t> gridbox). cause , if so, how should handle problem , prepare it?

remove generic parameter show:

public t show(gridbox<t> gridbox)

the t type parameter different 1 declared on class why compiler error.

c# generics

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -