使用TypeBuilder/propertyBuilder定义无效的参考类型属性

发布于 2025-02-05 14:06:40 字数 292 浏览 1 评论 0原文

我正在使用TypeBuilder和PropertyBuilder在运行时创建类型(.NET 6)。

我需要指定我的属性具有无效的参考类型: 公共myReferenceType? myproperty {get;放; }

我发现编译器正在使用自定义属性的“ system.runtime.compilerServices.pilerServices.nullableAttribute”在引擎盖下进行操作,但是看来此属性也是在编译时创建的,并且它不存在其他地方,我可以添加的地方。它可以到我新创建的属性。

有人知道我们该怎么做吗?

I'm using TypeBuilder and PropertyBuilder to create Types at runtime (.NET 6).

I need to specify that my property has a nullable reference type:
public MyReferenceType? MyProperty { get; set; }

I have found that the compiler is doing it under the hood with a custom attribute "System.Runtime.CompilerServices.NullableAttribute" but it seems that this attribute is also created at compile time and it does not exist somewhere else where I can just add it to my newly created property.

Does someone know how can we do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文