Skip to content

Commit

Permalink
fix culture bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bodong1987 committed Jul 5, 2024
1 parent 148da11 commit ca64637
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using UnrealSharp.Utils.Extensions;
using System.Globalization;
using UnrealSharp.Utils.Extensions;
using UnrealSharpTool.Core.TypeInfo;

namespace UnrealSharpTool.Core.CodeGen.Processors;
Expand All @@ -25,7 +26,8 @@ public NumericPropertyProcessor(BindingContext context) : base(context)
/// <returns>System.String[].</returns>
public override string[] GetMatchedTypeClass()
{
return [
return
[
"Int8Property",
"ByteProperty",
"Int16Property",
Expand Down Expand Up @@ -63,6 +65,7 @@ public override string GetCSharpTypeName(PropertyDefinition property, ELocalUsag
_ => base.GetCSharpTypeName(property, usage)
};
}

/// <summary>
/// Gets the interop get value text.
/// </summary>
Expand Down Expand Up @@ -104,7 +107,8 @@ public override string GetInteropSetValueText(
// ReSharper disable once ConvertIfStatementToReturnStatement
if (property.IsByteEnum)
{
return $"InteropUtils.SetEnum<{property.GetCSharpTypeName(Context)}>({address}, {offset}, {property.Size}, {variable})";
return
$"InteropUtils.SetEnum<{property.GetCSharpTypeName(Context)}>({address}, {offset}, {property.Size}, {variable})";
}

return $"InteropUtils.SetNumeric({address}, {offset}, {variable})";
Expand All @@ -117,11 +121,12 @@ public override string GetInteropSetValueText(
/// <param name="value">The value.</param>
/// <param name="usage">The usage.</param>
/// <returns>System.Nullable&lt;System.String&gt;.</returns>
public override string? DecorateDefaultValueText(PropertyDefinition property, string value, ELocalUsageScenarioType usage)
public override string? DecorateDefaultValueText(PropertyDefinition property, string value,
ELocalUsageScenarioType usage)
{
if(usage.HasFlag(ELocalUsageScenarioType.Field))
if (usage.HasFlag(ELocalUsageScenarioType.Field))
{
if(value.All(x=>x is '0' or '.'))
if (value.All(x => x is '0' or '.'))
{
return null;
}
Expand All @@ -131,7 +136,7 @@ public override string GetInteropSetValueText(
{
case "IntProperty":
{
if(int.TryParse(value, out _))
if (int.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -140,7 +145,7 @@ public override string GetInteropSetValueText(
}
case "UInt32Property":
{
if(uint.TryParse(value, out _))
if (uint.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -149,7 +154,7 @@ public override string GetInteropSetValueText(
}
case "Int64Property":
{
if(long.TryParse(value, out _))
if (long.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -158,7 +163,7 @@ public override string GetInteropSetValueText(
}
case "UInt64Property":
{
if(ulong.TryParse(value, out _))
if (ulong.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -167,7 +172,7 @@ public override string GetInteropSetValueText(
}
case "Int8Property":
{
if(sbyte.TryParse(value, out _))
if (sbyte.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -176,7 +181,7 @@ public override string GetInteropSetValueText(
}
case "Int16Property":
{
if(short.TryParse(value, out _))
if (short.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -185,7 +190,7 @@ public override string GetInteropSetValueText(
}
case "UInt16Property":
{
if(ushort.TryParse(value, out _))
if (ushort.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture, out _))
{
return value.Trim();
}
Expand All @@ -194,7 +199,7 @@ public override string GetInteropSetValueText(
}
case "FloatProperty":
{
if (float.TryParse(value, out _))
if (float.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out _))
{
return $"{value}f";
}
Expand All @@ -203,7 +208,7 @@ public override string GetInteropSetValueText(
}
case "DoubleProperty":
{
if(double.TryParse(value, out _))
if (double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out _))
{
return $"{value}d";
}
Expand All @@ -212,7 +217,7 @@ public override string GetInteropSetValueText(
}
default:
{
if(property.IsByteEnum)
if (property.IsByteEnum)
{
return value == "(INVALID)" ? null : $"{property.ByteEnumName}.{value}";
}
Expand Down
3 changes: 2 additions & 1 deletion Tools/Programs/UnrealSharpTool.Core/TypeInfo/MetaData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnrealSharp.Utils.Extensions;
Expand Down Expand Up @@ -85,7 +86,7 @@ public bool TryGetMeta(string key, out bool value)
public bool TryGetMeta(string key, out int value)
{
value = 0;
return Metas.TryGetValue(key, out var temp) && int.TryParse(temp, out value);
return Metas.TryGetValue(key, out var temp) && int.TryParse(temp, NumberStyles.Integer, CultureInfo.InvariantCulture, out value);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnrealSharp.Utils.Misc;
using UnrealSharp.Utils.UnrealEngine;
using UnrealSharpTool.Core.ErrorReports;
using System.Globalization;

namespace UnrealSharpTool.Core.TypeInfo.MonoCecil;

Expand Down Expand Up @@ -75,7 +76,7 @@ public static void SetupBaseTypeDefinition(BaseTypeDefinition baseTypeDefinition

if (exportFlagsProperty.Argument.Value != null && exportFlagsProperty.Argument.Value.ToString().IsNotNullOrEmpty())
{
if (int.TryParse(exportFlagsProperty.Argument.Value.ToString(), out var v))
if (int.TryParse(exportFlagsProperty.Argument.Value.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var v))
{
baseTypeDefinition.ExportFlags = v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<Configurations>Debug;Release</Configurations>
<IsAotCompatible>True</IsAotCompatible>
<IsTrimmable>False</IsTrimmable>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<AssemblyVersion>1.2.1.0</AssemblyVersion>
<FileVersion>1.2.1.0</FileVersion>

</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
Expand Down
4 changes: 2 additions & 2 deletions Tools/Programs/UnrealSharpTool/UnrealSharpTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PublishAot>true</PublishAot>
<IsAotCompatible>True</IsAotCompatible>
<IsTrimmable>False</IsTrimmable>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<FileVersion>1.2.0.0</FileVersion>
<AssemblyVersion>1.2.1.0</AssemblyVersion>
<FileVersion>1.2.1.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'">
<OutputPath>../../Publish/UnrealSharpTool/DotNET</OutputPath>
Expand Down

0 comments on commit ca64637

Please sign in to comment.