Comments (5)
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.
I don't see how that would work. I need classes to createdobject model diagrams. Without objects there's no OMD
from dotnetomdgenerator.
Oh and by default only public members are shown but all yours are private
from dotnetomdgenerator.
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.
from dotnetomdgenerator.
Related Issues (16)
- Add support for delegate HOT 1
- Add support for generating diff-OMDs between two branches or folders HOT 1
- Add search/filtering to HTML OMD HOT 7
- Add grouping support to HTML OMD HOT 5
- Test out generating SVGs instead for HTML diagrams
- Add support for XML comments HOT 3
- Suggestion: Sort the properties and methods by name and the constructors by # of parameters HOT 1
- Suggestion: Use the new Tuple syntax with names
- public static fields aren't shown HOT 1
- Suggestion: Add support for nested classes HOT 1
- Add support for .csproj and .sln project/solutions
- Add support for comparing DLLs and WinMD files. HOT 1
- Add dotnet tool support the Generator HOT 2
- `private protected` members are not handled correctly
- Add Mermaid output for markdown support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dotnetomdgenerator.