Skip to content

Commit

Permalink
General Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Biotronic committed Nov 17, 2014
1 parent 3f68657 commit 2d7d32e
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 487 deletions.
4 changes: 2 additions & 2 deletions Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void Start()
{
// Checkers are identified by the type name and version field name.
FieldInfo[] fields =
getAllTypes()
GetAllTypes()
.Where(t => t.Name == "CompatibilityChecker")
.Select(t => t.GetField("_version", BindingFlags.Static | BindingFlags.NonPublic))
.Where(f => f != null)
Expand Down Expand Up @@ -201,7 +201,7 @@ public static bool IsAllCompatible()
return IsCompatible() && IsUnityCompatible() && !IsWin64();
}

private static IEnumerable<Type> getAllTypes()
private static IEnumerable<Type> GetAllTypes()
{
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
Expand Down
71 changes: 28 additions & 43 deletions ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

Expand All @@ -14,12 +13,12 @@ public static class ExtensionMethods
/// </summary>
/// <typeparam name="T1">The type of the elements in the first IEnumerable.</typeparam>
/// <typeparam name="T2">The type of the elements in the second IEnumerable.</typeparam>
/// <param name="destination">The first IEnumerable.</param>
/// <param name="source">The second IEnumerable.</param>
/// <param name="a">The first IEnumerable.</param>
/// <param name="b">The second IEnumerable.</param>
/// <returns>An IEnumerable containing Tuples of the elements in the two IEnumerables.</returns>
public static IEnumerable<Tuple<T1, T2>> Zip<T1, T2>(this IEnumerable<T1> a, IEnumerable<T2> b)
{
return a.Zip(b, (x, y) => Tuple.Create(x, y));
return a.Zip(b, Tuple.Create);
}

/// <summary>
Expand Down Expand Up @@ -91,15 +90,8 @@ public static int StupidCount(this IEnumerable a)
/// <returns>The first field of the given type, or null.</returns>
public static FieldInfo GetNonPublicFieldByType<T>(this Type t)
{
FieldInfo[] f = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var e in f)
{
if (e.FieldType == typeof(T))
{
return e;
}
}
return null;
var f = t.GetFields(BindingFlags.NonPublic | BindingFlags.Instance);
return f.FirstOrDefault(e => e.FieldType == typeof (T));
}

