'How to generate a xsd file from namespace directly in code using C#?

Consider having a simple POCO C# class:

namespace MyNamespace;

public class MyClass
{
    public int A { get; set; }
    public double B { get; set; }
}

I'm aware of the xsd file generation possibilities by the xsd.exe tool, but is it possible to generate a xsd file from the MyNamespace namespace within C# code directly?

Something like:

string xsdString = XsdGenerator.FromNamespace("MyNamespace");


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source