C#: Quickly Propagating Properties of an Object to the Parent Class

To quickly implement the propagation of all of the methods from an object owned by a class (called “theObj” below), to the owner, you can use the C# Interactive Window. Right-click your C# project, and choose “Initialize Interactive with Project”. Then, create an instance of your object, and extract the methods in the interactive window using the code below. Copy and paste the methods into your class’s code, and then manually edit any problematic results (i.e. generics won’t appear properly).

You can repeat this process for properties and events, simply changing the code to suit your needs.

theObj = new TheObjectTypeIWantToExpose();
var props = theObj.GetType().GetMethods(System.Reflection.BindingFlags.DeclaredOnly | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

foreach (var prop in props) {
    if (prop.Name.StartsWith("get_") || prop.Name.StartsWith("set_") ||
        prop.Name.StartsWith("add_") || prop.Name.StartsWith("remove_")) continue;

    var parameters = prop.GetParameters();
    List<string> paramlist = new List<string>();
    List<string> paramnames = new List<string>();
    foreach(var param in parameters)
        string curParam = param.ParameterType.FullName + " " + param.Name;

    string allParams = string.Join(",", paramlist);
    string allNames = string.Join(",", paramnames);

    Console.WriteLine($"{prop.ReturnType.FullName} {prop.Name}({allParams}) => TheChildObject.{prop.Name}({allNames});");

Fix for applications that do not support high DPI

I recently got a Microsoft Surface Pro, which has a high DPI display.  Many apps do not display properly, because they are not DPI-aware.  Here’s how to fix that in Windows 10/Windows Server 2016:

  1. If the program(s) you need to fix are in the Program Files folder(s), you’ll need Administrator rights.
  2. In your registry, tell Windows to prefer external program manifests over embedded ones:
    1. In RegEdit, go to the key:
    2. Add a new DWORD 32-bit value:
      and set it to 1.
  3. Create a text file in the same folder as the program with the exact same name as your the program including the .exe extension, and add a second extension, .manifest.  So, if your program is called Program.exe, you’ll create a new text file called Program.exe.manifest.
  4. Edit the text file, and add the following code to it:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
          version="" processorArchitecture="*"
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
        <ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</ms_windowsSettings:dpiAware>

Note that if you right-click and select Properties in Windows 10, there’s also a compatibility mode tab which has a setting that lets you override the application’s scaling properties.  However, this doesn’t seem to work on an RDP connection.  The manifest method above does work in RDP.