mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-06 17:58:05 +02:00
Add method for getting type of var (#5070)
Co-authored-by: amylizzle <amylizzle@users.noreply.github.com>
This commit is contained in:
@@ -264,6 +264,26 @@ namespace Robust.Shared.Serialization.Manager
|
||||
return dataDefinition != null;
|
||||
}
|
||||
|
||||
public bool TryGetVariableType(Type type, string variableName, [NotNullWhen(true)] out Type? variableType)
|
||||
{
|
||||
if (!TryGetDefinition(type, out var definition))
|
||||
{
|
||||
variableType = null;
|
||||
return false;
|
||||
}
|
||||
var foundFieldDef = definition.BaseFieldDefinitions.FirstOrDefault(fieldDef => fieldDef?.BackingField.Name==variableName, null);
|
||||
if(foundFieldDef != null)
|
||||
{
|
||||
variableType = foundFieldDef.BackingField.FieldType;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
variableType = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Type ResolveConcreteType(Type baseType, string typeName)
|
||||
{
|
||||
var type = ReflectionManager.YamlTypeTagLookup(baseType, typeName);
|
||||
|
||||
Reference in New Issue
Block a user