Is possible to set generic type by another class?

Posted by Soul_Master on Stack Overflow See other posts from Stack Overflow or by Soul_Master
Published on 2009-12-29T23:15:30Z Indexed on 2010/03/27 11:03 UTC
Read the original article Hit count: 180

Filed under:
|
|

I use ASP.NET MVC for serving web application and I want to create something like the following code.

<% using(HTML.Form(Model)) { %>
<%     HTML.CreateTextBox('txt1', x => x.Property1);
<% }

From the above code, Form extension method will receive object that represent type of current Model object in current View page. Next, CreateTextBox method will receive type from Form method and I can bind textbox to some property of this model.

Update 1

The following code is code of CreateTextBox method that will create instance of TextBox class.

public static CreateTextBox(string value, Expression<Func<object>> bindedProperty)
{
    // T should be receive from HTML.Form method or class
    return new TextBox<T>(value);
}

Is it possible to creating some code that doing something like the above code?

Thanks,

© Stack Overflow or respective owner

Related posts about c#4.0

Related posts about ASP.NET