Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
lonitra committed May 6, 2024
1 parent f0166e3 commit df10a81
Showing 1 changed file with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ResXSerializationBinderTests
[Fact]
public void ResXSerializationBinder_BindToType_FullyQualifiedName()
{
CustomTypeResolutionService typeResolutionService = new();
TrackGetTypePathTypeResolutionService typeResolutionService = new();
ResXSerializationBinder binder = new(typeResolutionService);
binder.BindToType(typeof(Button).Assembly.FullName!, typeof(Button).FullName!).Should().Be(typeof(Button));
typeResolutionService.FullyQualifiedAssemblyNamePath.Should().BeTrue();
Expand All @@ -25,7 +25,7 @@ public void ResXSerializationBinder_BindToType_FullyQualifiedName()
[Fact]
public void ResXSerializationBinder_BindToType_FullName()
{
CustomTypeResolutionService typeResolutionService = new();
TrackGetTypePathTypeResolutionService typeResolutionService = new();
ResXSerializationBinder binder = new(typeResolutionService);
binder.BindToType(typeof(MyClass).Assembly.FullName!, typeof(MyClass).FullName!).Should().Be(typeof(MyClass));
typeResolutionService.FullNamePath.Should().BeTrue();
Expand All @@ -35,7 +35,7 @@ public void ResXSerializationBinder_BindToType_FullName()
[Fact]
public void ResXSerializationBinder_BindToType_FullyQualifiedNameNoVersion()
{
CustomTypeResolutionService typeResolutionService = new();
TrackGetTypePathTypeResolutionService typeResolutionService = new();
ResXSerializationBinder binder = new(typeResolutionService);
binder.BindToType(typeof(Form).Assembly.FullName!, typeof(Form).FullName!).Should().Be(typeof(Form));
typeResolutionService.FullyQualifiedAssemblyNameNoVersionPath.Should().BeTrue();
Expand All @@ -62,24 +62,11 @@ public void ResXSerializationBinder_BindToName_TypeNameConverter_NameChange()
typeName.Should().Be(typeName);
}

private class CustomTypeResolutionService : ITypeResolutionService
private class TrackGetTypePathTypeResolutionService : ITypeResolutionService
{
public bool FullNamePath { get; private set; }
public bool FullyQualifiedAssemblyNamePath { get; private set; }
public bool FullyQualifiedAssemblyNameNoVersionPath { get; private set; }
private readonly string _formNoVersionFullyQualifiedName;

public CustomTypeResolutionService()
{
TypeName parsed = TypeName.Parse($"{typeof(Form).FullName}, {typeof(Form).Assembly.FullName}");
AssemblyNameInfo? assemblyNameInfo = parsed.AssemblyName;
_formNoVersionFullyQualifiedName = $"{typeof(Form).FullName}, {new AssemblyNameInfo(
assemblyNameInfo!.Name,
version: null,
assemblyNameInfo.CultureName,
assemblyNameInfo.Flags,
assemblyNameInfo.PublicKeyOrToken).FullName}";
}

public Assembly? GetAssembly(AssemblyName name) => throw new NotImplementedException();
public Assembly? GetAssembly(AssemblyName name, bool throwOnError) => throw new NotImplementedException();
Expand All @@ -96,10 +83,21 @@ public CustomTypeResolutionService()
FullNamePath = true;
return typeof(MyClass);
}
else if (typeName == _formNoVersionFullyQualifiedName)
else
{
FullyQualifiedAssemblyNameNoVersionPath = true;
return typeof(Form);
TypeName parsed = TypeName.Parse($"{typeof(Form).FullName}, {typeof(Form).Assembly.FullName}");
AssemblyNameInfo? assemblyNameInfo = parsed.AssemblyName;
string formNoVersionFullyQualifiedName = $"{typeof(Form).FullName}, {new AssemblyNameInfo(
assemblyNameInfo!.Name,
version: null,
assemblyNameInfo.CultureName,
assemblyNameInfo.Flags,
assemblyNameInfo.PublicKeyOrToken).FullName}";
if (typeName == formNoVersionFullyQualifiedName)
{
FullyQualifiedAssemblyNameNoVersionPath = true;
return typeof(Form);
}
}

return null;
Expand Down

0 comments on commit df10a81

Please sign in to comment.