CodeAnalysis by Feast
NuGet / site data
Details
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
Original Readme
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
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)
- CSharp Project
- Program.cs
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>
This is the use of CodeAnalysis in Program.cs
Console.WriteLine(Namespace_Andrei.Class_Ignat.Text);
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- LiteralAttribute.g.cs
- Namespace_Andrei.Class_Ignat.g.cs
#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){ }
}
}
// <auto-generated/> By Feast.CodeAnalysis
#pragma warning disable
#nullable enable
namespace Namespace_Andrei
{
partial class Class_Ignat
{
internal static string Text = """
namespace DemoLit
{
internal class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
""".Replace("\"^\"\"", "\"\"\"");
}
}
Useful
Download Example (.NET C# )
Share CodeAnalysis
https://ignatandrei.github.io/RSCG_Examples/v2/docs/CodeAnalysis