c# - Converting inherited class with generic class property -


IListModel discloses a general inventory property, which is an abstract type of item item item item. But when I try to convert any Derivative orbit to IListModel, I get the "Object reference not set for an instance of an object" error.

  Public abstract class list itemModel {public string username {get; Set; } Public string SomeProperty {get; Set; }} Public Interface Illustudel & lt; T & gt; Where T: ListItemModel {list & lt; T & gt; Item {get; Set; }} Public Category UserListModel: IListModel & lt; UserListItemModel & gt; {Public string query {get; Set; } Public Intel TotalUsers {get; Set; } Public listing & lt; UserListItemModel & gt; Item {get; Set; }} Public class UserListItemModel: ListItemModel {public string first name {get; Set; } Public String LastName {get; Set; }} Var users = new UserListModel {query = "a", total user = 1111, item = new list & lt; UserListItemModel & gt; {New UserListItemModel {FirstName = "a", last name = "B"}}}; // Later application will be passed to users as an object which will be sent to LICTML & lt; ListItemModel & gt; To use your properties, but converted the converted null value = users to ILISTODEL & lt; ListItemModel & gt; Forex Currency (Various Items in Converted Items) Item) {item.SomeProperty = DoSomethingHere (item.UserName); }   

I'm trying to get here which is able to populate some proprietary list items from the itemmodel baseclass.

please see:

However, if the conversion is not possible, So instead of raising the exception, as a return tap.

Actually, what is happening is that you are doing an invalid artist, and the result of that illegal artist depends on the form of castings used.

  var changed = users as elitodels & lt; ListItemModel & gt; // Converted Null variation = (Eististellel & lt; ListItemModel & gt;) user; // raises the exception   

Is it really necessary? UserListModel: IListModel & lt; UserListItemModel & gt; This indicates that this is a type of IListModel you want, so you should be able to provide it only in the pressure block and work with it, do not you?

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -