reformat code + level load events
This commit is contained in:
@@ -1,75 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Cabrito
|
||||
{
|
||||
[Flags]
|
||||
public enum ConsoleFlags
|
||||
{
|
||||
NoSerialize = 1, // Value does not persist
|
||||
[Flags]
|
||||
public enum ConsoleFlags
|
||||
{
|
||||
NoSerialize = 1, // Value does not persist
|
||||
|
||||
Alias = NoSerialize,
|
||||
}
|
||||
Alias = NoSerialize
|
||||
}
|
||||
|
||||
internal struct ConsoleVariable
|
||||
{
|
||||
public string name { get; private set; }
|
||||
public ConsoleFlags flags { get; private set; }
|
||||
internal struct ConsoleVariable
|
||||
{
|
||||
public string name { get; }
|
||||
public ConsoleFlags flags { get; }
|
||||
|
||||
private FieldInfo field;
|
||||
private MethodInfo getter;
|
||||
private MethodInfo setter;
|
||||
private readonly FieldInfo field;
|
||||
private readonly MethodInfo getter;
|
||||
private readonly MethodInfo setter;
|
||||
|
||||
public ConsoleVariable(string name, ConsoleFlags flags, FieldInfo field)
|
||||
{
|
||||
this.name = name;
|
||||
this.flags = flags;
|
||||
this.field = field;
|
||||
this.getter = null;
|
||||
this.setter = null;
|
||||
}
|
||||
public ConsoleVariable(string name, ConsoleFlags flags, FieldInfo field)
|
||||
{
|
||||
this.name = name;
|
||||
this.flags = flags;
|
||||
this.field = field;
|
||||
getter = null;
|
||||
setter = null;
|
||||
}
|
||||
|
||||
public ConsoleVariable(string name, ConsoleFlags flags, MethodInfo getter, MethodInfo setter)
|
||||
{
|
||||
this.name = name;
|
||||
this.flags = flags;
|
||||
this.field = null;
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
}
|
||||
public ConsoleVariable(string name, ConsoleFlags flags, MethodInfo getter, MethodInfo setter)
|
||||
{
|
||||
this.name = name;
|
||||
this.flags = flags;
|
||||
field = null;
|
||||
this.getter = getter;
|
||||
this.setter = setter;
|
||||
}
|
||||
|
||||
public string GetValueString()
|
||||
{
|
||||
var type = field != null ? field.FieldType : getter.ReturnType;
|
||||
if (type == typeof(string))
|
||||
{
|
||||
if (field != null)
|
||||
return (string) field.GetValue(null);
|
||||
else if (setter != null)
|
||||
return (string) getter.Invoke(null, null);
|
||||
}
|
||||
else
|
||||
throw new Exception("cvar is not type of string");
|
||||
public string GetValueString()
|
||||
{
|
||||
Type type = field != null ? field.FieldType : getter.ReturnType;
|
||||
if (type == typeof(string))
|
||||
{
|
||||
if (field != null)
|
||||
return (string)field.GetValue(null);
|
||||
if (setter != null)
|
||||
return (string)getter.Invoke(null, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("cvar is not type of string");
|
||||
}
|
||||
|
||||
throw new Exception("GetValueString no field or getter specified");
|
||||
}
|
||||
throw new Exception("GetValueString no field or getter specified");
|
||||
}
|
||||
|
||||
public void SetValue(string value)
|
||||
{
|
||||
var type = field != null ? field.FieldType : getter.ReturnType;
|
||||
if (type == typeof(string))
|
||||
{
|
||||
if (field != null)
|
||||
field.SetValue(null, value);
|
||||
else if (setter != null)
|
||||
setter.Invoke(null, new object[] {value});
|
||||
}
|
||||
else
|
||||
throw new Exception("Unsupported type for SetValue: " + type.Name);
|
||||
}
|
||||
}
|
||||
public void SetValue(string value)
|
||||
{
|
||||
Type type = field != null ? field.FieldType : getter.ReturnType;
|
||||
if (type == typeof(string))
|
||||
{
|
||||
if (field != null)
|
||||
field.SetValue(null, value);
|
||||
else if (setter != null)
|
||||
setter.Invoke(null, new object[] { value });
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Unsupported type for SetValue: " + type.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user