-1

I don't want the namespace Microsoft.Win32 to be in clear text in the code, so I want to store the namespace as base64 encoded in a string that will be equal to a function that decodes it. Example:

byte[] data = Convert.FromBase64String("TWljcm9zb2Z0LldpbjMy");

string Decoded_Namespace = Encoding.UTF8.GetString(data); // equal to Microsoft.Win32

Then I want to access the RegistryKey class which the namespace Microsoft.Win32 will be required.

Decoded_Namespace.RegistryKey instead of Microsoft.Win32.RegistryKey

J0k3r
  • 1
  • 1

1 Answers1

0

You can use the Activator.CreateInstance to get an instance of the class you want, but keep in mind you lose a lot of functionality from the IDE

    public object GetObjectFromType(string Decoded_Namespace, string typeName) 
    {
        return Activator.CreateInstance(Type.GetType(Decoded_Namespace + "." +typeName));
        
    }

Also keep in mind this uses the empty constructor of the class (but you can read some more here:

J.Salas
  • 1,268
  • 1
  • 8
  • 15
  • This public object should be in a different class cs file right ? (Inside an internal class) – J0k3r Dec 27 '21 at 14:56
  • Yes, some accesible class, I dont know how you want to implement it or how's your project internally, so the exact place could be one or another, but a Helpers.cs comes to my mind – J.Salas Dec 27 '21 at 15:47