/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Compilers/Test/Core/Mocks/TestMetadataReferenceResolver.cs
59 строк
2 KB
Tomas Matousek
Move
23 окт 2020, 21:06
23 окт 2020, 21:06
d49cd2b
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. #nullable disable using System; using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Roslyn.Utilities; namespace Roslyn.Test.Utilities { internal class TestMetadataReferenceResolver : MetadataReferenceResolver { private readonly RelativePathResolver _pathResolver; private readonly Dictionary<string, PortableExecutableReference> _assemblyNames; private readonly Dictionary<string, PortableExecutableReference> _files; public TestMetadataReferenceResolver( RelativePathResolver pathResolver = null, Dictionary<string, PortableExecutableReference> assemblyNames = null, Dictionary<string, PortableExecutableReference> files = null) { _pathResolver = pathResolver; _assemblyNames = assemblyNames ?? new Dictionary<string, PortableExecutableReference>(); _files = files ?? new Dictionary<string, PortableExecutableReference>(); } public override ImmutableArray<PortableExecutableReference> ResolveReference(string reference, string baseFilePath, MetadataReferenceProperties properties) { Dictionary<string, PortableExecutableReference> map; if (PathUtilities.IsFilePath(reference)) { if (_pathResolver != null) { reference = _pathResolver.ResolvePath(reference, baseFilePath); if (reference == null) { return ImmutableArray<PortableExecutableReference>.Empty; } } map = _files; } else { map = _assemblyNames; } return map.TryGetValue(reference, out var result) ? ImmutableArray.Create(result) : ImmutableArray<PortableExecutableReference>.Empty; } public override bool Equals(object other) => true; public override int GetHashCode() => 1; } }