Skip to content

Commit

Permalink
Fix ResXNullRef type handling (#10)
Browse files Browse the repository at this point in the history
* Fix ResXNullRef type handling

* Clarify the exclusivity of cases in winforms type mapping

* Test vs editor compatibility for ResXNullRef node writes

Also fixed a misunderstanding in the round trip test

---------

Co-authored-by: Spencer Farley <[email protected]>
  • Loading branch information
AdrianKokot and farlee2121 authored Mar 5, 2024
1 parent 110c7e0 commit 279e3a4
Show file tree
Hide file tree
Showing 8 changed files with 465 additions and 272 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";
}
}
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

0 comments on commit 279e3a4

Please sign in to comment.