diff --git a/BizHawk.Common/BinaryQuickSerializer.cs b/BizHawk.Common/BinaryQuickSerializer.cs index 421461c328..16da8bc9d4 100644 --- a/BizHawk.Common/BinaryQuickSerializer.cs +++ b/BizHawk.Common/BinaryQuickSerializer.cs @@ -27,11 +27,6 @@ namespace BizHawk.Common return caller.Method; } - private static MethodInfo Method(Expression f) - { - return FromExpression(f.Body); - } - private static MethodInfo Method(Expression> f) { return FromExpression(f.Body); diff --git a/BizHawk.Common/BizHawk.Common.csproj b/BizHawk.Common/BizHawk.Common.csproj index 83ea8473cc..e791e6fda4 100644 --- a/BizHawk.Common/BizHawk.Common.csproj +++ b/BizHawk.Common/BizHawk.Common.csproj @@ -85,9 +85,7 @@ - - @@ -98,7 +96,6 @@ - diff --git a/BizHawk.Common/BizInvoke/BizInvokeUtilities.cs b/BizHawk.Common/BizInvoke/BizInvokeUtilities.cs index 55a3c9feab..7272d87606 100644 --- a/BizHawk.Common/BizInvoke/BizInvokeUtilities.cs +++ b/BizHawk.Common/BizInvoke/BizInvokeUtilities.cs @@ -1,10 +1,8 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.InteropServices; -using System.Text; namespace BizHawk.Common.BizInvoke { diff --git a/BizHawk.Common/BizInvoke/BizInvoker.cs b/BizHawk.Common/BizInvoke/BizInvoker.cs index 5f47b7ffa8..0369c0ded4 100644 --- a/BizHawk.Common/BizInvoke/BizInvoker.cs +++ b/BizHawk.Common/BizInvoke/BizInvoker.cs @@ -194,8 +194,7 @@ namespace BizHawk.Common.BizInvoke TypeBuilder type, MethodInfo baseMethod, CallingConvention nativeCall, string entryPointName, FieldInfo monitorField) { // create the delegate type - MethodBuilder delegateInvoke; - var delegateType = BizInvokeUtilities.CreateDelegateType(baseMethod, nativeCall, type, out delegateInvoke); + var delegateType = BizInvokeUtilities.CreateDelegateType(baseMethod, nativeCall, type, out var delegateInvoke); var paramInfos = baseMethod.GetParameters(); var paramTypes = paramInfos.Select(p => p.ParameterType).ToArray(); diff --git a/BizHawk.Common/BizInvoke/CallingConventionAdapter.cs b/BizHawk.Common/BizInvoke/CallingConventionAdapter.cs index 6dfb0766e4..df6ad89894 100644 --- a/BizHawk.Common/BizInvoke/CallingConventionAdapter.cs +++ b/BizHawk.Common/BizInvoke/CallingConventionAdapter.cs @@ -3,8 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using System.Threading.Tasks; namespace BizHawk.Common.BizInvoke { diff --git a/BizHawk.Common/BizInvoke/WaterboxUtils.cs b/BizHawk.Common/BizInvoke/WaterboxUtils.cs index 13f2ce5705..07cbd4d364 100644 --- a/BizHawk.Common/BizInvoke/WaterboxUtils.cs +++ b/BizHawk.Common/BizInvoke/WaterboxUtils.cs @@ -1,9 +1,6 @@ using System; -using System.Collections.Generic; using System.IO; -using System.Linq; using System.Security.Cryptography; -using System.Text; namespace BizHawk.Common.BizInvoke { @@ -25,18 +22,14 @@ namespace BizHawk.Common.BizInvoke public static byte[] Hash(byte[] data) { - using (var h = SHA1.Create()) - { - return h.ComputeHash(data); - } + using var h = SHA1.Create(); + return h.ComputeHash(data); } public static byte[] Hash(Stream s) { - using (var h = SHA1.Create()) - { - return h.ComputeHash(s); - } + using var h = SHA1.Create(); + return h.ComputeHash(s); } public static unsafe void ZeroMemory(IntPtr mem, long length) @@ -49,24 +42,19 @@ namespace BizHawk.Common.BizInvoke } } - public static long Timestamp() - { - return DateTime.UtcNow.Ticks; - } - /// /// system page size /// - public static int PageSize { get; private set; } + public static int PageSize { get; } /// /// bitshift corresponding to PageSize /// - public static int PageShift { get; private set; } + public static int PageShift { get; } /// /// bitmask corresponding to PageSize /// - public static ulong PageMask { get; private set; } + public static ulong PageMask { get; } static WaterboxUtils() { diff --git a/BizHawk.Common/Buffer.cs b/BizHawk.Common/Buffer.cs index 5209257da0..07453a2775 100644 --- a/BizHawk.Common/Buffer.cs +++ b/BizHawk.Common/Buffer.cs @@ -20,41 +20,24 @@ namespace BizHawk.Common return new CBuffer(amt, itemsize); } - public void Write08(uint addr, byte val) { this.Byteptr[addr] = val; } - public void Write16(uint addr, ushort val) { *(ushort*)(this.Byteptr + addr) = val; } - public void Write32(uint addr, uint val) { *(uint*)(this.Byteptr + addr) = val; } - public void Write64(uint addr, ulong val) { *(ulong*)(this.Byteptr + addr) = val; } - public byte Read08(uint addr) { return this.Byteptr[addr]; } - public ushort Read16(uint addr) { return *(ushort*)(this.Byteptr + addr); } - public uint Read32(uint addr) { return *(uint*)(this.Byteptr + addr); } - public ulong Read64(uint addr) { return *(ulong*)(this.Byteptr + addr); } - public void Write08(int addr, byte val) { this.Byteptr[addr] = val; } - public void Write16(int addr, ushort val) { *(ushort*)(this.Byteptr + addr) = val; } - public void Write32(int addr, uint val) { *(uint*)(this.Byteptr + addr) = val; } - public void Write64(int addr, ulong val) { *(ulong*)(this.Byteptr + addr) = val; } - public byte Read08(int addr) { return this.Byteptr[addr]; } - public ushort Read16(int addr) { return *(ushort*)(this.Byteptr + addr); } - public uint Read32(int addr) { return *(uint*)(this.Byteptr + addr); } - public ulong Read64(int addr) { return *(ulong*)(this.Byteptr + addr); } - public CBuffer(T[] arr, int itemsize) { - this.Itemsize = itemsize; - this.Len = arr.Length; - this.Arr = arr; - this.Hnd = GCHandle.Alloc(arr, GCHandleType.Pinned); - this.Ptr = this.Hnd.AddrOfPinnedObject().ToPointer(); - this.Byteptr = (byte*)this.Ptr; + Itemsize = itemsize; + Len = arr.Length; + Arr = arr; + Hnd = GCHandle.Alloc(arr, GCHandleType.Pinned); + Ptr = Hnd.AddrOfPinnedObject().ToPointer(); + Byteptr = (byte*)Ptr; } public CBuffer(int amt, int itemsize) { - this.Itemsize = itemsize; - this.Len = amt; - this.Arr = new T[amt]; - this.Hnd = GCHandle.Alloc(this.Arr, GCHandleType.Pinned); - this.Ptr = this.Hnd.AddrOfPinnedObject().ToPointer(); - this.Byteptr = (byte*)this.Ptr; - Util.Memset(this.Byteptr, 0, this.Len * itemsize); + Itemsize = itemsize; + Len = amt; + Arr = new T[amt]; + Hnd = GCHandle.Alloc(this.Arr, GCHandleType.Pinned); + Ptr = Hnd.AddrOfPinnedObject().ToPointer(); + Byteptr = (byte*)Ptr; + Util.Memset(Byteptr, 0, Len * itemsize); } public void Dispose() @@ -67,11 +50,11 @@ namespace BizHawk.Common { if (disposing) { - if (this.Arr != null) + if (Arr != null) { - this.Hnd.Free(); + Hnd.Free(); } - this.Arr = null; + Arr = null; } } diff --git a/BizHawk.Common/CustomCollections.cs b/BizHawk.Common/CustomCollections.cs index 2aeee81b32..67d8cfb023 100644 --- a/BizHawk.Common/CustomCollections.cs +++ b/BizHawk.Common/CustomCollections.cs @@ -44,12 +44,6 @@ namespace BizHawk.Common [Serializable] public class Bag : BagBase>, List> { } - /// - /// a Dictionary-of-lists with key K and values List<V> - /// - [Serializable] - public class SortedBag : BagBase>, List> { } - /// /// base class for Bag and SortedBag /// diff --git a/BizHawk.Common/DeepEquality.cs b/BizHawk.Common/DeepEquality.cs index 00cf2299a7..b45e464551 100644 --- a/BizHawk.Common/DeepEquality.cs +++ b/BizHawk.Common/DeepEquality.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using System.Reflection; namespace BizHawk.Common @@ -50,27 +49,6 @@ namespace BizHawk.Common } } - /// - /// test if two arrays are equal in contents; arrays should have same type - /// - private static bool ArrayEquals(T[] o1, T[] o2) - { - if (o1.Length != o2.Length) - { - return false; - } - - for (int i = 0; i < o1.Length; i++) - { - if (!DeepEquals(o1[i], o2[i])) - { - return false; - } - } - - return true; - } - static MethodInfo ArrayEqualsGeneric = typeof(DeepEquality).GetMethod("ArrayEquals", BindingFlags.NonPublic | BindingFlags.Static); /// @@ -101,7 +79,7 @@ namespace BizHawk.Common // this is actually pretty fast; it allows using fast ldelem and stelem opcodes on // arbitrary array types without emitting custom IL var method = ArrayEqualsGeneric.MakeGenericMethod(new Type[] { t1.GetElementType() }); - return (bool)method.Invoke(null, new object[] { o1, o2 }); + return (bool)method.Invoke(null, new[] { o1, o2 }); } if (t1.IsPrimitive) diff --git a/BizHawk.Common/DescribableEnumConverter.cs b/BizHawk.Common/DescribableEnumConverter.cs index 3547d04995..73dd8e4e85 100644 --- a/BizHawk.Common/DescribableEnumConverter.cs +++ b/BizHawk.Common/DescribableEnumConverter.cs @@ -3,10 +3,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Globalization; -using System.Linq; using System.Reflection; -using System.Text; -using System.Threading.Tasks; namespace BizHawk.Common { diff --git a/BizHawk.Common/Extensions/BufferExtensions.cs b/BizHawk.Common/Extensions/BufferExtensions.cs index 5cbdbf009b..55b7998bd1 100644 --- a/BizHawk.Common/Extensions/BufferExtensions.cs +++ b/BizHawk.Common/Extensions/BufferExtensions.cs @@ -93,11 +93,9 @@ namespace BizHawk.Common.BufferExtensions public static string HashMD5(this byte[] data, int offset, int len) { - using (var md5 = MD5.Create()) - { - md5.ComputeHash(data, offset, len); - return md5.Hash.BytesToHexString(); - } + using var md5 = MD5.Create(); + md5.ComputeHash(data, offset, len); + return md5.Hash.BytesToHexString(); } public static string HashMD5(this byte[] data) @@ -107,11 +105,9 @@ namespace BizHawk.Common.BufferExtensions public static string HashSHA1(this byte[] data, int offset, int len) { - using (var sha1 = SHA1.Create()) - { - sha1.ComputeHash(data, offset, len); - return sha1.Hash.BytesToHexString(); - } + using var sha1 = SHA1.Create(); + sha1.ComputeHash(data, offset, len); + return sha1.Hash.BytesToHexString(); } public static string HashSHA1(this byte[] data) diff --git a/BizHawk.Common/Extensions/CollectionExtensions.cs b/BizHawk.Common/Extensions/CollectionExtensions.cs index 7fb8fb3180..1ee48a4aa9 100644 --- a/BizHawk.Common/Extensions/CollectionExtensions.cs +++ b/BizHawk.Common/Extensions/CollectionExtensions.cs @@ -1,7 +1,5 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Linq; namespace BizHawk.Common.CollectionExtensions { @@ -95,25 +93,5 @@ namespace BizHawk.Common.CollectionExtensions throw new InvalidOperationException("Item not found"); } - - public static byte[] ToByteArray(this IEnumerable list) - { - var bits = new BitArray(list.ToArray()); - byte[] bytes = new byte[(bits.Length / 8) + (bits.Length % 8 == 0 ? 0 : 1)]; - bits.CopyTo(bytes, 0); - return bytes; - } - - /// - /// Converts any byte array into a bit array represented as a list of booleans - /// - public static IEnumerable ToBools(this byte[] bytes) - { - var bits = new BitArray(bytes); - var bools = new bool[bits.Length]; - bits.CopyTo(bools, 0); - - return bools; - } } } diff --git a/BizHawk.Common/Extensions/IOExtensions.cs b/BizHawk.Common/Extensions/IOExtensions.cs index ea05a546a0..d075dc01d4 100644 --- a/BizHawk.Common/Extensions/IOExtensions.cs +++ b/BizHawk.Common/Extensions/IOExtensions.cs @@ -116,39 +116,6 @@ namespace BizHawk.Common.IOExtensions } } - public static int[] ReadInt32s(this BinaryReader br, int num) - { - int[] ret = new int[num]; - for (int i = 0; i < num; i++) - { - ret[i] = br.ReadInt32(); - } - - return ret; - } - - public static short[] ReadInt16s(this BinaryReader br, int num) - { - short[] ret = new short[num]; - for (int i = 0; i < num; i++) - { - ret[i] = br.ReadInt16(); - } - - return ret; - } - - public static ushort[] ReadUInt16s(this BinaryReader br, int num) - { - ushort[] ret = new ushort[num]; - for (int i = 0; i < num; i++) - { - ret[i] = br.ReadUInt16(); - } - - return ret; - } - public static void WriteBit(this BinaryWriter bw, Bit bit) { bw.Write((bool)bit); diff --git a/BizHawk.Common/Extensions/ReflectionExtensions.cs b/BizHawk.Common/Extensions/ReflectionExtensions.cs index ec997a25c9..85bda2ec4a 100644 --- a/BizHawk.Common/Extensions/ReflectionExtensions.cs +++ b/BizHawk.Common/Extensions/ReflectionExtensions.cs @@ -3,8 +3,6 @@ using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Reflection; -using System.Reflection.Emit; -using System.Runtime.InteropServices; namespace BizHawk.Common.ReflectionExtensions { @@ -118,64 +116,6 @@ namespace BizHawk.Common.ReflectionExtensions return default(T); } - /// - /// Takes an object and determines if it has methodName as a public method - /// - /// Returns whether or not the object both contains the method name and the method is public - public static bool HasExposedMethod(this object obj, string methodName) - { - var method = obj.GetType().GetMethod(methodName); - - if (method != null) - { - return method.IsPublic; - } - - return false; - } - - /// - /// Takes an object and invokes the method - /// The method must exist and be public - /// - /// The return value of the method, as an object. - /// If the method returns void, the return value is null - /// If the method does not exist or is not public, it returns null - /// - public static object InvokeMethod(this object obj, string methodName, object[] args) - { - var method = obj.GetType().GetMethod(methodName); - if (method != null && method.IsPublic) - { - return method.Invoke(obj, args); - } - - return null; - } - - public static bool HasPublicProperty(this object obj, string propertyName) - { - var property = obj.GetType().GetProperty(propertyName); - - if (property != null) - { - return property.CanRead; - } - - return false; - } - - public static object GetPropertyValue(this object obj, string propertyName) - { - var property = obj.GetType().GetProperty(propertyName); - if (property != null && property.CanRead) - { - return property.GetValue(obj, null); - } - - return null; - } - /// /// Takes an enum Type and generates a list of strings from the description attributes /// @@ -193,62 +133,5 @@ namespace BizHawk.Common.ReflectionExtensions { return (T)o.GetType().GetCustomAttributes(typeof(T), false)[0]; } - - /// - /// where the fields begin relative to the address an object references points to - /// - public static IntPtr ManagedFieldStart => _managedfieldstart; - - [StructLayout(LayoutKind.Explicit)] - private class Junkus - { - [FieldOffset(0)] - public IntPtr s; - } - - static IntPtr _managedfieldstart = GetManagedOffset(typeof(Junkus).GetField("s")); - - /// - /// the address of a field relative to the address an object reference of that type points to. this function is very expensive to call. - /// - public static IntPtr GetManagedOffset(this FieldInfo field) - { - Type type = field.DeclaringType; - - var dyn = new System.Reflection.Emit.DynamicMethod( - "xxz0", typeof(IntPtr), new Type[] { typeof(object) }, typeof(ReflectionExtensions).Module, true); - var il = dyn.GetILGenerator(); - - var pin = il.DeclareLocal(type, true); - var baseaddr = il.DeclareLocal(typeof(IntPtr)); - - il.Emit(OpCodes.Ldarg_0); - il.Emit(OpCodes.Stloc, pin); // force cast object to type (invalid), and pin - - il.Emit(OpCodes.Ldloc, pin); // base address of reference (points to typeinfo) - il.Emit(OpCodes.Conv_I); // convert object ref to intptr (invalid) - il.Emit(OpCodes.Stloc, baseaddr); - - il.Emit(OpCodes.Ldloc, pin); - il.Emit(OpCodes.Ldflda, field); // address of desired field - il.Emit(OpCodes.Conv_I); // convert field& to intptr (invalid) - il.Emit(OpCodes.Ldloc, baseaddr); - il.Emit(OpCodes.Sub); - il.Emit(OpCodes.Ret); - - return (IntPtr)dyn.Invoke(null, new object[] { new object() }); - } - - public static bool ThrowsError(this MethodInfo info) - { - var il = info.GetMethodBody().GetILAsByteArray(); - return il[il.Length - 1] == 0x7A; - } - - public static bool IsEmpty(this MethodInfo info) - { - var il = info.GetMethodBody().GetILAsByteArray(); - return il.Length == 1 && il[0] == 0x2A; - } } } diff --git a/BizHawk.Common/Extensions/StringExtensions.cs b/BizHawk.Common/Extensions/StringExtensions.cs index aad03258be..701e1024c7 100644 --- a/BizHawk.Common/Extensions/StringExtensions.cs +++ b/BizHawk.Common/Extensions/StringExtensions.cs @@ -24,12 +24,6 @@ namespace BizHawk.Common.StringExtensions return str.Substring(0, index); } - public static bool IsValidRomExtentsion(this string str, params string[] romExtensions) - { - var strUpper = str.ToUpper(); - return romExtensions.Any(ext => strUpper.EndsWith(ext.ToUpper())); - } - public static bool In(this string str, params string[] options) { return options.Any(opt => opt.Equals(str, StringComparison.CurrentCultureIgnoreCase)); @@ -128,12 +122,7 @@ namespace BizHawk.Common.StringExtensions /// public static bool IsHex(this string str) { - if (string.IsNullOrWhiteSpace(str)) - { - return false; - } - - return str.All(IsHex); + return !string.IsNullOrWhiteSpace(str) && str.All(IsHex); } /// @@ -154,12 +143,7 @@ namespace BizHawk.Common.StringExtensions /// public static bool IsBinary(this string str) { - if (string.IsNullOrWhiteSpace(str)) - { - return false; - } - - return str.All(IsBinary); + return !string.IsNullOrWhiteSpace(str) && str.All(IsBinary); } /// diff --git a/BizHawk.Common/IPC/SharedMemoryBlock.cs b/BizHawk.Common/IPC/SharedMemoryBlock.cs deleted file mode 100644 index 72a591efa8..0000000000 --- a/BizHawk.Common/IPC/SharedMemoryBlock.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace BizHawk.Common -{ - public unsafe class SharedMemoryBlock : IDisposable - { - public string Name; - public string BlockName; - public int Size; - public byte* Ptr; - byte[] bytes; - GCHandle handle; - - public void Allocate() - { - bytes = new byte[Size]; - handle = GCHandle.Alloc(bytes, GCHandleType.Pinned); - Ptr = (byte*)handle.AddrOfPinnedObject(); - } - - public void Dispose() - { - handle.Free(); - bytes = null; - } - } -} \ No newline at end of file diff --git a/BizHawk.Common/InstanceDll.cs b/BizHawk.Common/InstanceDll.cs index 8a7b558e73..f2492d09ca 100644 --- a/BizHawk.Common/InstanceDll.cs +++ b/BizHawk.Common/InstanceDll.cs @@ -69,7 +69,7 @@ namespace BizHawk.Common return GetProcAddress(_hModule, procName); } - public IntPtr HModule { get { return _hModule; } } + public IntPtr HModule => _hModule; IntPtr IImportResolver.Resolve(string entryPoint) { diff --git a/BizHawk.Common/MruStack.cs b/BizHawk.Common/MruStack.cs deleted file mode 100644 index 9406ef54d0..0000000000 --- a/BizHawk.Common/MruStack.cs +++ /dev/null @@ -1,62 +0,0 @@ -namespace BizHawk.Common -{ - public class MruStack - { - private readonly T[] _store; - private int _count; - private int _head; - - public MruStack(int capacity) - { - _store = new T[capacity]; - Clear(); - } - - public int Count => _count; - - public void Clear() - { - _head = 0; - _count = 0; - for (int i = 0; i < _store.Length; i++) - { - _store[i] = default(T); - } - } - - public void Push(T value) - { - _store[_head] = value; - _head = (_head + 1) % _store.Length; - - if (_count < _store.Length) - { - _count++; - } - } - - public T Pop() - { - if (_count == 0) - { - return default(T); - } - - _head--; - if (_head < 0) - { - _head = _store.Length - 1; - } - - _count--; - T value = _store[_head]; - _store[_head] = default(T); - return value; - } - - public bool HasElements() - { - return _count > 0; - } - } -} \ No newline at end of file diff --git a/BizHawk.Common/MutableIntRange.cs b/BizHawk.Common/MutableIntRange.cs index 8309e6ffd0..c9c0a4c260 100644 --- a/BizHawk.Common/MutableIntRange.cs +++ b/BizHawk.Common/MutableIntRange.cs @@ -9,10 +9,7 @@ namespace BizHawk.Common public int Min { - get - { - return _min; - } + get => _min; set { if (_max < value) throw new ArgumentException(); @@ -22,10 +19,7 @@ namespace BizHawk.Common public int Max { - get - { - return _max; - } + get => _max; set { if (value < _min) throw new ArgumentException(); diff --git a/BizHawk.Common/QuickCollections.cs b/BizHawk.Common/QuickCollections.cs index 776c6b3b90..8f15e653e4 100644 --- a/BizHawk.Common/QuickCollections.cs +++ b/BizHawk.Common/QuickCollections.cs @@ -19,14 +19,11 @@ namespace BizHawk.Common public T this[int index] { - get { return buffer[index]; } - set { buffer[index] = value; } + get => buffer[index]; + set => buffer[index] = value; } - public int Count - { - get { return Position; } - } + public int Count => Position; public void Add(T item) { @@ -53,7 +50,7 @@ namespace BizHawk.Common buffer = new T[capacity]; } - public int Count { get { return size; } } + public int Count => size; public void Enqueue(T item) { @@ -130,10 +127,7 @@ namespace BizHawk.Common return dict.ContainsKey(key); } - public ICollection Keys - { - get { return dict.Keys; } - } + public ICollection Keys => dict.Keys; public bool Remove(TKey key) { @@ -145,15 +139,12 @@ namespace BizHawk.Common return dict.TryGetValue(key, out value); } - public ICollection Values - { - get { return dict.Values; } - } + public ICollection Values => dict.Values; public TValue this[TKey key] { - get { return dict[key]; } - set { throw new InvalidOperationException(); } + get => dict[key]; + set => throw new InvalidOperationException(); } public void Add(KeyValuePair item) @@ -176,15 +167,9 @@ namespace BizHawk.Common dict.CopyTo(array, arrayIndex); } - public int Count - { - get { return dict.Count; } - } + public int Count => dict.Count; - public bool IsReadOnly - { - get { return true; } - } + public bool IsReadOnly => true; public bool Remove(KeyValuePair item) { diff --git a/BizHawk.Common/Serializer.cs b/BizHawk.Common/Serializer.cs index ae0a3df4c0..2e94f0643b 100644 --- a/BizHawk.Common/Serializer.cs +++ b/BizHawk.Common/Serializer.cs @@ -14,40 +14,19 @@ namespace BizHawk.Common #region Public - public bool IsReader - { - get { return _isReader; } - } + public bool IsReader => _isReader; - public bool IsWriter - { - get { return !IsReader; } - } + public bool IsWriter => !IsReader; - public bool IsText - { - get { return _isText; } - } + public bool IsText => _isText; - public BinaryReader BinaryReader - { - get { return _br; } - } + public BinaryReader BinaryReader => _br; - public BinaryWriter BinaryWriter - { - get { return _bw; } - } + public BinaryWriter BinaryWriter => _bw; - public TextReader TextReader - { - get { return _tr; } - } + public TextReader TextReader => _tr; - public TextWriter TextWriter - { - get { return _tw; } - } + public TextWriter TextWriter => _tw; public Serializer(BinaryWriter bw) { @@ -118,7 +97,7 @@ namespace BizHawk.Common public void BeginSection(string name) { - this._sections.Push(name); + _sections.Push(name); if (IsText) { if (IsWriter) @@ -135,7 +114,7 @@ namespace BizHawk.Common public void EndSection() { - var name = this._sections.Pop(); + var name = _sections.Pop(); if (IsText) { if (IsWriter) diff --git a/BizHawk.Common/SwitcherStream.cs b/BizHawk.Common/SwitcherStream.cs index 0be955d7e4..8383bcf8ae 100644 --- a/BizHawk.Common/SwitcherStream.cs +++ b/BizHawk.Common/SwitcherStream.cs @@ -15,10 +15,6 @@ namespace BizHawk.Common // switchstream method? flush old stream? private Stream _currStream; - public SwitcherStream() - { - } - /// /// if this is enabled, seeks to Begin,0 will get ignored; anything else will be an exception /// @@ -34,11 +30,7 @@ namespace BizHawk.Common public override long Position { - get - { - return _currStream.Position; - } - + get => _currStream.Position; set { if (DenySeekHack) @@ -55,11 +47,6 @@ namespace BizHawk.Common } } - public void SetCurrStream(Stream str) - { - _currStream = str; - } - public override void Flush() { _currStream.Flush(); diff --git a/BizHawk.Common/UndoHistory.cs b/BizHawk.Common/UndoHistory.cs index a17e5d054f..66bedf1354 100644 --- a/BizHawk.Common/UndoHistory.cs +++ b/BizHawk.Common/UndoHistory.cs @@ -16,12 +16,6 @@ namespace BizHawk.Common Enabled = enabled; } - public UndoHistory(IEnumerable newState, bool enabled) - { - AddState(newState); - Enabled = enabled; - } - public bool Enabled { get; } public bool CanUndo => Enabled && _curPos > 1; diff --git a/BizHawk.Common/UnmanagedResourceHeap.cs b/BizHawk.Common/UnmanagedResourceHeap.cs deleted file mode 100644 index 14ed39ea73..0000000000 --- a/BizHawk.Common/UnmanagedResourceHeap.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; - -namespace BizHawk.Common -{ - public class UnmanagedResourceHeap : IDisposable - { - public IntPtr StringToHGlobalAnsi(string str) - { - var ret = Marshal.StringToHGlobalAnsi(str); - HGlobals.Add(ret); - return ret; - } - - public List HGlobals = new List(); - - public void Dispose() - { - foreach (var h in HGlobals) - { - Marshal.FreeHGlobal(h); - } - - HGlobals.Clear(); - } - } -} diff --git a/BizHawk.Common/Util.cs b/BizHawk.Common/Util.cs index 17c8a90722..bbc6debdd7 100644 --- a/BizHawk.Common/Util.cs +++ b/BizHawk.Common/Util.cs @@ -7,7 +7,7 @@ using System.Text; namespace BizHawk.Common { - public static unsafe partial class Util + public static unsafe class Util { public static void CopyStream(Stream src, Stream dest, long len) { @@ -89,29 +89,6 @@ namespace BizHawk.Common return TryWaitForFileToVanish(pathWant); } - public static bool IsPowerOfTwo(int x) - { - if (x == 0 || x == 1) - { - return true; - } - - return (x & (x - 1)) == 0; - } - - public static int SaveRamBytesUsed(byte[] saveRam) - { - for (var i = saveRam.Length - 1; i >= 0; i--) - { - if (saveRam[i] != 0) - { - return i + 1; - } - } - - return 0; - } - // Could be extension method public static byte[] HexStringToBytes(string str) { @@ -351,12 +328,6 @@ namespace BizHawk.Common return ret; } - public static int Memcmp(void* a, string b, int len) - { - fixed (byte* bp = Encoding.ASCII.GetBytes(b)) - return Memcmp(a, bp, len); - } - public static int Memcmp(void* a, void* b, int len) { var ba = (byte*)a; @@ -384,17 +355,6 @@ namespace BizHawk.Common } } - public static void Memset32(void* ptr, int val, int len) - { - System.Diagnostics.Debug.Assert(len % 4 == 0); - int dwords = len / 4; - int* dwptr = (int*)ptr; - for (int i = 0; i < dwords; i++) - { - dwptr[i] = val; - } - } - public static string FormatFileSize(long filesize) { decimal size = filesize; @@ -447,8 +407,7 @@ namespace BizHawk.Common foreach (var kvp in first) { - TValue secondValue; - if (!second.TryGetValue(kvp.Key, out secondValue)) + if (!second.TryGetValue(kvp.Key, out var secondValue)) { return false; } @@ -481,23 +440,6 @@ namespace BizHawk.Common } } - public static class BitConverterLE - { - public static void WriteBytes(ushort value, byte[] dst, int index) - { - dst[index ] = (byte)(value ); - dst[index + 1] = (byte)(value >> 8); - } - - public static void WriteBytes(uint value, byte[] dst, int index) - { - dst[index ] = (byte)(value ); - dst[index + 1] = (byte)(value >> 8); - dst[index + 2] = (byte)(value >> 16); - dst[index + 3] = (byte)(value >> 24); - } - } - public static class VLInteger { public static void WriteUnsigned(uint value, byte[] data, ref int index)