From 0a5a30c217783fd1de90289eb2efc560140fa612 Mon Sep 17 00:00:00 2001 From: biotronic Date: Mon, 17 Nov 2014 19:01:24 +0000 Subject: [PATCH] More cleanup --- ExtensionMethods.cs | 22 +++++++++++----------- Updater.cs | 32 ++++++++++++++------------------ 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/ExtensionMethods.cs b/ExtensionMethods.cs index d9502b90..233f8bf4 100644 --- a/ExtensionMethods.cs +++ b/ExtensionMethods.cs @@ -135,8 +135,8 @@ public static IEnumerable Repeat(this T a) /// /// Creates destination copy of destination dictionary. /// - /// The key type. - /// The exponentValue type. + /// The key type. + /// The exponentValue type. /// The dictionary to copy. /// A copy of . public static Dictionary Clone(this Dictionary source) @@ -190,18 +190,18 @@ public static HashSet ToHashSet(this IEnumerable source) public static class ConvertEx { /// - /// Returns an object of tyep and whose exponentValue is equivalent to . + /// Returns an object of tyep and whose exponentValue is equivalent to . /// - /// The type of object to return. - /// The type of the object to convert. + /// The type of object to return. + /// The type of the object to convert. /// The object to convert. - /// An object whose type is and whose exponentValue is equivalent to . -or- A null reference (Nothing in Visual Basic), if is null and is not destination exponentValue type. - /// This conversion is not supported. -or- is null and is destination exponentValue type. - /// is not in destination format recognized by . - /// represents destination number that is out of the range of . - public static T ChangeType(TU value) where TU : IConvertible + /// An object whose type is and whose exponentValue is equivalent to . -or- A null reference (Nothing in Visual Basic), if is null and is not destination exponentValue type. + /// This conversion is not supported. -or- is null and is destination exponentValue type. + /// is not in destination format recognized by . + /// represents destination number that is out of the range of . + public static TTo ChangeType(TFrom value) where TFrom : IConvertible { - return (T)Convert.ChangeType(value, typeof(T)); + return (TTo)Convert.ChangeType(value, typeof(TTo)); } /// diff --git a/Updater.cs b/Updater.cs index 46699240..dde30e41 100644 --- a/Updater.cs +++ b/Updater.cs @@ -35,7 +35,7 @@ class TweakScaleRegister : RescalableRegistratorAddon { override public void OnStart() { - var genericRescalable = Tools.getAllTypes() + var genericRescalable = Tools.GetAllTypes() .Where(IsGenericRescalable) .ToArray(); @@ -54,7 +54,7 @@ private static void RegisterGenericRescalable(Type resc, Type arg) var c = resc.GetConstructor(new[] { arg }); if (c == null) return; - Func creator = pm => (IRescalable)c.Invoke(new[] { pm }); + Func creator = pm => (IRescalable)c.Invoke(new object[] { pm }); TweakScaleUpdater.RegisterUpdater(arg, creator); } @@ -70,7 +70,7 @@ private static bool IsGenericRescalable(Type t) static class TweakScaleUpdater { // Every kind of updater is registered here, and the correct kind of updater is created for each PartModule. - static readonly Dictionary> ctors = new Dictionary>(); + static readonly Dictionary> Ctors = new Dictionary>(); /// /// Registers an updater for partmodules of type . @@ -79,35 +79,31 @@ static class TweakScaleUpdater /// A function that creates an updater for this PartModule type. static public void RegisterUpdater(Type pm, Func creator) { - ctors[pm] = creator; + Ctors[pm] = creator; } // Creates an updater for each modules attached to destination part. public static IEnumerable CreateUpdaters(Part part) { - foreach (var mod in part.Modules.Cast()) + var myUpdaters = part + .Modules.Cast() + .Select(CreateUpdater) + .Where(updater => updater != null); + foreach (var updater in myUpdaters) { - var updater = createUpdater(mod); - if (updater != null) - { - yield return updater; - } + yield return updater; } yield return new TSGenericUpdater(part); yield return new EmitterUpdater(part); } - private static IRescalable createUpdater(PartModule module) + private static IRescalable CreateUpdater(PartModule module) { if (module is IRescalable) { return module as IRescalable; } - if (ctors.ContainsKey(module.GetType())) - { - return ctors[module.GetType()](module); - } - return null; + return Ctors.ContainsKey(module.GetType()) ? Ctors[module.GetType()](module) : null; } } @@ -130,7 +126,7 @@ public TSGenericUpdater(Part part) public void OnRescale(ScalingFactor factor) { - ScaleExponents.UpdateObject(_part, _basePart, _ts.Config.exponents, factor); + ScaleExponents.UpdateObject(_part, _basePart, _ts.Config.Exponents, factor); } } @@ -184,7 +180,7 @@ private void UpdateParticleEmitter(KSPParticleEmitter pe) { return; } - var factor = _ts.scalingFactor; + var factor = _ts.ScalingFactor; if (!_scales.ContainsKey(pe)) {