Fix .NET Standard compatibility:

- Replace double.DegreesToRadians/RadiansToDegrees with Math-based conversions
- Replace Random.Shared with thread-local Random for thread safety
This commit is contained in:
codex 2025-08-26 00:39:43 -05:00
commit 5f7b862d5e
3 changed files with 9 additions and 11 deletions

View file

@ -26,8 +26,8 @@
var input = _args[0].Value; var input = _args[0].Value;
decimal value = Convert.ToDecimal(input.Value); decimal value = Convert.ToDecimal(input.Value);
// Convert radians to degrees // Convert radians to degrees (compatible with .NET Standard)
return new FunctionValue(FunctionValueType.Numeric, double.RadiansToDegrees((double)value)); return new FunctionValue(FunctionValueType.Numeric, (double)value * (180.0 / Math.PI));
}); });
} }
} }

View file

@ -26,8 +26,8 @@
var input = _args[0].Value; var input = _args[0].Value;
decimal value = Convert.ToDecimal(input.Value); decimal value = Convert.ToDecimal(input.Value);
// Convert degrees to radians // Convert degrees to radians (compatible with .NET Standard)
return new FunctionValue(FunctionValueType.Numeric, double.DegreesToRadians((double)value)); return new FunctionValue(FunctionValueType.Numeric, (double)value * (Math.PI / 180.0));
}); });
} }
} }

View file

@ -8,13 +8,11 @@ namespace CSMic.StandardLibrary.Functions.Random
{ {
public abstract class RandomBase : FunctionBase public abstract class RandomBase : FunctionBase
{ {
protected static System.Random RandomNumberGenerator // Provide a thread-local random to approximate Random.Shared in .NET Standard
{ private static readonly System.Threading.ThreadLocal<System.Random> s_threadLocalRandom =
get new System.Threading.ThreadLocal<System.Random>(() => new System.Random());
{
return System.Random.Shared; protected static System.Random RandomNumberGenerator => s_threadLocalRandom.Value!;
}
}
protected static decimal NextDecimal() protected static decimal NextDecimal()
{ {