Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ResXNullRef type handling #10

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion System.Resources.NetStandard/ResXDataNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ private void InitializeDataNode(string basePath)
}
}
}

if (nodeType != null && nodeType.Equals(typeof(ResXNullRef)))
{
value = new ResXNullRef();
}
}

/// <summary>
Expand Down Expand Up @@ -619,11 +624,16 @@ public string GetValueTypeName(AssemblyName[] names)
/// </summary>
public object GetValue(ITypeResolutionService typeResolver)
{
if (value is ResXNullRef)
{
return null;
}

if (value != null)
{
return value;
}

object result = null;
if (FileRefFullPath != null)
{
Expand Down Expand Up @@ -962,6 +972,13 @@ public Type GetType(string name, bool throwOnError, bool ignoreCase)
result = typeof(ResXFileRef);
return result;
}

// Replace the WinForms ResXNullRef with the copy in this library
if (name.StartsWith(ResXConstants.ResXNullRef_TypeNameAndAssembly, StringComparison.Ordinal))
{
result = typeof(ResXNullRef);
return result;
}

// Missed in cache, try to resolve the type from the reference assemblies.
if (name.IndexOf(',') != -1)
Expand Down
3 changes: 3 additions & 0 deletions System.Resources.NetStandard/ResxConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ internal class ResXConstants

public const string ResxFileRefTypeInfo = "System.Resources.ResXFileRef, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
public const string ResxFileRef_TypeNameAndAssembly = "System.Resources.ResXFileRef, System.Windows.Forms";

public const string ResxNullRefTypeInfo = "System.Resources.ResXNullRef, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
public const string ResXNullRef_TypeNameAndAssembly = "System.Resources.ResXNullRef, System.Windows.Forms";
}
}
15 changes: 6 additions & 9 deletions System.Resources.NetStandard/WinformsTypeMappers.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace System.Resources.NetStandard
namespace System.Resources.NetStandard
{
internal static class WinformsTypeMappers
{
Expand All @@ -12,13 +8,14 @@ public static Func<Type, string> InterceptWinformsTypes(Func<Type,string> typeNa
{
if (type.AssemblyQualifiedName == typeof(ResXFileRef).AssemblyQualifiedName)
{
return NetStandard.ResXConstants.ResxFileRefTypeInfo;
return ResXConstants.ResxFileRefTypeInfo;
}
else
else if (type.AssemblyQualifiedName == typeof(ResXNullRef).AssemblyQualifiedName)
{
if (typeNameConverter != null) return typeNameConverter(type);
else return null;
return ResXConstants.ResxNullRefTypeInfo;
}
else if (typeNameConverter != null) return typeNameConverter(type);
else return null;
};
}

Expand Down
265 changes: 142 additions & 123 deletions Tests/Example.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading