Tag Archives: reflection

Run user-entered code that modifies the program’s form in C#

The example Run user-entered code in C# shows how you can compile and execute code entered at run time. That example simply displays a message box and returns a DialogResult indicating which button the user pressed. This example shows how … Continue reading

Posted in algorithms, miscellany, programs, reflection | Tagged , , , , , , , , , , , , , , , , | Leave a comment

Graph equations entered by the user in C#

This example draws a graph of an equation entered by the user by combining techniques from the following two posts: Evaluate numeric expressions that are entered by the user in C# Graph an equation in C# This example uses techniques … Continue reading

Posted in algorithms, drawing, graphics, mathematics, reflection | Tagged , , , , , , , , , , , | 2 Comments

Evaluate numeric expressions that are entered by the user in C#

This example shows one way to evaluate mathematical expressions entered by the user at runtime. Enter a numeric expression involving x and y in the upper text box. Then enter values for x and y in the lower text boxes … Continue reading

Posted in algorithms, mathematics, miscellany, programs, reflection | Tagged , , , , , , , , , , , | 2 Comments

List languages that you can compile at runtime in C#

The example Run user-entered code in C# shows how to let the user enter C# code, compile at runtime, and execute the result, but how do you know what languages you can compile that way? You might guess C# and … Continue reading

Posted in algorithms, miscellany, programs, reflection | Tagged , , , , , , , , , , , , , , , , , | 1 Comment

Run user-entered code in C#

This example shows how to compile and run user-entered code at run time. The form includes the following using statements. using System.CodeDom.Compiler; using System.Reflection; The following code executes when you click the Run button. // Compile and execute the code. … Continue reading

Posted in algorithms, miscellany, programs, reflection | Tagged , , , , , , , , , , , , , , , , | 12 Comments

Get variable values by name in C#

The process for displaying variable values is somewhat convoluted, but it’s not too long. The example starts by using the following code to define some private and public fields. // Some form-level values. private string private_value1 = “This is private … Continue reading

Posted in arrays, reflection, variables | Tagged , , , , , , , , , , , , , , , | 1 Comment

List colors in WPF and C#

This example shows how to list colors and display color samples in a WPF ListBox. To build the list, the example demonstrates reflection, LINQ, and XAML data templates. The program uses the following XAML code to define the ListBox that … Continue reading

Posted in drawing, enums, graphics, LINQ, reflection, wpf, XAML | Tagged , , , , , , , , , , , , , , , , , , , , , , | Leave a comment

Initialize a ComboBox from an enumeration in C#

Often it’s useful to initialize a ComboBox from an enumeration so the user can pick one of the enumeration’s values. You could type the value into the ComboBox at design time, but then if the enumeration changes, you’ll have to … Continue reading

Posted in controls, user interface | Tagged , , , , , , , , , , , , | Leave a comment

Use the predefined system colors in C#

The static System.Drawing.SystemColors class defines properties that give the system colors. These include colors for such items as active objects, highlighted text, captions, and window frames. This example uses the following code to list the defined system colors. // List … Continue reading

Posted in drawing, graphics, reflection | Tagged , , , , , , , , , , | Leave a comment

Invoke public methods by using their names in C#

You can use reflection to invoke public methods by using their names. The following code shows how the example program does this. // Invoke the method. private void btnInvoke_Click(object sender, EventArgs e) { try { Type this_type = this.GetType(); MethodInfo … Continue reading

Posted in classes, reflection | Tagged , , , , , , , , , | Leave a comment