相关疑难解决方法(0)

如何获得AssemblyTitle?

我知道.NET Core的替代品Assembly.GetExecutingAssembly()typeof(MyType).GetTypeInfo().Assembly,但是替换的是什么

Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false)
Run Code Online (Sandbox Code Playgroud)

我已经尝试在组装之后附加代码的最后一位用于提到的第一个解决方案,如下所示:

typeof(VersionInfo).GetTypeInfo().Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute));
Run Code Online (Sandbox Code Playgroud)

但它给了我一个"不能隐式转换为object []的消息.

更新: 是的,正如下面的评论所示,我认为它与输出类型相关联.

这是代码片段,我只是想将其更改为与.Net Core兼容:

public class VersionInfo
{
  public static string AssemlyTitle
  {
    get
    {
      object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
      // More code follows
Run Code Online (Sandbox Code Playgroud)

我已经尝试将其更改为使用CustomAttributeExtensions.GetCustomAttributes(但我目前还不了解c#,知道如何实现与上面相同的代码.关于MemberInfo和Type之类的东西我还是混淆了.非常感谢任何帮助!

.net c# .net-core

13
推荐指数
4
解决办法
1万
查看次数

标签 统计

.net ×1

.net-core ×1

c# ×1