Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 0a49bdd9 authored by Michael KRISPER's avatar Michael KRISPER
Browse files

added SI Prototype for 0-Instances

parent 720ce78d
No related branches found
No related tags found
No related merge requests found
......@@ -259,7 +259,6 @@ namespace TUGraz.VectoCommon.Utils
// private Gram(double val) : base(val, NumeratorDefault) {}
//}
//public class GramPerSecond : SIBase<GramPerSecond>
//{
// private static readonly Unit[] NumeratorDefault = { Unit.g };
......@@ -323,7 +322,6 @@ namespace TUGraz.VectoCommon.Utils
}
}
public class Liter : SIBase<Liter>
{
private static readonly Unit[] NumeratorDefault = { Unit.liter };
......@@ -583,7 +581,6 @@ namespace TUGraz.VectoCommon.Utils
}
}
/// <summary>
/// SI Class for one per second [1/s].
/// </summary>
......@@ -782,6 +779,8 @@ namespace TUGraz.VectoCommon.Utils
/// <typeparam name="T"></typeparam>
public abstract class SIBase<T> : SI where T : SIBase<T>
{
static T _zeroPrototype;
static SIBase()
{
var bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance;
......@@ -789,6 +788,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);
}
/// <summary>
......@@ -802,6 +802,9 @@ namespace TUGraz.VectoCommon.Utils
/// <param name="val">The value of the SI object.</param>
public static T Create(double val)
{
if (val == 0)
return _zeroPrototype;
return Constructor(val);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment