diff --git a/VectoCommon/VectoCommon/Utils/EnumberableExtensionMethods.cs b/VectoCommon/VectoCommon/Utils/EnumberableExtensionMethods.cs index d60a984f40dcdc6fea274194db97f5a3bb99a2df..8864d43cead8a86cda9e64a23e6473e9d0cbd45a 100644 --- a/VectoCommon/VectoCommon/Utils/EnumberableExtensionMethods.cs +++ b/VectoCommon/VectoCommon/Utils/EnumberableExtensionMethods.cs @@ -225,5 +225,10 @@ namespace TUGraz.VectoCommon.Utils } } } + + public static IEnumerable<T> Repeat<T>(this T element, int count) + { + return Enumerable.Repeat(element, count); + } } } \ No newline at end of file diff --git a/VectoCommon/VectoCommon/Utils/SI.cs b/VectoCommon/VectoCommon/Utils/SI.cs index 955bfdbf514f9e8e64fd049841124e636eeb45cd..63b9f9e886250b9e1b1efa1aec09336f2a881ee1 100644 --- a/VectoCommon/VectoCommon/Utils/SI.cs +++ b/VectoCommon/VectoCommon/Utils/SI.cs @@ -44,7 +44,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Scalar Values. Converts implicitely to double and is only castable if the SI value has no units. /// </summary> - public class Scalar : SIBase<Scalar> + public sealed class Scalar : SIBase<Scalar> { [DebuggerHidden] private Scalar(double val) : base(val) {} @@ -112,7 +112,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Newton [N]. /// </summary> - public class Newton : SIBase<Newton> + public sealed class Newton : SIBase<Newton> { private static readonly Unit[] NumeratorDefault = { Unit.N }; @@ -149,7 +149,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Radian [] (rad). /// </summary> - public class Radian : SIBase<Radian> + public sealed class Radian : SIBase<Radian> { [DebuggerHidden] private Radian(double val) : base(val) {} @@ -158,7 +158,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for PerSquareSecond [1/s^2]. /// </summary> - public class PerSquareSecond : SIBase<PerSquareSecond> + public sealed class PerSquareSecond : SIBase<PerSquareSecond> { private static readonly Unit[] DenominatorDefault = { Unit.s, Unit.s }; @@ -175,7 +175,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Meter per square second [m/s^2]. /// </summary> - public class MeterPerSquareSecond : SIBase<MeterPerSquareSecond> + public sealed class MeterPerSquareSecond : SIBase<MeterPerSquareSecond> { private static readonly Unit[] NumeratorDefault = { Unit.m }; private static readonly Unit[] DenominatorDefault = { Unit.s, Unit.s }; @@ -196,7 +196,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Second [s]. /// </summary> - public class Second : SIBase<Second> + public sealed class Second : SIBase<Second> { private static readonly Unit[] NumeratorDefault = { Unit.s }; @@ -207,7 +207,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Meter [m]. /// </summary> - public class Meter : SIBase<Meter> + public sealed class Meter : SIBase<Meter> { private static readonly Unit[] NumeratorDefault = { Unit.m }; @@ -239,7 +239,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for KilogramPerMeter [kg/m]. /// </summary> - public class KilogramPerMeter : SIBase<KilogramPerMeter> + public sealed class KilogramPerMeter : SIBase<KilogramPerMeter> { private static readonly Unit[] NumeratorDefault = { Unit.k, Unit.g }; private static readonly Unit[] DenominatorDefault = { Unit.m }; @@ -248,39 +248,7 @@ namespace TUGraz.VectoCommon.Utils private KilogramPerMeter(double val) : base(val, NumeratorDefault, DenominatorDefault) {} } - ///// <summary> - ///// SI Class for Gram - ///// </summary> - //public class Gram : SIBase<Gram> - //{ - // private static readonly Unit[] NumeratorDefault = { Unit.g }; - - // [DebuggerHidden] - // private Gram(double val) : base(val, NumeratorDefault) {} - //} - - //public class GramPerSecond : SIBase<GramPerSecond> - //{ - // private static readonly Unit[] NumeratorDefault = { Unit.g }; - // private static readonly Unit[] DenominatorDefault = { Unit.s }; - - // private GramPerSecond(double val) : base(val, NumeratorDefault, DenominatorDefault) { } - - // public static Gram operator *(GramPerSecond gps, Second s) - // { - // return SIBase<Gram>.Create(gps.Val * s.Value()); - // } - //} - - //public class GramPerLiter : SIBase<GramPerLiter> - //{ - // private static readonly Unit[] NumeratorDefault = { Unit.g }; - // private static readonly Unit[] DenominatorDefault = { Unit.liter }; - - // private GramPerLiter(double val) : base(val, NumeratorDefault, DenominatorDefault) {} - //} - - public class LiterPerSecond : SIBase<LiterPerSecond> + public sealed class LiterPerSecond : SIBase<LiterPerSecond> { private static readonly Unit[] NumeratorDefault = { Unit.liter }; private static readonly Unit[] DenominatorDefault = { Unit.s }; @@ -291,7 +259,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Kilogram [kg]. /// </summary> - public class Kilogram : SIBase<Kilogram> + public sealed class Kilogram : SIBase<Kilogram> { private static readonly Unit[] NumeratorDefault = { Unit.k, Unit.g }; @@ -322,7 +290,7 @@ namespace TUGraz.VectoCommon.Utils } } - public class Liter : SIBase<Liter> + public sealed class Liter : SIBase<Liter> { private static readonly Unit[] NumeratorDefault = { Unit.liter }; @@ -338,7 +306,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// /// </summary> - public class NormLiter : SIBase<NormLiter> + public sealed class NormLiter : SIBase<NormLiter> { private static readonly Unit[] NumeratorDefault = { Unit.NI }; @@ -354,7 +322,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// /// </summary> - public class NormLiterPerSecond : SIBase<NormLiterPerSecond> + public sealed class NormLiterPerSecond : SIBase<NormLiterPerSecond> { private static readonly Unit[] NumeratorDefault = { Unit.NI }; private static readonly Unit[] DenominatorDefault = { Unit.s }; @@ -376,7 +344,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Kilogram per Second [kg]. /// </summary> - public class KilogramPerSecond : SIBase<KilogramPerSecond> + public sealed class KilogramPerSecond : SIBase<KilogramPerSecond> { private static readonly Unit[] NumeratorDefault = { Unit.k, Unit.g }; private static readonly Unit[] DenominatorDefault = { Unit.s }; @@ -394,7 +362,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Square meter [m^2]. /// </summary> - public class SquareMeter : SIBase<SquareMeter> + public sealed class SquareMeter : SIBase<SquareMeter> { private static readonly Unit[] NumeratorDefault = { Unit.m, Unit.m }; @@ -417,7 +385,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Kilogram Square Meter [kgm^2]. /// </summary> - public class KilogramSquareMeter : SIBase<KilogramSquareMeter> + public sealed class KilogramSquareMeter : SIBase<KilogramSquareMeter> { private static readonly Unit[] NumeratorDefault = { Unit.k, Unit.g, Unit.m, Unit.m }; @@ -434,7 +402,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Kilogram Square Meter [kgm^2]. /// </summary> - public class KilogramPerCubicMeter : SIBase<KilogramPerCubicMeter> + public sealed class KilogramPerCubicMeter : SIBase<KilogramPerCubicMeter> { private static readonly Unit[] NumeratorDefault = { Unit.k, Unit.g }; private static readonly Unit[] DenominatorDefault = { Unit.m, Unit.m, Unit.m }; @@ -462,7 +430,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Kilogramm per watt second [kg/Ws]. /// </summary> - public class KilogramPerWattSecond : SIBase<KilogramPerWattSecond> + public sealed class KilogramPerWattSecond : SIBase<KilogramPerWattSecond> { private static readonly Unit[] NumeratorDefault = { Unit.k, Unit.g }; private static readonly Unit[] DenominatorDefault = { Unit.W, Unit.s }; @@ -474,7 +442,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for watt second [Ws]. /// </summary> - public class WattSecond : SIBase<WattSecond> + public sealed class WattSecond : SIBase<WattSecond> { private static readonly Unit[] NumeratorDefault = { Unit.W, Unit.s }; @@ -491,7 +459,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for Watt [W]. /// </summary> - public class Watt : SIBase<Watt> + public sealed class Watt : SIBase<Watt> { private static readonly Unit[] NumeratorDefault = { Unit.W }; @@ -545,7 +513,7 @@ namespace TUGraz.VectoCommon.Utils } } - public class Joule : SIBase<Joule> + public sealed class Joule : SIBase<Joule> { private static readonly Unit[] NumeratorDefault = { Unit.W, Unit.s }; @@ -568,7 +536,7 @@ namespace TUGraz.VectoCommon.Utils } } - public class JoulePerKilogramm : SIBase<JoulePerKilogramm> + public sealed class JoulePerKilogramm : SIBase<JoulePerKilogramm> { private static readonly Unit[] NumeratorDefault = { Unit.J }; private static readonly Unit[] DenominatorDefault = { Unit.k, Unit.g }; @@ -585,7 +553,7 @@ namespace TUGraz.VectoCommon.Utils /// SI Class for one per second [1/s]. /// </summary> [DebuggerDisplay("rad/s: {this} | rpm: {ConvertTo().Rounds.Per.Minute}")] - public class PerSecond : SIBase<PerSecond> + public sealed class PerSecond : SIBase<PerSecond> { private static readonly Unit[] DenominatorDefault = { Unit.s }; @@ -602,7 +570,7 @@ namespace TUGraz.VectoCommon.Utils /// SI Class for Meter per second [m/s]. /// </summary> [DebuggerDisplay("{this} | {ConvertTo().Kilo.Meter.Per.Hour}")] - public class MeterPerSecond : SIBase<MeterPerSecond> + public sealed class MeterPerSecond : SIBase<MeterPerSecond> { private static readonly Unit[] NumeratorDefault = { Unit.m }; private static readonly Unit[] DenominatorDefault = { Unit.s }; @@ -668,7 +636,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// SI Class for NewtonMeter [Nm]. /// </summary> - public class NewtonMeter : SIBase<NewtonMeter> + public sealed class NewtonMeter : SIBase<NewtonMeter> { private static readonly Unit[] NumeratorDefault = { Unit.N, Unit.m }; @@ -718,7 +686,7 @@ namespace TUGraz.VectoCommon.Utils } } - public class NewtonMeterSecond : SIBase<NewtonMeterSecond> + public sealed class NewtonMeterSecond : SIBase<NewtonMeterSecond> { private static readonly Unit[] NumeratorDefault = { Unit.N, Unit.m, Unit.s }; private NewtonMeterSecond(double val) : base(val, NumeratorDefault) {} @@ -727,7 +695,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// /// </summary> - public class Ampere : SIBase<Ampere> + public sealed class Ampere : SIBase<Ampere> { private static readonly Unit[] NumeratorDefault = { Unit.Ampere }; private Ampere(double val) : base(val, NumeratorDefault) {} @@ -756,7 +724,7 @@ namespace TUGraz.VectoCommon.Utils /// <summary> /// /// </summary> - public class Volt : SIBase<Volt> + public sealed class Volt : SIBase<Volt> { private static readonly Unit[] NumeratorDefault = { Unit.Volt }; private Volt(double val) : base(val, NumeratorDefault) {} @@ -779,7 +747,7 @@ namespace TUGraz.VectoCommon.Utils /// <typeparam name="T"></typeparam> public abstract class SIBase<T> : SI where T : SIBase<T> { - static T _zeroPrototype; + private static readonly T ZeroPrototype; static SIBase() { @@ -788,7 +756,7 @@ namespace TUGraz.VectoCommon.Utils var parameter = Expression.Parameter(typeof(double)); var lambda = Expression.Lambda<Func<double, T>>(Expression.New(constructorInfo, parameter), parameter); Constructor = lambda.Compile(); - _zeroPrototype = Constructor(0); + ZeroPrototype = Constructor(0); } /// <summary> @@ -803,7 +771,7 @@ namespace TUGraz.VectoCommon.Utils public static T Create(double val) { if (val == 0) - return _zeroPrototype; + return ZeroPrototype; return Constructor(val); }