using System; using NUnit.Framework; namespace OpenMI.Tests { [TestFixture] public class ExchangeItemTest { [Test] public void GetValueAsIValueSet() { IExchangeItem exchangeItem = new ExchangeItem(); IValueSet values = exchangeItem.GetValue(DateTime.Now); Assert.AreEqual(1, values.Values.Length); } [Test] public void GetValueAsDoubleArray() { IExchangeItem exchangeItem = new ExchangeItem(); double[] values = exchangeItem.GetValue(DateTime.Now); Assert.AreEqual(1, values.Length); } } /// /// Defines interface which can be used to link and exchange vlaues of a different types. /// public interface IExchangeItem { T GetValue(DateTime time); } /// /// Implementation of an ExchangeItem able to work with different value types. /// public class ExchangeItem : IExchangeItem { public int GetValue(DateTime time) { return 1; } public T GetValue(DateTime time) { if (typeof(T).Equals(typeof(IValueSet))) { IValueSet valueSet = new ValueSet(); return (T)valueSet; } if (typeof(T).Equals(typeof(double[]))) { double[] values = new double[1]; values[0] = 100.0; return (T)(object)values; } throw new ArgumentException("Can't find value of type: " + typeof(T)); } } /// /// Wrapper of a .NET double[] type. Strange, isn't it? Certainly violation of a YAGNI principle. /// public interface IValueSet { double[] Values { get; set; } } /// /// Implementation of a wrapper of a .NET double[] type. /// public class ValueSet : IValueSet { private double[] values; public double[] Values { get { return values; } set { values = value; } } public ValueSet() { values = new double[1]; } } } -- Delft Hydraulics, GeoDelft, the Subsurface and Groundwater unit of TNO and parts of Rijkswaterstaat have joined forces in a new independent institute for delta technology, Deltares. Deltares combines knowledge and experience in the field of water, soil and the subsurface. We provide innovative solutions to make living in deltas, coastal areas and river basins safe, clean and sustainable. DISCLAIMER: This message is intended exclusively for the addressee(s) and may contain confidential and privileged information. If you are not the intended recipient please notify the sender immediately and destroy this message. Unauthorized use, disclosure or copying of this message is strictly prohibited. The foundation 'Stichting Deltares', which has its seat at Delft, The Netherlands, Commercial Registration Number 41146461, is not liable in any way whatsoever for consequences and/or damages resulting from the improper, incomplete and untimely dispatch, receipt and/or content of this e-mail.