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;
        paramlist.Add(curParam);
        paramnames.Add(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:
      HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide
    2. Add a new DWORD 32-bit value:
      PreferExternalManifest
      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">
    
    <dependency>
      <dependentAssembly>
        <assemblyIdentity
          type="win32"
          name="Microsoft.Windows.Common-Controls"
          version="6.0.0.0" processorArchitecture="*"
          publicKeyToken="6595b64144ccf1df"
          language="*">
        </assemblyIdentity>
      </dependentAssembly>
    </dependency>
    
    <dependency>
      <dependentAssembly>
        <assemblyIdentity
          type="win32"
          name="Microsoft.VC90.CRT"
          version="9.0.21022.8"
          processorArchitecture="amd64"
          publicKeyToken="1fc8b3b9a1e18e3b">
        </assemblyIdentity>
      </dependentAssembly>
    </dependency>
    
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
        <requestedPrivileges>
          <requestedExecutionLevel
            level="asInvoker"
            uiAccess="false"/>
        </requestedPrivileges>
      </security>
    </trustInfo>
    
    <asmv3:application>
      <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>
      </asmv3:windowsSettings>
    </asmv3:application>
    
    </assembly>
    

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.

Source