forked from dotnet/roslyn
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add analyzer loading support for CoreCLR
Adds a new type, CoreClrAnalyzerAssemblyLoader, that is responsible for finding and loading analyzer assemblies on CoreCLR. This is used in the CscCore and VbcCore CoreCLR-targeting projects.
- Loading branch information
Showing
17 changed files
with
349 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Immutable; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Reflection.Metadata; | ||
using System.Reflection.PortableExecutable; | ||
|
||
namespace Microsoft.CodeAnalysis | ||
{ | ||
internal static class AnalyzerAssemblyLoadUtils | ||
{ | ||
public static AssemblyIdentity TryGetAssemblyIdentity(string filePath) | ||
{ | ||
try | ||
{ | ||
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) | ||
using (var peReader = new PEReader(stream)) | ||
{ | ||
var metadataReader = peReader.GetMetadataReader(); | ||
|
||
AssemblyDefinition assemblyDefinition = metadataReader.GetAssemblyDefinition(); | ||
|
||
string name = metadataReader.GetString(assemblyDefinition.Name); | ||
Version version = assemblyDefinition.Version; | ||
|
||
StringHandle cultureHandle = assemblyDefinition.Culture; | ||
string cultureName = (!cultureHandle.IsNil) ? metadataReader.GetString(cultureHandle) : null; | ||
AssemblyFlags flags = assemblyDefinition.Flags; | ||
|
||
bool hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0; | ||
BlobHandle publicKeyHandle = assemblyDefinition.PublicKey; | ||
ImmutableArray<byte> publicKeyOrToken = !publicKeyHandle.IsNil | ||
? metadataReader.GetBlobBytes(publicKeyHandle).AsImmutableOrNull() | ||
: default(ImmutableArray<byte>); | ||
return new AssemblyIdentity(name, version, cultureName, publicKeyOrToken, hasPublicKey); | ||
} | ||
} | ||
catch { } | ||
|
||
return null; | ||
} | ||
} | ||
} |
Oops, something went wrong.