Here I have used Person, PersonContainer and PersonViewModel just for representation. In actual scenario, the object is complex which updates many of its properties on Addition/modification of items in the datagrid. So, saving the index won't serve the purpose as we need the actual values.
Can you elaborate more on the 'imports' mentioned on #4? Still, i believe we need to clone the actual object and work on it. Appreciate, if you can help me a little detailed code.
Q: what could be the best way to handle 'Ok' and 'Cancel' in a dialog? Is creating a cloned object right way?
There is no "right" way, there are only efficient, inefficient and non-compiling implementations. FWIW, I'm doing something similar; I clone the object and throw it in a PropertyEditor. Has a third button that says "reset" that simply clones the original again and uploads it anew in the PropertyEditor. Works well, doesn't have much overhead.
Q: How can we implement undo/redo here?
An undo/redo is usually limited to the form where one is editing. You'd need the Memento-pattern, saving the internal state of the object every time the user performs an action. Undoing the action is then as simple as fetching the internal state from that point.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
Like Eddy said, there is no right or wrong to do it, using observable collections, you could have 2 and a flag, if the record is dirty (meaning that was modify) then in the save event in your viewmodel you just save the record, if cancel was hit and it was dirty then restore from either the db. again (re-read the record) or copy it from the other collection. What I mean with the 'imports' is that the 'Message' needs a import on the viewmodel.
There are essentially two ways to do this. The first is what you've done: copy the object, have the dialog operate on that copy, and update the original if you press OK. The second is rather similar, but instead of having a copy of the base data object to operate on, you operate on a specific data object for the form (i.e. it has properties for the fields that are editable on this form only), and if you press OK you assign all the properties from that data object into the source.
In the second case the data object can actually be the form itself, particularly with WPF's data binding that allows you to have UI controls display numbers, enum choices etc simply. This is normally what I do.
Re undo/redo, you need to save a command when you change the original object, i.e. press OK. Do you need to be able to undo each thing individually? ... I would normally expect 'Edit Object' to end up as a single undo action which is easier (you just have a command which stores the properties that were changed and the previous value, or even the whole before and after states, of the source object). If you do need undo entries for every dialog interaction then you need to have a local command stack within the dialog, and when you save the object you can execute them all in order on the source object and push them onto the global undo stack against that object.
Hi I'd like to run a method of a class calling it using its name in string format. Is it possible using reflection??
Thanks a lot
staticvoid Main(string args)
Type r = typeof(MyClass);
// I want to run MyClass.a() to show the message// here my try...unsuccesful :(
Console.WriteLine("Have good time");
You answered a question which wasn't the one that was actually asked, in a way which is likely to confuse the questioner.
Reflection is rarely useful full stop in my work, apart from loading types in from assemblies for plugins (which conform to a static interface so I don't use reflection for method lookups at all). The only place where I can see method lookups being useful is if you're trying to implement a scripting language or similar, at which point I can definitely see it being a case of looking up a method by name inside a (statically) known class (e.g. typeof(SomeClass)).
Bear in mind that reflection is slow; you shouldn't use it unless you don't know what you want to run at compile time (e.g. you are running commands based on user input, or you do not have a compile time reference to the class or a relevant interface through which to bind statically).
I have a simple WCF service with one interface and one class. When I add a service reference to my console apps, my WCF service class is not getting the expected name. My WCF service class name is service1 but it is exposed to the client end as Service1Client.
Why is the word"Client" being added before my actual class name? Do I need to add anything in my web.config for the service or in the app.config for the console end?
really i just do not understand what u trying to say. where we add service then we have to give service reference name. i gave service reference name say myfirstservice but when i type myfirstservice and dot then my class name is not appearing like "Myservice" rather a class name appear called "Myserviceclient" why the word "client" is being added before my actual class name and expose to client end.
I would verify your WCF Service Project Name and/or your Namespaces. Also, in the rare case that you renamed the WCF Service Project, I've found it's wise to just start over (i.e. delete the project and create a brand new one with the name you want) vs. figuring out all the things you need to also rename behind the scenes.
I'm trying to build a program which will read and assign to variables the values from an XML file which goes like this (without the *):
<*n1> random number here <*/n1>
<*n2> random number here <*/n2>
I tried to use the XmlTextReader but I got an error when I passed the location of the file
("C:\\Documents and Settings\\myfile.xml") so I tried the XmlDocument and it's function SelectSingleNode("n1") but I got another error.
So what's the best way to get the values from this XML file? (I also want to show an error message if the XML file is not built as I mentioned (<*n1> <*/n1> <*n2> <*/n2>).