我知道.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 Framework 4.0移植到.NET Core,并且看到您可以做的有用的事情之一就是添加类似以下内容的代码,这些代码将有条件地编译部分代码:
#if NETCOREAPP1_0
do something
#elif NET40
do something else
#endif
Run Code Online (Sandbox Code Playgroud)
我的问题是用什么代替NET40上面的代码。我只能得到NETCOREAPP1_0和NETSTANDARD1_6被认可。我已经把对所有其他的事情NET40没有工作,其中包括net40,NET40,NET4_0,和其他几个人。是否有清单可以为如何引用提供指导?还是我需要在项目的其他部分采取其他步骤才能使它得到认可net40?