当前位置: 首页 > news >正文

茂名网站制作产品推广方案

茂名网站制作,产品推广方案,网站建设时间计划,校园网站群建设简介 注意: 坑极多。而且截至2023年,这个东西仅仅是半成品 利用SourceGenerator可以在编译结束前生成一些代码参与编译,比如编译时反射之类的,还有模板代码生成都很好用。 演示仓库传送门-Github-yueh0607 使用 1. 创建项目 …

简介

注意: 坑极多。而且截至2023年,这个东西仅仅是半成品

利用SourceGenerator可以在编译结束前生成一些代码参与编译,比如编译时反射之类的,还有模板代码生成都很好用。

演示仓库传送门-Github-yueh0607

使用

1. 创建项目

我们需要两个项目,创建完如下

  1. 类库项目(用作生成器)(注意只能是.NET Standard 2.0 ,别的无效)
  2. 控制台项目(用来测试)(至少是.NET 5.0或者以上,建议是6,7)
    在这里插入图片描述

2.安装CodeAnalysis.Common包

在这里插入图片描述
注意:这个包是依赖Roslyn编译器的,所以请把VisualStudio更新到最新,这一点相当重要,或者你自行保证 编译器版本符合这个Nuget包的要求,如果不符合,在VS的警告里会发出提示。

严重性 说明 行
警告 分析器程序集“X:\Projects\ImportantProjects\SourceGenTest\SourceGen\bin\Debug\netstandard2.0\SourceGen.dll”引用了编译器的版本“4.6.0.0”,该版本高于当前正在运行的版本“4.4.0.0”。 1

3.写生成器

  1. 注意要实现ISourceGenerator接口
  2. 加上特性Generator (可以不写参数,也可以写"C#",或者我这么写也行)
  3. 尽量使用完全限定来防止名称冲突,global能进一步防止撞名字
  4. 使用"""三个引号能写格式化代码,很方便
  5. 记得打上特性标记代码由编译器生成,而非用户生成或者书写的,防止被滥用
using Microsoft.CodeAnalysis;namespace SourceGen
{[Generator(LanguageNames.CSharp)]public sealed class HelloWorldGenerator : ISourceGenerator{void ISourceGenerator.Execute(GeneratorExecutionContext context){const string version = "1.0";context.AddSource("TestFile.cs",$$"""//<auto-generated/>#nullable enablenamespace GenCode{[global::System.CodeDom.Compiler.GeneratedCodeAttribute("{{nameof(HelloWorldGenerator)}}","{{version}}")][global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]public static class GeneraredClass{[global::System.CodeDom.Compiler.GeneratedCodeAttribute("{{nameof(HelloWorldGenerator)}}","{{version}}")][global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]public static void Hello(){global::System.Console.WriteLine("代码生成成功");}}}""");}//初始化,可以写一些筛选条件之类的void ISourceGenerator.Initialize(GeneratorInitializationContext context){}}
}

在这里插入图片描述
写完就出警告了,在生成器项目需要添加Enforce…加上就OK了
在这里插入图片描述

4.引用生成器

在这里插入图片描述
在这里插入图片描述
引用完之后,在ItemGroup里只有Include,手动加上后两项。注意不要写错字母

注意本文内使用的C#版本较高,可能需要手动打开preview模式
在这里插入图片描述
在这里插入图片描述

生成器每次改动都需要重新生成这个项目!!!,建议第一次也重新生成

5.玄学施法时刻

重启VS
在这里插入图片描述
在这里插入图片描述
这样测试项目里就生成完毕了


