Skip to content

Commit

Permalink
SymbolAssemblyInfo.Location fix [return valid path only]
Browse files Browse the repository at this point in the history
  • Loading branch information
Sholtee committed Jan 12, 2021
1 parent 444bb7a commit 820b8c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
24 changes: 20 additions & 4 deletions SRC/Private/Reflection/SymbolAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* *
* Author: Denes Solti *
********************************************************************************/
using System.IO;
using System.Linq;

using Microsoft.CodeAnalysis;
Expand All @@ -29,10 +30,25 @@ public static IAssemblyInfo CreateFrom(IAssemblySymbol asm, Compilation compilat
return new SymbolAssemblyInfo(asm, compilation);
}

public string? Location => Compilation
.References
.First(reference => SymbolEqualityComparer.Default.Equals(UnderlyingSymbol, Compilation.GetAssemblyOrModuleSymbol(reference)))
.Display;
public string? Location
{
get
{
string? nameOrPath = Compilation
.References
.First(reference => SymbolEqualityComparer.Default.Equals(UnderlyingSymbol, Compilation.GetAssemblyOrModuleSymbol(reference)))
.Display;

//
// Ha a Compilation GeneratorExecutionContext-bol jon es nem teljes ujraforditas
// van akkor a MetadataReference.Display nem biztos h eleresi utvonal
//

return nameOrPath is not null && File.Exists(nameOrPath)
? nameOrPath
: null;
}
}

public bool IsDynamic => false; // forditas idoben nem lehet dinamikus ASM hivatkozva

Expand Down
10 changes: 10 additions & 0 deletions SRC/Private/Visibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ public static void Check(ITypeInfo type, string assemblyName)
var collector = new ReferenceCollector(includeRuntimeReferences: false);
collector.AddType(type);

//
// Korbedolgozas arra az esetre ha a "type" GeneratorExecutionContext-bol jon es nem
// teljes ujraforditas van
//

if (collector.References.Any(@ref => @ref.Location is null))
return;

//
// Mivel az "internal" es "protected" kulcsszavak nem leteznek IL szinten ezert reflexioval
// nem tudnank megallapitani h a tipus lathato e a kodunk szamara szoval a forditotol kerjuk
Expand All @@ -130,6 +138,8 @@ public static void Check(ITypeInfo type, string assemblyName)
throw new MemberAccessException(string.Format(Resources.Culture, Resources.TYPE_NOT_VISIBLE, type));
case Accessibility.Internal when !type.DeclaringAssembly.IsFriend(assemblyName):
throw new MemberAccessException(string.Format(Resources.Culture, Resources.IVT_REQUIRED, type, assemblyName));
case Accessibility.NotApplicable:
throw new InvalidOperationException();
}
}
}
Expand Down

0 comments on commit 820b8c3

Please sign in to comment.