Coder Social home page Coder Social logo

Comments (5)

Sicos1977 avatar Sicos1977 commented on June 5, 2024 1

In the end I just fixed it like this.

I first pre process the script by putting it in a

using Using1;
using Using2;

// etc....

public Script 
{
}

and move any usings outside the class scope. After that it just works without any problems.

    internal static string GenerateObjectModalDiagram(string script, bool privateMembers, bool internalMembers)
    {
        var usings = new StringBuilder();
        var @class = new StringBuilder();

        @class.AppendLine("public class Script");
        @class.AppendLine("{");

        var lines = script.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
        foreach (var line in lines)
        {
            if (line.Trim().StartsWith("using", StringComparison.InvariantCultureIgnoreCase))
                usings.AppendLine(line);
            else
                @class.AppendLine(line);
        }

        @class.AppendLine("}");
        var modifiedScript = usings.ToString() + @class;

        var scriptOptions = ScriptOptions.Default
            .WithEmitDebugInformation(true)
            .AddReferences(MetadataReferences.Get)
            .WithAllowUnsafe(false)
            .WithCheckOverflow(true)
            .WithLanguageVersion(LanguageVersion.Latest);

        var compilation = CSharpScript
            .Create<string>(modifiedScript, scriptOptions, typeof(MainGlobals))
            .GetCompilation();

        var namedTypeSymbols = compilation.SyntaxTrees
            .SelectMany(tree => tree.GetRoot().DescendantNodesAndSelf().OfType<TypeDeclarationSyntax>())
            .Select(typeDeclaration => compilation.GetSemanticModel(typeDeclaration.SyntaxTree).GetDeclaredSymbol(typeDeclaration))
            .OfType<INamedTypeSymbol>().ToList();

        namedTypeSymbols = namedTypeSymbols.OrderBy(t => t.Name).ThenBy(t => t.GetFullNamespace()).ToList();

        using var stringWriter = new StringWriter();

        var generator = new HtmlOmdGenerator(stringWriter, namedTypeSymbols, privateMembers, internalMembers);

        foreach (var symbol in namedTypeSymbols)
        {
            switch (symbol.TypeKind)
            {
                case TypeKind.Enum:
                    generator.WriteEnum(symbol);
                    break;

                case TypeKind.Interface:
                    generator.WriteInterface(symbol);
                    break;

                default:
                {
                    if (symbol.TypeKind is TypeKind.Class or TypeKind.Struct)
                        generator.WriteClass(symbol);
                    else if (symbol.TypeKind == TypeKind.Delegate)
                        generator.WriteDelegate(symbol);
                    break;
                }
            }
        }

        generator.Complete();
        //File.WriteAllText("d:\\test.html", stringWriter.ToString());
        

from dotnetomdgenerator.

dotMorten avatar dotMorten commented on June 5, 2024

I don't see how that would work. I need classes to createdobject model diagrams. Without objects there's no OMD

from dotnetomdgenerator.

dotMorten avatar dotMorten commented on June 5, 2024

Oh and by default only public members are shown but all yours are private

from dotnetomdgenerator.

Sicos1977 avatar Sicos1977 commented on June 5, 2024

I already added some options to also show the private and internal members.

I was now removing all the code that does some comparing between new and old code because I never will have that.

from dotnetomdgenerator.

dotMorten avatar dotMorten commented on June 5, 2024

from dotnetomdgenerator.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.