Skip to content

Commit

Permalink
Fix ResXNullRef type handling
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianKokot committed Mar 4, 2024
1 parent 110c7e0 commit affcd3c
Show file tree
Hide file tree
Showing 6 changed files with 352 additions and 258 deletions.
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";
}
}
20 changes: 11 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 @@ -13,12 +9,18 @@ public static Func<Type, string> InterceptWinformsTypes(Func<Type,string> typeNa
if (type.AssemblyQualifiedName == typeof(ResXFileRef).AssemblyQualifiedName)
{
return NetStandard.ResXConstants.ResxFileRefTypeInfo;
}
else
}

if (type.AssemblyQualifiedName == typeof(ResXNullRef).AssemblyQualifiedName)
{
if (typeNameConverter != null) return typeNameConverter(type);
else return null;
return NetStandard.ResXConstants.ResxNullRefTypeInfo;
}


if (typeNameConverter != null)
return typeNameConverter(type);

return null;
};
}

Expand Down
229 changes: 119 additions & 110 deletions Tests/Example.Designer.cs

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

Loading

0 comments on commit affcd3c

Please sign in to comment.