From 0a49bdd931dafb2f1e11cec50b22a859866d4ecf Mon Sep 17 00:00:00 2001
From: Michael Krisper <michael.krisper@tugraz.at>
Date: Mon, 13 Jun 2016 12:38:28 +0200
Subject: [PATCH] added SI Prototype for 0-Instances

---
 VectoCommon/VectoCommon/Utils/SI.cs | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/VectoCommon/VectoCommon/Utils/SI.cs b/VectoCommon/VectoCommon/Utils/SI.cs
index 6005ad2e87..955bfdbf51 100644
--- a/VectoCommon/VectoCommon/Utils/SI.cs
+++ b/VectoCommon/VectoCommon/Utils/SI.cs
@@ -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);
 		}
 
-- 
GitLab