8000 GitHub - sps014/SourceGenExample
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sps014/SourceGenExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SourceGenExample

Metaprogramming in C#.
Generate Partial method code at compile time on the fly.

Sample shows how to generate code for scenario given below

new JSAsm().Create();
partial class JSAsm
{
	 [JSMethod]
	 public partial void Create();
}

Traversing Syntax Tree to generate compile time injectable code

   // using the context, get a list of syntax trees in the users compilation
   var syntaxTrees = context.Compilation.SyntaxTrees.Where(t => t.GetText().ToString().Contains("[JSMethod"));
   sourceBuilder.AppendLine(@"using System;");
   // add the filepath of each tree to the class we're building
   foreach (SyntaxTree tree in syntaxTrees)
   {
       var v=tree.GetRoot().DescendantNodes().OfType<ClassDeclarationSyntax>().ToList();
   }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0