mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Changed Count/MinValue/MaxValue from properties to methods
This commit is contained in:
parent
d17da427bc
commit
439b34f7c2
2 changed files with 35 additions and 44 deletions
|
@ -5,65 +5,56 @@ namespace System
|
||||||
{
|
{
|
||||||
struct Enum
|
struct Enum
|
||||||
{
|
{
|
||||||
public static int Count
|
[Comptime(ConstEval=true)]
|
||||||
|
public static int GetCount()
|
||||||
{
|
{
|
||||||
[Comptime(ConstEval=true)]
|
int count = 0;
|
||||||
get
|
for (var field in Compiler.OrigCalleeType.GetFields())
|
||||||
{
|
{
|
||||||
int count = 0;
|
if (field.IsEnumCase)
|
||||||
for (var field in Compiler.OrigCalleeType.GetFields())
|
count++;
|
||||||
{
|
|
||||||
if (field.IsEnumCase)
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var MinValue
|
[Comptime(ConstEval=true)]
|
||||||
|
public static var GetMinValue()
|
||||||
{
|
{
|
||||||
[Comptime(ConstEval=true)]
|
Compiler.SetReturnType(Compiler.OrigCalleeType);
|
||||||
get
|
|
||||||
{
|
|
||||||
Compiler.SetReturnType(Compiler.OrigCalleeType);
|
|
||||||
|
|
||||||
int? minValue = null;
|
int? minValue = null;
|
||||||
for (var field in Compiler.OrigCalleeType.GetFields())
|
for (var field in Compiler.OrigCalleeType.GetFields())
|
||||||
|
{
|
||||||
|
if (field.IsEnumCase)
|
||||||
{
|
{
|
||||||
if (field.IsEnumCase)
|
if (minValue == null)
|
||||||
{
|
minValue = field.[Friend]mFieldData.mData;
|
||||||
if (minValue == null)
|
else
|
||||||
minValue = field.[Friend]mFieldData.mData;
|
minValue = Math.Min(minValue.Value, field.[Friend]mFieldData.mData);
|
||||||
else
|
|
||||||
minValue = Math.Min(minValue.Value, field.[Friend]mFieldData.mData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return minValue.ValueOrDefault;
|
|
||||||
}
|
}
|
||||||
|
return minValue.ValueOrDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static var MaxValue
|
[Comptime(ConstEval=true)]
|
||||||
|
public static var GetMaxValue()
|
||||||
{
|
{
|
||||||
[Comptime(ConstEval=true)]
|
Compiler.SetReturnType(Compiler.OrigCalleeType);
|
||||||
get
|
|
||||||
{
|
|
||||||
Compiler.SetReturnType(Compiler.OrigCalleeType);
|
|
||||||
|
|
||||||
int? maxValue = null;
|
int? maxValue = null;
|
||||||
for (var field in Compiler.OrigCalleeType.GetFields())
|
for (var field in Compiler.OrigCalleeType.GetFields())
|
||||||
|
{
|
||||||
|
if (field.IsEnumCase)
|
||||||
{
|
{
|
||||||
if (field.IsEnumCase)
|
if (maxValue == null)
|
||||||
{
|
maxValue = field.[Friend]mFieldData.mData;
|
||||||
if (maxValue == null)
|
else
|
||||||
maxValue = field.[Friend]mFieldData.mData;
|
maxValue = Math.Max(maxValue.Value, field.[Friend]mFieldData.mData);
|
||||||
else
|
|
||||||
maxValue = Math.Max(maxValue.Value, field.[Friend]mFieldData.mData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (maxValue == null)
|
|
||||||
return -1;
|
|
||||||
return maxValue.ValueOrDefault;
|
|
||||||
}
|
}
|
||||||
|
if (maxValue == null)
|
||||||
|
return -1;
|
||||||
|
return maxValue.ValueOrDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void EnumToString(Type type, String strBuffer, int64 iVal)
|
public static void EnumToString(Type type, String strBuffer, int64 iVal)
|
||||||
|
|
|
@ -138,9 +138,9 @@ namespace Tests
|
||||||
eg.Set(66);
|
eg.Set(66);
|
||||||
Test.Assert(eg == .B);
|
Test.Assert(eg == .B);
|
||||||
|
|
||||||
var ea = EnumA.MaxValue;
|
var ea = EnumA.GetMaxValue();
|
||||||
Test.Assert(ea == .B);
|
Test.Assert(ea == .B);
|
||||||
Test.Assert(EnumA.Count == 2);
|
Test.Assert(EnumA.GetCount() == 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue