All Projects → kekyo → Microsoft.codeanalysis.activepatterns

kekyo / Microsoft.codeanalysis.activepatterns

Licence: other
F# Active pattern library for Roslyn Compiler Platform (C#, VB)

Programming Languages

csharp
926 projects
fsharp
127 projects

Labels

Projects that are alternatives of or similar to Microsoft.codeanalysis.activepatterns

ThunderboltIoc
One of the very first IoC frameworks for .Net that has no reflection. An IoC that casts its services before thunder casts its bolts.
Stars: ✭ 40 (+48.15%)
Mutual labels:  roslyn
Awesome Roslyn
Curated list of awesome Roslyn books, tutorials, open-source projects, analyzers, code fixes, refactorings, and source generators
Stars: ✭ 395 (+1362.96%)
Mutual labels:  roslyn
Granular
WPF for JavaScript
Stars: ✭ 569 (+2007.41%)
Mutual labels:  roslyn
Codist
A visual studio extension which enhances syntax highlighting, quick info (tooltip), navigation bar, scrollbar, display quality and brings smart tool bar to code editor.
Stars: ✭ 134 (+396.3%)
Mutual labels:  roslyn
Roslyn Sdk
Roslyn-SDK templates and Syntax Visualizer
Stars: ✭ 255 (+844.44%)
Mutual labels:  roslyn
Sonar Dotnet
Code analyzer for C# and VB.NET projects https://redirect.sonarsource.com/plugins/vbnet.html
Stars: ✭ 466 (+1625.93%)
Mutual labels:  roslyn
UnitTestBoilerplateGenerator
An extension for Visual Studio that generates a unit test boilerplate from a given class, setting up mocks for all dependencies. Supports NUnit, Visual Studio Test, XUnit and many mock frameworks.
Stars: ✭ 39 (+44.44%)
Mutual labels:  roslyn
Polygen
PolyGen is a code generator that produces database schema, ORM layer, REST API and a (coming soon — stay tuned!) single-page web UI for your business model.
Stars: ✭ 19 (-29.63%)
Mutual labels:  roslyn
Buildalyzer
A utility to perform design-time builds of .NET projects without having to think too hard about it.
Stars: ✭ 354 (+1211.11%)
Mutual labels:  roslyn
Security Code Scan
Vulnerability Patterns Detector for C# and VB.NET
Stars: ✭ 550 (+1937.04%)
Mutual labels:  roslyn
Ref12
Sends F12 in Visual Studio to the new .Net Reference Source Browser
Stars: ✭ 76 (+181.48%)
Mutual labels:  roslyn
AOP With Roslyn
Roslyn AOP
Stars: ✭ 66 (+144.44%)
Mutual labels:  roslyn
Roslynclrheapallocationanalyzer
Roslyn based C# heap allocation diagnostic analyzer that can detect explicit and many implicit allocations like boxing, display classes a.k.a closures, implicit delegate creations, etc.
Stars: ✭ 492 (+1722.22%)
Mutual labels:  roslyn
replay-csharp
An editable C# REPL (Read Eval Print Loop) powered by Roslyn and .NET Core
Stars: ✭ 69 (+155.56%)
Mutual labels:  roslyn
Natasha
基于 Roslyn 的 C# 动态程序集构建库,该库允许开发者在运行时使用 C# 代码构建域 / 程序集 / 类 / 结构体 / 枚举 / 接口 / 方法等,使得程序在运行的时候可以增加新的模块及功能。Natasha 集成了域管理/插件管理,可以实现域隔离,域卸载,热拔插等功能。 该库遵循完整的编译流程,提供完整的错误提示, 可自动添加引用,完善的数据结构构建模板让开发者只专注于程序集脚本的编写,兼容 stanadard2.0 / netcoreapp3.0+, 跨平台,统一、简便的链式 API。 且我们会尽快修复您的问题及回复您的 issue.
Stars: ✭ 705 (+2511.11%)
Mutual labels:  roslyn
DDDToolbox
A set of Roslyn refactorings supporting DDD design
Stars: ✭ 31 (+14.81%)
Mutual labels:  roslyn
Codeconverter
Convert code from C# to VB.NET and vice versa using Roslyn
Stars: ✭ 432 (+1500%)
Mutual labels:  roslyn
Rosetta
Toolset for migrating your codebase from C# to TypeScript
Stars: ✭ 23 (-14.81%)
Mutual labels:  roslyn
Mappinggenerator
🔄 "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
Stars: ✭ 831 (+2977.78%)
Mutual labels:  roslyn
Uno
Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
Stars: ✭ 6,029 (+22229.63%)
Mutual labels:  roslyn

F# Active pattern library for Roslyn Compiler Platform (C#, VB)

"Microsoft.CodeAnalysis.ActivePatterns" is a F#'s active pattern functions library for The .NET Compiler Platform ("Roslyn") compiler platform. This library auguments for Roslyn AST (Abstract syntax tree nodes) types by F# active pattern functions.

  • This library still under construction...