/// <summary>
Expand All @@ -117,10 +109,10 @@ public static bool IsOverride(this MethodInfo m)
/// </summary>
/// <typeparam name="T1">The type of the elements in the first IEnumerable.</typeparam>
/// <typeparam name="T2">The type of the elements in the second IEnumerable.</typeparam>
/// <param name="destination">The IEnumerable to be filtered</param>
/// <param name="source">The IEnumerable acting as destination selector.</param>
/// <param name="filterFunc">The function to determine if an element in <paramref name="source"/> means the corresponing element in <paramref name="destination"/> should be kept.</param>
/// <returns>An IEnumerable the elements of which are chosen from <paramref name="destination"/> where <paramref name="filterFunc"/> returns true for the corresponding element in <paramref name="source"/>.</returns>
/// <param name="a">The IEnumerable to be filtered</param>
/// <param name="b">The IEnumerable acting as destination selector.</param>
/// <param name="filterFunc">The function to determine if an element in <paramref name="b"/> means the corresponing element in <paramref name="a"/> should be kept.</param>
/// <returns>An IEnumerable the elements of which are chosen from <paramref name="a"/> where <paramref name="filterFunc"/> returns true for the corresponding element in <paramref name="b"/>.</returns>
public static IEnumerable<T1> ZipFilter<T1, T2>(this IEnumerable<T1> a, IEnumerable<T2> b, Func<T2, bool> filterFunc)
{
return a.Zip(b).Where(e => filterFunc(e.Item2)).Select(e => e.Item1);
Expand All @@ -130,8 +122,8 @@ public static IEnumerable<T1> ZipFilter<T1, T2>(this IEnumerable<T1> a, IEnumera
/// Repeats destination exponentValue forever.
/// </summary>
/// <typeparam name="T">The type of the exponentValue to be repeated.</typeparam>
/// <param name="destination">The exponentValue to be repeated.</param>
/// <returns>An IEnumerable&lt;T&gt; containing an infite number of the exponentValue <paramref name="destination"/>"/></returns>
/// <param name="a">The exponentValue to be repeated.</param>
/// <returns>An IEnumerable&lt;T&gt; containing an infite number of the exponentValue <paramref name="a"/>"/></returns>
public static IEnumerable<T> Repeat<T>(this T a)
{
while (true)
Expand All @@ -147,7 +139,7 @@ public static IEnumerable<T> Repeat<T>(this T a)
/// <typeparam name="V">The exponentValue type.</typeparam>
/// <param name="source">The dictionary to copy.</param>
/// <returns>A copy of <paramref name="source"/>.</returns>
public static Dictionary<K, V> Clone<K, V>(this Dictionary<K, V> source)
public static Dictionary<TK, TV> Clone<TK, TV>(this Dictionary<TK, TV> source)
{
return source.AsEnumerable().ToDictionary(a => a.Key, a => a.Value);
}
Expand All @@ -161,14 +153,7 @@ public static Dictionary<K, V> Clone<K, V>(this Dictionary<K, V> source)
public static bool ContainsDuplicates<T>(this IEnumerable<T> source)
{
var tmp = new HashSet<T>();
foreach (var item in source)
{
if (!tmp.Add(item))
{
return true;
}
}
return false;
return source.Any(item => !tmp.Add(item));
}

/// <summary>
Expand All @@ -194,7 +179,7 @@ public static IEnumerable<T> Duplicates<T>(this IEnumerable<T> source)
public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
{
var result = new HashSet<T>();
foreach (T item in source)
foreach (var item in source)
{
result.Add(item);
}
Expand All @@ -205,29 +190,29 @@ public static HashSet<T> ToHashSet<T>(this IEnumerable<T> source)
public static class ConvertEx
{
/// <summary>
/// Returns an object of tyep <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="exponentValue"/>.
/// Returns an object of tyep <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="value"/>.
/// </summary>
/// <typeparam name="T">The type of object to return.</typeparam>
/// <typeparam name="U">The type of the object to convert.</typeparam>
/// <param name="exponentValue">The object to convert.</param>
/// <returns>An object whose type is <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="exponentValue"/>. -or- A null reference (Nothing in Visual Basic), if <paramref name="exponentValue"/> is null and <typeparamref name="T"/> is not destination exponentValue type.</returns>
/// <exception cref="System.InvalidCastException">This conversion is not supported. -or-<paramref name="exponentValue"/> is null and <typeparamref name="T"/> is destination exponentValue type.</exception>
/// <exception cref="System.FormatException"><paramref name="exponentValue"/> is not in destination format recognized by <typeparamref name="T"/>.</exception>
/// <exception cref="System.OverflowException"><paramref name="exponentValue"/> represents destination number that is out of the range of <typeparamref name="T"/>.</exception>
public static T ChangeType<T, U>(U value) where U : System.IConvertible
/// <typeparam name="TU">The type of the object to convert.</typeparam>
/// <param name="value">The object to convert.</param>
/// <returns>An object whose type is <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="value"/>. -or- A null reference (Nothing in Visual Basic), if <paramref name="value"/> is null and <typeparamref name="T"/> is not destination exponentValue type.</returns>
/// <exception cref="System.InvalidCastException">This conversion is not supported. -or-<paramref name="value"/> is null and <typeparamref name="T"/> is destination exponentValue type.</exception>
/// <exception cref="System.FormatException"><paramref name="value"/> is not in destination format recognized by <typeparamref name="T"/>.</exception>
/// <exception cref="System.OverflowException"><paramref name="value"/> represents destination number that is out of the range of <typeparamref name="T"/>.</exception>
public static T ChangeType<T, TU>(TU value) where TU : IConvertible
{
return (T)Convert.ChangeType(value, typeof(T));
}

/// <summary>
/// Returns an object of tyep <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="exponentValue"/>.
/// Returns an object of tyep <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="value"/>.
/// </summary>
/// <typeparam name="T">The type of object to return.</typeparam>
/// <param name="exponentValue">The object to convert.</param>
/// <returns>An object whose type is <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="exponentValue"/>. -or- A null reference (Nothing in Visual Basic), if <paramref name="exponentValue"/> is null and <typeparamref name="T"/> is not destination exponentValue type.</returns>
/// <exception cref="System.InvalidCastException">This conversion is not supported. -or-<paramref name="exponentValue"/> is null and <typeparamref name="T"/> is destination exponentValue type.-or-<paramref name="exponentValue"/> does not implement the System.IConvertible interface.</exception>
/// <exception cref="System.FormatException"><paramref name="exponentValue"/> is not in destination format recognized by <typeparamref name="T"/>.</exception>
/// <exception cref="System.OverflowException"><paramref name="exponentValue"/> represents destination number that is out of the range of <typeparamref name="T"/>.</exception>
/// <param name="value">The object to convert.</param>
/// <returns>An object whose type is <typeparamref name="T"/> and whose exponentValue is equivalent to <paramref name="value"/>. -or- A null reference (Nothing in Visual Basic), if <paramref name="value"/> is null and <typeparamref name="T"/> is not destination exponentValue type.</returns>
/// <exception cref="System.InvalidCastException">This conversion is not supported. -or-<paramref name="value"/> is null and <typeparamref name="T"/> is destination exponentValue type.-or-<paramref name="value"/> does not implement the System.IConvertible interface.</exception>
/// <exception cref="System.FormatException"><paramref name="value"/> is not in destination format recognized by <typeparamref name="T"/>.</exception>
/// <exception cref="System.OverflowException"><paramref name="value"/> represents destination number that is out of the range of <typeparamref name="T"/>.</exception>
public static T ChangeType<T>(object value)
{
return (T)Convert.ChangeType(value, typeof(T));
Expand Down
Binary file modified Gamedata/TweakScale/plugins/Scale.dll
Binary file not shown.
22 changes: 8 additions & 14 deletions MemberUpdater.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using UnityEngine;

namespace TweakScale
{
public class MemberUpdater
{
object _object = null;
FieldInfo _field = null;
PropertyInfo _property = null;
UI_FloatRange _floatRange = null;
readonly object _object;
readonly FieldInfo _field;
readonly PropertyInfo _property;
readonly UI_FloatRange _floatRange;

public static MemberUpdater Create(object obj, string name)
{
Expand Down Expand Up @@ -67,14 +64,11 @@ public object Value
{
return _field.GetValue(_object);
}
else if (_property != null)
if (_property != null)
{
return _property.GetValue(_object, null);
}
else
{
return null;
}
return null;
}
}

Expand All @@ -86,7 +80,7 @@ public Type MemberType
{
return _field.FieldType;
}
else if (_property != null)
if (_property != null)
{
return _property.PropertyType;
}
Expand All @@ -113,7 +107,7 @@ public void Scale(double scale, MemberUpdater source)
return;
}

object newValue = Value;
var newValue = Value;
if (MemberType == typeof(float))
{
Set((float)newValue * (float)scale);
Expand Down
1 change: 0 additions & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
Expand Down
Loading

0 comments on commit 2d7d32e

Please sign in to comment.