Remove EnumHelper file and some code cleanup

This commit is contained in:
adelikat 2014-07-03 18:02:22 +00:00
parent 55c9132037
commit e058e08c35
11 changed files with 39 additions and 60 deletions

View File

@ -1,23 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Reflection;
using BizHawk.Common.ReflectionExtensions;
namespace BizHawk.Common
{
public static class EnumHelper
{
public static IEnumerable<string> GetDescriptions<T>()
{
var vals = Enum.GetValues(typeof(T));
foreach (var v in vals)
{
yield return v.GetDescription();
}
}
}
}

View File

@ -64,13 +64,22 @@ namespace BizHawk.Common
//we didnt find it. return something corresponding to lower_bound semantics //we didnt find it. return something corresponding to lower_bound semantics
if (mid == list.Count) if (mid == list.Count)
return max; //had to go all the way to max before giving up; lower bound is max {
return max; // had to go all the way to max before giving up; lower bound is max
}
if (mid == 0) if (mid == 0)
return -1; //had to go all the way to min before giving up; lower bound is min {
return -1; // had to go all the way to min before giving up; lower bound is min
}
midKey = keySelector(list[mid]); midKey = keySelector(list[mid]);
if (midKey.CompareTo(key) >= 0) return mid - 1; if (midKey.CompareTo(key) >= 0)
else return mid; {
return mid - 1;
}
return mid;
} }
// http://stackoverflow.com/questions/1766328/can-linq-use-binary-search-when-the-collection-is-ordered // http://stackoverflow.com/questions/1766328/can-linq-use-binary-search-when-the-collection-is-ordered

View File

@ -1,9 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
namespace BizHawk.Common.ReflectionExtensions namespace BizHawk.Common.ReflectionExtensions
{ {
@ -17,15 +14,15 @@ namespace BizHawk.Common.ReflectionExtensions
/// </summary> /// </summary>
public static string GetDescription(this object obj) public static string GetDescription(this object obj)
{ {
Type type = obj.GetType(); var type = obj.GetType();
var memInfo = type.GetMember(obj.ToString()); var memInfo = type.GetMember(obj.ToString());
if (memInfo != null && memInfo.Length > 0) if (memInfo.Length > 0)
{ {
object[] attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false); var attrs = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attrs != null && attrs.Length > 0) if (attrs.Length > 0)
{ {
return ((DescriptionAttribute)attrs[0]).Description; return ((DescriptionAttribute)attrs[0]).Description;
} }
@ -69,12 +66,16 @@ namespace BizHawk.Common.ReflectionExtensions
if (attribute != null) if (attribute != null)
{ {
if (attribute.Description == description) if (attribute.Description == description)
{
return (T)field.GetValue(null); return (T)field.GetValue(null);
}
} }
else else
{ {
if (field.Name == description) if (field.Name == description)
{
return (T)field.GetValue(null); return (T)field.GetValue(null);
}
} }
} }

View File

@ -329,7 +329,7 @@ namespace BizHawk.Common.StringExtensions
var output = new StringBuilder(); var output = new StringBuilder();
bool usedDot = false; var usedDot = false;
foreach (var chr in raw) foreach (var chr in raw)
{ {
if (chr == '.') if (chr == '.')
@ -338,10 +338,8 @@ namespace BizHawk.Common.StringExtensions
{ {
continue; continue;
} }
else
{ usedDot = true;
usedDot = true;
}
} }
if (IsFixedPoint(chr)) if (IsFixedPoint(chr))
@ -366,8 +364,8 @@ namespace BizHawk.Common.StringExtensions
var output = new StringBuilder(); var output = new StringBuilder();
bool usedDot = false; var usedDot = false;
int count = 0; var count = 0;
foreach (var chr in raw) foreach (var chr in raw)
{ {
if (count == 0 && chr == '-') if (count == 0 && chr == '-')
@ -382,10 +380,8 @@ namespace BizHawk.Common.StringExtensions
{ {
continue; continue;
} }
else
{ usedDot = true;
usedDot = true;
}
} }
if (IsFixedPoint(chr)) if (IsFixedPoint(chr))
@ -393,9 +389,10 @@ namespace BizHawk.Common.StringExtensions
output.Append(chr); output.Append(chr);
} }
} }
count++;
} }
count++;
return output.ToString(); return output.ToString();
} }

