Build 0.20.7.0
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Barotrauma;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Xunit;
|
||||
|
||||
namespace TestProject;
|
||||
@@ -27,12 +29,56 @@ public class INetSerializableStructImplementationChecks
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var members = NetSerializableProperties.GetPropertiesAndFields(type);
|
||||
var concreteType = type;
|
||||
if (type.IsGenericType)
|
||||
{
|
||||
// Plug in some known good parameters to evaluate
|
||||
// a concrete instance of this generic type
|
||||
|
||||
var paramsConstraints = type.GetGenericArguments()
|
||||
.Select(p => p.GetGenericParameterConstraints())
|
||||
.ToImmutableArray();
|
||||
|
||||
var chosenArgs = new Type[paramsConstraints.Length];
|
||||
|
||||
for (int i = 0; i < paramsConstraints.Length; i++)
|
||||
{
|
||||
var constraints = paramsConstraints[i];
|
||||
bool refTypeConstraint = constraints.Any(c
|
||||
=> c.GenericParameterAttributes.HasFlag(GenericParameterAttributes.ReferenceTypeConstraint));
|
||||
bool valueTypeConstraint = constraints.Any(c
|
||||
=> c.GenericParameterAttributes.HasFlag(GenericParameterAttributes.NotNullableValueTypeConstraint));
|
||||
if (refTypeConstraint && valueTypeConstraint)
|
||||
{
|
||||
throw new Exception($"Type \"{type.Name}\" has invalid generic constraints");
|
||||
}
|
||||
|
||||
int rngMin = refTypeConstraint ? 3 : 0;
|
||||
int rngMax = valueTypeConstraint ? 3 : 6;
|
||||
|
||||
chosenArgs[i] = Rand.Range(rngMin, rngMax) switch
|
||||
{
|
||||
0 => typeof(Vector2),
|
||||
1 => typeof(Point),
|
||||
2 => typeof(int),
|
||||
|
||||
3 => typeof(string),
|
||||
4 => typeof(float[]),
|
||||
5 => typeof(int[]),
|
||||
|
||||
var invalid => throw new Exception($"Broken RNG ranges in test, got {invalid}")
|
||||
};
|
||||
}
|
||||
|
||||
concreteType = type.MakeGenericType(chosenArgs);
|
||||
}
|
||||
|
||||
var members = NetSerializableProperties.GetPropertiesAndFields(concreteType);
|
||||
foreach (var member in members)
|
||||
{
|
||||
void checkType(Type typeBeingChecked)
|
||||
{
|
||||
Assert.True(tryFindBehavior(typeBeingChecked, out _), $"{type}.{member.Name} of type {member.Type} is unsupported in {nameof(INetSerializableStruct)}");
|
||||
Assert.True(tryFindBehavior(typeBeingChecked, out _), $"{concreteType}.{member.Name} of type {member.Type} is unsupported in {nameof(INetSerializableStruct)}");
|
||||
Type? nestedType = null;
|
||||
if (typeBeingChecked.IsGenericType)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user