1

Background

After spending a lot of time researching, I have not found any way of assigning multiple objects to PropertyGrid (Extended WPF Toolkit). My next idea is to create my own aggregator class that takes in selected objects and exposes their common properties to the outside world. I'll then assign (an instance of) this class to PropertyGrid. Any changes made by the user in PropertyGrid will be passed on to the selected objects by the aggregator class.

Question

Is there anything in the Framework (especially Reflection) that could help me with this task? All objects in my domain inherit from a common ancestor and add new properties of their own (or override ancestor versions). Class hierarchy is multiple levels deep.

UPDATE

For anyone else stuck in the same situation as me, I was able to finally solve PropertyGrid problem. See my other post for the solution.

Community
  • 1
  • 1
dotNET
  • 33,414
  • 24
  • 162
  • 251
  • With what you want, you need to create the aggregator class ***dynamically*** . So it's hard to be done easily (we need to use `System.Reflection.Emit`). In fact it may be easier if we generate the class definition code and use `System.CodeDom.Compiler` and `Microsoft.CSharp`. I wonder why you want to do something like that? If you want to show all common properties in the `PropertyGrid`, I guess you can set its `SelectedObjects` (instead of just `SelectedObject`) to your array of objects. – Hopeless Oct 08 '15 at 09:27
  • Well, I've just realized you mean the `PropertyGrid` in extended toolkit, looks like it does not support multiple objects selection. – Hopeless Oct 08 '15 at 09:31
  • @Hopeless: Your ID frightens me more than your answer! – dotNET Oct 08 '15 at 09:42
  • I guess the solution to your problem will even make you more frighten than my ID. – Hopeless Oct 08 '15 at 09:52

1 Answers1

0

Hope I can interpret what you want correctly.

One of the idea is using T4ToolBox to generate pre-compile class by scripting (which is also C# code in a template file).

  • Define your objects that want to be aggregate into xml.
  • Then you can use reflection to loop through all public method/properties in the objects (based on the xml) to find out the set of common methods
  • Generate an interface and (if you want) the corresponding concrete classes
  • One manual work after this is change your original object by implementing the newly generated interface.
cscmh99
  • 2,701
  • 2
  • 15
  • 18