View File

@ -159,7 +159,7 @@ namespace BizHawk.Common
/// <summary> /// <summary>
/// these extensions won't even be tried as archives (removes spurious archive detects since some of the signatures are pretty damn weak) /// these extensions won't even be tried as archives (removes spurious archive detects since some of the signatures are pretty damn weak)
/// </summary> /// </summary>
public string[] NonArchiveExtensions = new string[] { }; public string[] NonArchiveExtensions = { };
public void Open(string path) public void Open(string path)
{ {

View File

@ -179,7 +179,7 @@ namespace BizHawk.Common
public class Tester public class Tester
{ {
Queue<byte> shazam = new Queue<byte>(); private readonly Queue<byte> shazam = new Queue<byte>();
string bufid; string bufid;
unsafe void a() unsafe void a()
@ -247,11 +247,13 @@ namespace BizHawk.Common
/// </summary> /// </summary>
public unsafe class IPCRingBufferStream : Stream public unsafe class IPCRingBufferStream : Stream
{ {
private readonly IPCRingBuffer buf;
public IPCRingBufferStream(IPCRingBuffer buf) public IPCRingBufferStream(IPCRingBuffer buf)
{ {
this.buf = buf; this.buf = buf;
} }
IPCRingBuffer buf;
public override bool CanRead { get { return true; } } public override bool CanRead { get { return true; } }
public override bool CanSeek { get { return false; } } public override bool CanSeek { get { return false; } }
public override bool CanWrite { get { return true; } } public override bool CanWrite { get { return true; } }

View File

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following

View File

@ -1128,9 +1128,9 @@ namespace BizHawk.Common
_tw.WriteLine("{0} {1}", name, val); _tw.WriteLine("{0} {1}", name, val);
} }
private class Section : Dictionary<string, Section> private sealed class Section : Dictionary<string, Section>
{ {
public string Name = String.Empty; public string Name = string.Empty;
public readonly Dictionary<string, string> Items = new Dictionary<string, string>(); public readonly Dictionary<string, string> Items = new Dictionary<string, string>();
} }

View File

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Collections.Concurrent; using System.Collections.Concurrent;
@ -11,10 +9,9 @@ namespace BizHawk.Common
{ {
public class SettingsUtil public class SettingsUtil
{ {
private class DefaultValueSetter private sealed class DefaultValueSetter
{ {
public Action<object, object[]> SetDefaultValues; public Action<object, object[]> SetDefaultValues;
public Type Type;
public object[] DefaultValues; public object[] DefaultValues;
} }
@ -74,7 +71,6 @@ namespace BizHawk.Common
return new DefaultValueSetter return new DefaultValueSetter
{ {
SetDefaultValues = (Action<object, object[]>)dyn.CreateDelegate(typeof(Action<object, object[]>)), SetDefaultValues = (Action<object, object[]>)dyn.CreateDelegate(typeof(Action<object, object[]>)),
Type = t,
DefaultValues = DefaultValues.ToArray() DefaultValues = DefaultValues.ToArray()
}; };
} }

View File

@ -359,7 +359,7 @@ namespace BizHawk.Common
const int BUFF_SIZE = 4096; const int BUFF_SIZE = 4096;
var buffer = new byte[BUFF_SIZE]; var buffer = new byte[BUFF_SIZE];
int bytesRead = 0; int bytesRead;
var inStream = new BufferedStream(stream); var inStream = new BufferedStream(stream);
var outStream = new MemoryStream(); var outStream = new MemoryStream();

View File

@ -1,5 +1,3 @@
using System;
static class VersionInfo static class VersionInfo
{ {
public const string MAINVERSION = "1.7.0"; public const string MAINVERSION = "1.7.0";