Status

Title Status
NuGet NuGet

Code example

This code fragment for Roslyn analysis target:

using System.Collections.Generic;

namespace SampleNamespace
{
    public sealed class SampleClass
    {
        public SampleClass()
        {
            this.Value = System.DateTime.Now.Tick;
        }

        public long Value
        {
            get;
            set;
        }
    }
}

This code fragment for Roslyn using C#:

using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;

/// Code fragments are how to analysis by Roslyn and C#.
/// (These are not better and rough codes, but maybe longer analysis codes by using C#...)
namespace csharp_sample
{
    static class Program
    {
        private static string ReadSampleCode()
        {
            using (var fs = Assembly.GetEntryAssembly().GetManifestResourceStream("csharp_standard_usage_sample.Sample.cs"))
            {
                var tr = new StreamReader(fs, Encoding.UTF8);
                return tr.ReadToEnd();
            }
        }

        private static string TraverseNameSyntax(NameSyntax name)
        {
            if (name is IdentifierNameSyntax idName)
            {
                return idName.Identifier.Text;
            }

            if (name is QualifiedNameSyntax qName)
            {
                return TraverseNameSyntax(qName.Left) + "." + TraverseNameSyntax(qName.Right);
            }

            return string.Empty;
        }

        static void Main(string[] args)
        {
            var sampleCode = ReadSampleCode();

            var tree = (CSharpSyntaxTree) CSharpSyntaxTree.ParseText(sampleCode);
            var root = (CompilationUnitSyntax)tree.GetRoot();

            // Too complex if we have to analyze roslyn AST using C#...

            if (root.Usings.Any(u =>
            {
                var name = TraverseNameSyntax(u.Name);
                return name == "System.Collections.Generic";
            }))
            {
                if (root.Members.Any(m =>
                {
                    if (m is NamespaceDeclarationSyntax nameDecl)
                    {
                        if (nameDecl.Name is IdentifierNameSyntax name)
                        {
                            if (name.Identifier.Text == "SampleNamespace")
                            {
                                if (nameDecl.Members.Any(m2 =>
                                {
                                    if (m2 is ClassDeclarationSyntax classDecl)
                                    {
                                        var name2 = classDecl.Identifier.Text;
                                        if (name2 == "SampleClass")
                                        {
                                            return true;
                                        }
                                    }
                                    return false;
                                }))
                                {
                                    // ...
                                }
                            }
                        }
                    }
                    return false;
                }))
                {
                    // ...
                }
            }
        }
    }
}

If you are using for F# and this library:

open System
open System.IO
open System.Reflection
open System.Text

open Microsoft.CodeAnalysis
open Microsoft.CodeAnalysis.CSharp

// This is a namespace for active pattern functions.
open Microsoft.CodeAnalysis.CSharp.Strict

[<EntryPoint>]
let main argv =
    let sampleCode =
        use fs = Assembly.GetEntryAssembly().GetManifestResourceStream "Sample.cs"
        let tr = new StreamReader(fs, Encoding.UTF8)
        tr.ReadToEnd()

    let tree = CSharpSyntaxTree.ParseText sampleCode
    let root = tree.GetRoot() :?> CSharpSyntaxNode
        
    // Roslyn C# AST can handle by F#'s pattern matching.
    // AST types deconstructs by this library's active pattern functions.
    // And syntax node pattern naming is shorter.

    match root with
    | CompilationUnit
       (_, [ UsingDirective(_, _, _, Identifier(["System";"Collections";"Generic"]), _)], _,
         [ NamespaceDeclaration(_,
            Identifier(["SampleNamespace"]), _, _, _,
            [ ClassDeclaration(decl,
                _, Text("SampleClass"), _, _, _, _,
                memberDecls,
                _, _)],
            _, _) ],
         _) ->
            memberDecls
            |> Seq.choose (function
              | PropertyDeclaration(_, typeSyntax, _, Text(id), _, _, _, _) ->
                 Some (typeSyntax, id)
              | _ -> None)
            |> Seq.iter (printf "%A")
            
    | _ -> ()
    0

Platform

  • .NET Standard 1.6/2.0, .NET Core 2.0 and .NET Framework 4.6
  • Roslyn 2 (based 2.8.2).

Additional resources

License

TODO:

  • Improvement auto generator for better output.
  • Add additional custom functions.

History

  • 0.8.20:
    • Fixed NamespaceDeclaration matcher.
  • 0.8.10:
    • Upgraded Roslyn to 3.6.0.
  • 0.8.1:
    • More shorter SyntaxNode related names (ex: CompilationUnitSyntax --> CompilationUnit).
    • Support strict and loose active patterns.
  • 0.7.1:
    • Support .NET Standard, .NET Core 2 and F# 4.5 (4.5.2), based Roslyn 2.8.2.
  • 0.5.1:
    • Initial packaged release.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].