c# - Using Reflection to fill a GUI for rule creation -


To create business rules I want to create a GUI application (MVC ASP Web Application) which can be used for my business rules.

For this, I have many objects (request objects) that can be used to create these rules. Because these request items are also used in the recognition of these rules.

For example, I have a TripRequest object with a strip variable 'airline' and a variable 'value'.

I want in my GUI that when you choose 'TriperX' from a different drop-down menu from various request objects, this second dropdown menu is filled with all its areas (airline, price, etc.).

Then when you select one of these fields, then its type (string, int) is required to read so that the GUI is suitable for commercial rules (equal, equal, large, small, etc.) ).

My idea is to use reflection to read the names of all the fields and method from various objects to create such GUIs and use them to fill the GUI. Is it a good practice to use this reflection?

I have not reflected before, so I am thinking that there can be a better way of doing this. I do not want to do all of the hard work because the application needs to be expanded (new object objects, new fields are added in the object) to add more code without a GUI.

my question: What is a good practice reflection to use for this problem? If not, what would you recommend or see?

This is my first question on the Stackshowourflow, if I have done something wrong, please tell me that I can edit or change it.

Thanks for reading :).

You do not use YouTube and data (and Possibly using a suitable metadata to create code and UI from that metadata) or trying to statically analyze your code (possibly Roslin!) To generate the appropriate code, however, The reflection is likely to be very less painful. Possible downsides ...

  • If you want to expose in the UI, it can be hard to decide how best to do this.
  • If you do not have a clear set of 'UI-facing' objects with rules according to visibility, then you only have to spend time to ensure that you only have certain features or conventions Make a plan based-share what you want to show.
  • You can find only on the runtime (worst position, in deployment) that you fail to display some rarely-used type correctly.

    After saying all this, if your data types are usually only bags of properties, the reflection is very straightforward. Here's some toy code that shows you the most relevant tricks, including data binding. Note that it is conventional to use properties rather than bare fields while reflecting on objects. {program} {STAThread} static zero main string [] args) {var request = new TripRequest () {airline = "reflection airways"}; Var window = new window (); Var stackpayel = new stackpanel (); Window.Content = stackPanel; Agrech (different property in request. Gettip (). GetProperties ()) {Console.WriteLine ("property named {0} type {1}", property.Name, property.PropertyType); If (property.PropertyType == typef (string)) {var textbox = new text box (); Var binding = new binding (); Binding Source = request; Binding.path = new propertypath (property.Name); Binding operation .Setbinding (text box, text box. Texproperty, binding); StackPanel.Children.Add (text box); } // etc.), you should take care of other types of windows.ShowDialog (); Console.vitaline ("airline is now {0}", request. Airline); Console.WriteLine ("Finish"); }} Class TripRequest {public string airline {get; Set; } Public At Price {Received; Set; }}

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -