using System; namespace MoleMole { public static class DelegateUtils { public static void UpdateField(ref T field, T newValue, Action updateDelegate) { T arg = field; field = newValue; if (updateDelegate != null) { updateDelegate(arg, field); } } public static void UpdateField(ref T field, T newValue, T delta, Action updateDelegate) { T arg = field; field = newValue; if (updateDelegate != null) { updateDelegate(arg, field, delta); } } public static void UpdateField(ref SafeInt8 field, sbyte newValue, Action updateDelegate) { sbyte value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeInt8 field, sbyte newValue, sbyte delta, Action updateDelegate) { sbyte value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeUInt8 field, byte newValue, Action updateDelegate) { byte value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeUInt8 field, byte newValue, byte delta, Action updateDelegate) { byte value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeInt16 field, short newValue, Action updateDelegate) { short value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeInt16 field, short newValue, short delta, Action updateDelegate) { short value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeUInt16 field, ushort newValue, Action updateDelegate) { ushort value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeUInt16 field, ushort newValue, ushort delta, Action updateDelegate) { ushort value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeInt32 field, int newValue, Action updateDelegate) { int value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeInt32 field, int newValue, int delta, Action updateDelegate) { int value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeUInt32 field, uint newValue, Action updateDelegate) { uint value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeUInt32 field, uint newValue, uint delta, Action updateDelegate) { uint value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeInt64 field, long newValue, Action updateDelegate) { long value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeInt64 field, long newValue, long delta, Action updateDelegate) { long value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeUInt64 field, ulong newValue, Action updateDelegate) { ulong value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeUInt64 field, ulong newValue, ulong delta, Action updateDelegate) { ulong value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeFloat field, float newValue, Action updateDelegate) { float value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeFloat field, float newValue, float delta, Action updateDelegate) { float value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } public static void UpdateField(ref SafeDouble field, double newValue, Action updateDelegate) { double value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue); } } public static void UpdateField(ref SafeDouble field, double newValue, double delta, Action updateDelegate) { double value = field.Value; field.Value = newValue; if (updateDelegate != null) { updateDelegate(value, newValue, delta); } } } }