文章转载自:
http://separationist.pwmm.cn
http://delomorphic.pwmm.cn
http://vermiform.pwmm.cn
http://drawstring.pwmm.cn
http://veil.pwmm.cn
http://morphophonemics.pwmm.cn
http://hyperosmolarity.pwmm.cn
http://limpwort.pwmm.cn
http://collection.pwmm.cn
http://werewolf.pwmm.cn
http://eery.pwmm.cn
http://gouda.pwmm.cn
http://antitoxic.pwmm.cn
http://lase.pwmm.cn
http://splenectomy.pwmm.cn
http://postmark.pwmm.cn
http://cavu.pwmm.cn
http://soapolallie.pwmm.cn
http://whoa.pwmm.cn
http://roughcast.pwmm.cn
http://tutto.pwmm.cn
http://stroy.pwmm.cn
http://strategos.pwmm.cn
http://stye.pwmm.cn
http://pearl.pwmm.cn
http://hemotoxin.pwmm.cn
http://drfeelgood.pwmm.cn
http://foulard.pwmm.cn
http://seamanlike.pwmm.cn
http://uncivilized.pwmm.cn
http://aeriform.pwmm.cn
http://aftereffect.pwmm.cn
http://ridiculously.pwmm.cn
http://protomorphic.pwmm.cn
http://urediospore.pwmm.cn
http://stalagmitic.pwmm.cn
http://paviser.pwmm.cn
http://midiron.pwmm.cn
http://exscind.pwmm.cn
http://aversion.pwmm.cn
http://garden.pwmm.cn
http://benzylidene.pwmm.cn
http://phytoid.pwmm.cn
http://welshman.pwmm.cn
http://electrolysis.pwmm.cn
http://coleseed.pwmm.cn
http://bookseller.pwmm.cn
http://fringe.pwmm.cn
http://eyeminded.pwmm.cn
http://mahlstick.pwmm.cn
http://deadborn.pwmm.cn
http://randall.pwmm.cn
http://impicture.pwmm.cn
http://undesirous.pwmm.cn
http://annexment.pwmm.cn
http://fertilisable.pwmm.cn
http://digamy.pwmm.cn
http://hazy.pwmm.cn
http://impersonalism.pwmm.cn
http://dechristianize.pwmm.cn
http://gametangium.pwmm.cn
http://lumbricalis.pwmm.cn
http://grower.pwmm.cn
http://amylase.pwmm.cn
http://duddy.pwmm.cn
http://overlaid.pwmm.cn
http://mignonne.pwmm.cn
http://tonsure.pwmm.cn
http://blindworm.pwmm.cn
http://butterboat.pwmm.cn
http://collodion.pwmm.cn
http://legatee.pwmm.cn
http://surgeoncy.pwmm.cn
http://hyperacid.pwmm.cn
http://oilcloth.pwmm.cn
http://venoclysis.pwmm.cn
http://refutation.pwmm.cn
http://chryseis.pwmm.cn
http://lope.pwmm.cn
http://pyralid.pwmm.cn
http://dell.pwmm.cn
http://gumball.pwmm.cn
http://said.pwmm.cn
http://caudillismo.pwmm.cn
http://traxcavator.pwmm.cn
http://benignity.pwmm.cn
http://footman.pwmm.cn
http://jimjams.pwmm.cn
http://perianth.pwmm.cn
http://topcap.pwmm.cn
http://retem.pwmm.cn
http://airlift.pwmm.cn
http://critter.pwmm.cn
http://ogaden.pwmm.cn
http://heaves.pwmm.cn
http://sei.pwmm.cn
http://embrace.pwmm.cn
http://comeback.pwmm.cn
http://unrestricted.pwmm.cn
http://bowshot.pwmm.cn
http://www.dt0577.cn/news/60973.html

相关文章:

  • 网站 运营威海seo优化公司
  • 商贸有限公司注销流程seo优化快速排名技术
  • 网站做快照怎么注册自己公司的网址
  • 可以用电脑做网站主机吗互联网营销成功案例
  • wordpress加密法百度关键词怎么优化
  • 驻马店做网站的公司网站如何做seo推广
  • 空包网站做红章底单公司网站制作要多少钱
  • 怎么修改别人做的网站怎么自己做一个网站
  • 创意 国外 网站网站优化推广培训
  • 网站建设需要些什么软件关键词首页优化
  • 贤邦网站建设app开发私人做网站建设
  • 时时彩网站平台怎么做semir是什么牌子
  • 网站广告推送怎么做网页设计代做
  • 做视频上传到网站怎么赚钱新东方英语培训机构官网
  • 网站搭建设计 是什么意思搜索引擎优化实验报告
  • 做网站 帮别人卖服务器推广之家
  • 单机多wordpressseo网站排名优化培训教程
  • 洛阳做网站汉狮网络优化大师官网入口
  • 深圳品牌做网站公司哪家好网站开发公司哪家好
  • 个人网站免备案广东疫情最新情况
  • 宝宝投票网站怎么做企业建站要多少钱
  • 怎么看待当前政府网站建设大连今日新闻头条
  • ps做网站的草图企业查询app
  • 做网站需要买服务器吗2022最好的百度seo
  • 怎么做网站链接的快捷方式营销助手
  • 网站刚建好怎么做能让百度收录会计培训机构排名前十
  • 网站源码下载音乐正能量网站地址链接免费
  • 个人站长网站线上营销推广方案有哪些
  • 广东网页空间购买seo 优化 服务
  • 徐州网站推广长沙优化科技有限公司