-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
源代码生成类型的方法导出功能 #39
源代码生成类型的方法导出功能 #39
Conversation
ba85e8c
to
6aa457b
Compare
|
||
public static class ValueTupleInfoParser | ||
{ | ||
public static bool TryParse(ITypeSymbol type, CancellationToken token, out ValueTupleInfo valueTupleInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NotNullWhen(true)]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@walterlv 似乎除了安装你的库之外,我没有找到其他好方法加上这个特性
$@"//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// 此代码由工具生成。 | ||
// | ||
// 对此文件的更改可能会导致不正确的行为,并且如果 | ||
// 重新生成代码,这些更改将会丢失。 | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
#define GENERATED_CODE | ||
|
||
"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从今天开始,你可以使用 """ 来编写这种代码,对得齐多好
src/TelescopeSourceGenerator/Analyzers/Core/AssemblySymbolHelper.cs
Outdated
Show resolved
Hide resolved
src/TelescopeSourceGenerator/Analyzers/Core/AssemblySymbolHelper.cs
Outdated
Show resolved
Hide resolved
/// <param name="typeSymbol"></param> | ||
/// <param name="classDeclarationList">嵌套类的定义</param> | ||
/// <returns></returns> | ||
private static bool TryGetClassDeclarationList(INamedTypeSymbol typeSymbol, out List<string>? classDeclarationList) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[NotNullWhen(true)]
// ReSharper disable InconsistentNaming | ||
public static DiagnosticDescriptor Tes000_UnknownError => new DiagnosticDescriptor | ||
( | ||
nameof(Tes000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我看大家编译诊断号的命名都是全大写缩写词,但你用帕斯卡缩写?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
举例 CS8002 CA1803 IDE1036
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@walterlv 似乎这部分没有什么规范,看起来改起来也比较麻烦,就先保持这样吧
src/TelescopeSourceGenerator/Analyzers/EmbeddedResourceCode/TelescopeExportAttribute.cs
Outdated
Show resolved
Hide resolved
src/TelescopeSourceGenerator/Analyzers/Core/IncrementalValuesProviderHelper.cs
Outdated
Show resolved
Hide resolved
[assembly: dotnetCampus.Telescope.MarkExportAttribute(typeof(Base), typeof(FooAttribute))] | ||
``` | ||
|
||
标记之后将会自动生成 `dotnetCampus.Telescope.__AttributedTypesExport__` 类型,即可在代码里面直接使用,如以下代码 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
之前我们使用 __
下划线名字是因为代码不应该被用户接触。但你现在被用户接触了,需要改名吧……
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@walterlv 改名的话,不能无缝对接原来的。我想做的是一个平替
新的话感觉使用分部方法更加合适,这样可以减少多一个程序集的引用且不用反射,也没有开发过程中缺乏语义提示问题
在分部类里定义分部方法,分部方法标记
dotnetCampus.Telescope.TelescopeExportAttribute
特性,且返回值包括导出条件,如以下写法以上代码将导出当前项目标记了
F1Attribute
且继承Base
的所有类型。经过 Telescope 源代码生成器即可生成大概如下的代码高级用法:
可以在 TelescopeExportAttribute 加上 IncludeReference 属性用来导出所有引用程序集的满足条件的类型,如以下代码
Close #35