Skip to main content

CodeAnalysis by Feast

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: CodeAnalysis

Auto generate extensions for Microsoft.CodeAnalysis

Author: Feast

NuGet: https://www.nuget.org/packages/Feast.CodeAnalysis.Literal/

You can find more details at https://github.com/feast107/CodeAnalysis

Source : https://github.com/feast107/CodeAnalysis

Original Readme

note

CodeAnalysis

自动生成提供给 SourceGenerator 的扩展

Requires

Supports

  • [Literal]

    Auto generate full qualified string literal for target class

    if you have a class like

    [Literal("Your.Program.Class")]
    public class Test
    {
    public IEnumerable<string> Name { get; set; }
    }

    Then it will generate a class like

    namespace Your.Program{
    public class Class{
    public static string Text = """
    public class Test
    {
    public global::System.Collection.Generic.IEnumerable<string> Name { get; set; }
    }
    """;
    }
    }
  • Feast.CompileTime

    class Assembly : System.Reflection.Assembly;
    class Module : System.Reflection.Module;
    class Type : System.Type;
    class MemberInfo : System.Reflection.MemberInfo;
    class MethodInfo : System.Reflection.MethodInfo;
    class EventInfo : System.Reflection.EventInfo;
    class FieldInfo : System.Reflection.FieldInfo;
    class PropertyInfo : System.Reflection.PropertyInfo;
    class ParameterInfo : System.Reflection.ParameterInfo;
    class ConstructorInfo : System.Reflection.ConstructorInfo;

Comment

我们需要 源代码生成器

因为我们需要生成更多的代码

我们需要 源代码生成器源代码生成器

因为 源代码生成器 现在还不够强大

我们需要 源代码生成器源代码生成器源代码生成器

因为 源代码生成器源代码生成器 现在还不能自举

由此可见

道生一,一生二,二生三,三生万物

总结

玩源生玩的。

About

note

Code to string literal. Unfortunately, it carries also some other CodeAnalysis generated files, which are not so useful.

How to use

Example ( source csproj, source files )

This is the CSharp Project that references CodeAnalysis

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Feast.CodeAnalysis.Literal" Version="0.1.0" />
</ItemGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

#nullable enable
using System;
namespace System
{
[global::System.AttributeUsage(global::System.AttributeTargets.Class | global::System.AttributeTargets.Struct | global::System.AttributeTargets.Interface | global::System.AttributeTargets.Enum | global::System.AttributeTargets.Delegate)]
public class LiteralAttribute : Attribute
{
public string? FieldName { get; set; }

public LiteralAttribute(string belongToFullyQualifiedClassName){ }
}
}

Usefull

Download Example (.NET C# )

Share CodeAnalysis

https://ignatandrei.github.io/RSCG_Examples/v2/docs/CodeAnalysis

In the same category (CodeToString) - 1 other generators

SourceGenerator.Helper.CopyCode