Closed dfgHiatus closed 1 year ago
One thing to note: As enum parsing is relatively expensive in general, this will update the "IsParsed" output only when the input string has been changed at least once. A simple workaround is to compare 2 enums
Just get @ProbablePrime opinion if possible if not then we will continue with how it is.
What... why are you looping?
using System;
public class Program
{
enum Season
{
Spring,
Summer,
Autumn,
Winter
}
public static void Main()
{
Season result;
var e = Enum.TryParse<Season>("Summer", out result);
if (e)
Console.WriteLine(result.ToString());
else
Console.WriteLine("Cheese");
}
}
What's the loop for?
In order to use Enum.TryParse
we needed to extend struct
. Read about this here
using System;
using FrooxEngine.LogiX;
namespace FrooxEngine
{
[Category(new string[] { "LogiX/Input" })]
[GenericTypes(GenericTypes.Group.CommonEnums)]
public class ParseEnum<E> : LogixOperator<E> where E Enum, IConvertible
{
public readonly Input<string> Canidate;
public readonly Input<bool> IgnoreCase;
public readonly Output<bool> IsParsed;
public override E Content
{
get
{
E testEnum;
IsParsed.Value = Enum.TryParse<E>(Canidate.EvaluateRaw(), IgnoreCase.EvaluateRaw(), out testEnum);
return testEnum; // Logically equivalent to default(E), or the first item in an enumeration
}
}
}
}
Works without the struct
On my end that isn't the case. I will defer to one of colleagues to confirm this works for them
It complains about struct on my end as well.
neos actual, doesnt complain, but either way it works, should be more performant too.
thanks for double checking
There is probably a more efficient way of doing this, but I figured I'd take a stab at it.
Related issue: https://github.com/Neos-Metaverse/NeosPublic/issues/3545