简体   繁体   English

如何确定程序集是从 f# 项目编译的?

[英]How determine that assembly was compiled from f# project?

What is the difference between c# and f# assemblies? c# 和 f# 程序集有什么区别? Some flag maybe?也许是一些旗帜? I want to determine it using reflection API only我只想使用反射 API 来确定它

There's no single value to check that would tell you what you need, but there's a good amount of circumstancial evidence that you could look at - IlSpy is your friend if you want to explore it.没有要检查的单一值可以告诉您需要什么,但是您可以查看大量的环境证据 - 如果您想探索它,IlSpy 是您的朋友。

I would suggest you check for presence of these two indicators, either of them being present would mean you're likely looking at an F# assembly unless someone is really dedicated to mess things up for you.我建议您检查这两个指标是否存在,它们中的任何一个存在都意味着您可能正在查看 F# 程序集,除非有人真的专门为您搞砸了。

  • FSharpInterfaceDataVersionAttribute on the assembly. FSharpInterfaceDataVersionAttribute上的FSharpInterfaceDataVersionAttribute This was my initial suggestion, however there are compiler flags that, when set, would prevent this attribute from being emitted: --standalone and --nointerfacedata .这是我最初的建议,但是有一些编译器标志在设置时会阻止发出此属性: --standalone--nointerfacedata I find it highly doubtful either of them would be commonly used in the field, but the fact remains there are openly available ways of opting out from the attribute being emitted right now.我发现非常怀疑它们中的任何一个是否会在该领域中常用,但事实仍然存在公开可用的方法来选择退出现在发出的属性。

     asm.GetCustomAttribute(typeof(FSharpInterfaceDataVersionAttribute))
  • Presence of StartupCode types. StartupCode类型的存在。 They're an artifact of how F# compiler compiles certain constructs, and it seems they're present even empty, so they should be highly reliable.它们是 F# 编译器如何编译某些构造的产物,而且它们似乎甚至是空的,因此它们应该是高度可靠的。

     asm.GetTypes().Where(fun x -> x.FullName.StartsWith("<StartupCode$"))

In particular looking for a reference to FSharp.Core is not a great idea, as it would be commonly referenced from C# projects as well if you're working with mixed solutions (and there's nothing stopping anyone from just getting it off nuget).特别是寻找对FSharp.Core的引用并不是一个好主意,因为如果您正在使用混合解决方案,它通常也会从 C# 项目中引用(并且没有什么可以阻止任何人从 nuget 中获取它)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM