Skip to content

nbarbettini/polyglot-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polygot-dotnet Build status

Polyglot is a small library that will attempt to determine the original source language of a compiled CLI (.NET) assembly.

Current Status

Polyglot supports these platforms:

  • .NET Framework 4.5.1 and higher
  • CoreCLR/DNX (or any dotnet5.1/netstandard1.0 platform)

Polyglot includes heuristics for code written in these languages:

  • C#
  • VB.NET (only on desktop .NET, currently!)
  • F#

Caveats caveats caveats

Polyglot will not always work, so don't rely on this for anything mission-critical. Incorrect results could occur if:

  • There isn't enough data to make an educated guess!
  • Language-specific libraries are reused (Microsoft.VisualBasic in a C# project, for instance)
  • Internal compiler semantics change (hello, Roslyn)
  • Someone deliberately wants to fool the analyzer
  • You think merging assemblies is a fun thing to do

Usage

// Analyze the current assembly.
var assembly = this.GetType().GetTypeInfo().Assembly;

// Analyze the calling assembly. Cool!
// (Only works on desktop .NET)
var assembly = Assembly.GetCallingAssembly();

// Analyze an assembly from disk.
var assembly = Assembly.LoadFrom(path);

// Analyze!
var analyzer = new AssemblyAnalyzer(assembly);

// analyzer.DetectedLanguage is the best guess,
// analyzer.AllResults shows all matching heuristics.

Background

This library is based on a StackOverflow answer I wrote that attempted to do the same thing. I was surprised that nothing else existed, so I took some hints from other questions and built a proof-of-concept.

It's solidly in the realm of "trickery that doesn't always work" (see caveats, above). But, works well enough for me to use for some rudimentary diagnostic reporting in the Stormpath.SDK library, which I maintain.