【问题标题】:Getting Assembly Version of a class that implements interface through interface method通过接口方法获取实现接口的类的Assembly Version
【发布时间】:2017-11-14 10:52:04
【问题描述】:

我的类都实现了一个接口。该接口存储了一些通用功能的函数。

其中一个功能是日志记录。在这个 Logging 函数中,我想获取实现接口的类的 AssemblyVersion。

我的问题是Assembly.GetExectuingAssembly() 将返回接口的 AssemblyVersion。

如何获取实现类的组装版本?

【问题讨论】:

  • this.GetType().Assembly.GetName().Version 怎么样?
  • 我想复杂的部分是,实现类与接口不在同一个命名空间中......它们是完全独立的项目
  • 我已经在现已删除的答案上问过一次,但为什么会有问题呢?你能澄清一下吗?
  • 好吧,我刚刚调试了你的代码,它似乎可以工作。非常感谢!

标签: c# version .net-assembly


【解决方案1】:

这应该可行:

this.GetType().Assembly.GetName().Version

【讨论】:

  • 嗯,肯定不是这个。可能是 varname.GetType() 其中 varname 存储接口引用。
  • @HansPassant 据我了解 OP,他有一个类似 public interface IFoo { string Version { get; } } 的接口,他想知道实现在派生类中的样子,所以它应该看起来像 public Foo : IFoo { public string Version { get { return this.GetType().Assembly.GetName().Version.ToString(); } } } - 所以是的,如果我理解正确,那将是this,但我误解的可能性很高。 :)
猜你喜欢
  • 1970-01-01
  • 2020-12-28
  • 1970-01-01
  • 1970-01-01
  • 2020-09-27
  • 2013-06-20
  • 2011-05-16
  • 1970-01-01
  • 2013-03-23
相关资源
最近更新 更多