Skip to content

Commit 2862372

Browse files
fix FriendlyName issue with values
1 parent 7da77a3 commit 2862372

File tree

9 files changed

+48
-19
lines changed

9 files changed

+48
-19
lines changed

Code/ValueSystem/BoolValue.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace SER.Code.ValueSystem;
1+
using JetBrains.Annotations;
2+
3+
namespace SER.Code.ValueSystem;
24

35
public class BoolValue(bool value) : LiteralValue<bool>(value)
46
{
@@ -14,5 +16,6 @@ public static implicit operator bool(BoolValue value)
1416

1517
public override string StringRep => Value.ToString().ToLower();
1618

17-
public override string FriendlyName => "boolean value";
19+
[UsedImplicitly]
20+
public new static string FriendlyName => "boolean (true/false) value";
1821
}

Code/ValueSystem/CollectionValue.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using JetBrains.Annotations;
23
using SER.Code.Exceptions;
34
using SER.Code.Extensions;
45
using SER.Code.Helpers.ResultSystem;
@@ -166,7 +167,8 @@ public static CollectionValue RemoveAt(CollectionValue collection, int index)
166167
return new CollectionValue(lhs.CastedValues.Where(val => !rhs.CastedValues.Contains(val)));
167168
}
168169

169-
public override string FriendlyName => "collection value";
170+
[UsedImplicitly]
171+
public new static string FriendlyName => "collection value";
170172

171173
public override string ToString()
172174
{

Code/ValueSystem/DurationValue.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using StringBuilder = System.Text.StringBuilder;
1+
using JetBrains.Annotations;
2+
using StringBuilder = System.Text.StringBuilder;
23

34
namespace SER.Code.ValueSystem;
45

@@ -48,5 +49,6 @@ public override string StringRep
4849
}
4950
}
5051

51-
public override string FriendlyName => "duration value";
52+
[UsedImplicitly]
53+
public new static string FriendlyName => "duration value";
5254
}

Code/ValueSystem/LiteralValue.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Diagnostics.CodeAnalysis;
2+
using JetBrains.Annotations;
23
using SER.Code.Exceptions;
34

45
namespace SER.Code.ValueSystem;
@@ -37,6 +38,9 @@ public override string ToString()
3738
}
3839

3940
public override int HashCode => Value.GetHashCode();
41+
42+
[UsedImplicitly]
43+
public new static string FriendlyName => "literal value";
4044
}
4145

4246
public abstract class LiteralValue<T>: LiteralValue

Code/ValueSystem/NumberValue.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace SER.Code.ValueSystem;
1+
using JetBrains.Annotations;
2+
3+
namespace SER.Code.ValueSystem;
24

35
public class NumberValue(decimal value) : LiteralValue<decimal>(value)
46
{
@@ -13,5 +15,7 @@ public static implicit operator decimal(NumberValue value)
1315
}
1416

1517
public override string StringRep => Value.ToString();
16-
public override string FriendlyName => "number value";
18+
19+
[UsedImplicitly]
20+
public new static string FriendlyName => "number value";
1721
}

Code/ValueSystem/PlayerValue.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using LabApi.Features.Wrappers;
1+
using JetBrains.Annotations;
2+
using LabApi.Features.Wrappers;
23
using SER.Code.Exceptions;
34
using SER.Code.Extensions;
45

@@ -27,5 +28,6 @@ public PlayerValue(IEnumerable<Player> players)
2728
? throw new TosoksFuckedUpException(error)
2829
: val;
2930

30-
public override string FriendlyName => "player value";
31+
[UsedImplicitly]
32+
public new static string FriendlyName => "player value";
3133
}

Code/ValueSystem/ReferenceValue.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using SER.Code.Exceptions;
1+
using JetBrains.Annotations;
2+
using SER.Code.Exceptions;
23
using SER.Code.Extensions;
34

45
namespace SER.Code.ValueSystem;
@@ -16,7 +17,8 @@ public override bool EqualCondition(Value other)
1617

1718
public override int HashCode => Value.GetHashCode();
1819

19-
public override string FriendlyName => "reference value";
20+
[UsedImplicitly]
21+
public new static string FriendlyName => "reference value";
2022

2123
public override string ToString()
2224
{
@@ -28,5 +30,6 @@ public class ReferenceValue<T>(T? value) : ReferenceValue(value)
2830
{
2931
public new T Value => (T) base.Value;
3032

31-
public override string FriendlyName => $"reference value of type {typeof(T).GetAccurateName()}";
33+
[UsedImplicitly]
34+
public new static string FriendlyName => $"reference to {typeof(T).GetAccurateName()} object";
3235
}

Code/ValueSystem/TextValue.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.RegularExpressions;
2+
using JetBrains.Annotations;
23
using SER.Code.Exceptions;
34
using SER.Code.Extensions;
45
using SER.Code.Helpers;
@@ -32,7 +33,8 @@ public static implicit operator string(TextValue value)
3233

3334
public override string StringRep => Value;
3435

35-
public override string FriendlyName => "text value";
36+
[UsedImplicitly]
37+
public new static string FriendlyName => "text value";
3638

3739
public static string ParseValue(string text, Script script) => ExpressionRegex.Replace(text, match =>
3840
{
@@ -68,7 +70,8 @@ public static string ParseValue(string text, Script script) => ExpressionRegex.R
6870

6971
public class DynamicTextValue(string text, Script script) : TextValue(text, script)
7072
{
71-
public override string FriendlyName => "dynamic text value";
73+
[UsedImplicitly]
74+
public new static string FriendlyName => "dynamic text value";
7275
}
7376

7477
public class StaticTextValue(string text) : TextValue(text, null)
@@ -78,5 +81,6 @@ public static implicit operator StaticTextValue(string text)
7881
return new(text);
7982
}
8083

81-
public override string FriendlyName => "static text value";
84+
[UsedImplicitly]
85+
public new static string FriendlyName => "static text value";
8286
}

Code/ValueSystem/Value.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Reflection;
23
using LabApi.Features.Wrappers;
34
using SER.Code.Exceptions;
45
using SER.Code.Extensions;
@@ -14,11 +15,12 @@ public abstract class Value
1415

1516
public static Value Parse(object obj, Script? script)
1617
{
18+
// ReSharper disable once ConvertIfStatementToSwitchStatement
1719
if (obj is null) throw new AndrzejFuckedUpException();
1820
if (obj is Value v) return v;
1921

2022
return obj switch
21-
{
23+
{
2224
bool b => new BoolValue(b),
2325
byte n => new NumberValue(n),
2426
sbyte n => new NumberValue(n),
@@ -42,12 +44,15 @@ public static Value Parse(object obj, Script? script)
4244
};
4345
}
4446

47+
public string FriendlyName => GetFriendlyName(GetType());
48+
4549
public static string GetFriendlyName(Type t)
4650
{
47-
return ((Value)t.CreateInstance()).FriendlyName;
51+
return (string?)t
52+
.GetField("FriendlyName", BindingFlags.Public | BindingFlags.Static)?
53+
.GetValue(null)
54+
?? throw new AndrzejFuckedUpException($"FriendlyName is not defined in {t.AccurateName}");
4855
}
49-
50-
public abstract string FriendlyName { get; }
5156

5257
public override string ToString()
5358
{

0 commit comments

Comments
 (0)