|
-
Jun 3rd, 2014, 01:44 AM
#1
Thread Starter
Frenzied Member
Any way to write a method that accepts generic parameter and assign value?
Hi!
I am working on refactoring an application that is written as a Model View Presenter (winforms).
I am stuck on a scenario where the view fires events to the presenter when certain properties are changed. For example, if the user is selecting data in a combobox, an "CountryValueSelectedChanged" event is fired as an Action<int id> where id is the value selected. Same for textboxes where the keyup-event fires an OnFirstNameChanged event which is an Action<string name>.
Would it be possible to write a single OnPropertyChanged<T> method, since both the view and the presenter are aware of T (which is the domain entity) Then I just need a way to inform this generic event two things
1) The new value
2) Which property that was changed.
How do I do this in a clever way? I have on the presenter a property of type T which is called "selectedEntity; In the event handler for OnPropertyChanged<T> I want to be able to do:
"selectedEntity.X = newValue.X;"
How can I define X?
/Henrik
-
Jun 6th, 2014, 09:40 AM
#2
Re: Any way to write a method that accepts generic parameter and assign value?
 Originally Posted by MrNorth
Hi!
I am working on refactoring an application that is written as a Model View Presenter (winforms).
I am stuck on a scenario where the view fires events to the presenter when certain properties are changed. For example, if the user is selecting data in a combobox, an "CountryValueSelectedChanged" event is fired as an Action<int id> where id is the value selected. Same for textboxes where the keyup-event fires an OnFirstNameChanged event which is an Action<string name>.
Would it be possible to write a single OnPropertyChanged<T> method, since both the view and the presenter are aware of T (which is the domain entity) Then I just need a way to inform this generic event two things
1) The new value
2) Which property that was changed.
How do I do this in a clever way? I have on the presenter a property of type T which is called "selectedEntity; In the event handler for OnPropertyChanged<T> I want to be able to do:
"selectedEntity.X = newValue.X;"
How can I define X?
/Henrik
Hmm yes if i am understanding what you want correctly then wouldn't Dependency Injection do the job?
You would need to do some reading up on DI as its not the easiest thing to explain and its quite a large subject but ......
Have a read of this - http://stackoverflow.com/questions/1...ency-injection
Read the accepted answer it's a pretty good explanation!
Please Mark your Thread "Resolved",  if the query is solved & Rate those who have helped you
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|