public T Get <T>(PortfolioPosition position,
                         ScalarAttribute attribute,
                         DateTime dateTime,
                         T defaultValue) where T : struct, IConvertible
        {
            //прочитали скалярный атрибут scalarStr
            //нашли в нем наше значение
            //вернули
            //не нашли в нем наше значение вернули defaultValue

            ScalarStr str = GetScalarStr(position, attribute);

            if (str == null || !str.HasValue(dateTime))
            {
                return(defaultValue);
            }

            string strIdent = str.Get(dateTime);
            KeyValuePair <Type, string> tke =
                new KeyValuePair <Type, string>(typeof(T), strIdent);

            if (_mapping.TKE.ContainsKey(tke))
            {
                Enum value = _mapping.TKE[tke];
                return((T)Enum.Parse(typeof(T), value.ToString(), true));
            }
            else
            {
                return(defaultValue);
            }
        }
        public bool Get <T>(PortfolioPosition position,
                            ScalarAttribute attribute,
                            DateTime dateTime)
        {
            ScalarStr str = GetScalarStr(position, attribute);

            if (str == null || !str.HasValue(dateTime))
            {
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public void TestScalarGet()
        {
            Dictionary <DateTime, string> dateTimes = new Dictionary <DateTime, string>()
            {
                { DateTime.Now, "bushuev" },
                { DateTime.Now.AddDays(-1), "roman" },
                { DateTime.Now.AddDays(1), "nik" }
            };

            ScalarStr date = new ScalarStr(dateTimes);

            Assert.IsFalse(date.HasValue(DateTime.Now.AddDays(-2)));
            Assert.AreEqual(date.Get(DateTime.Now), "bushuev");
            Assert.AreEqual(date.Get(DateTime.Now.AddDays(-1)), "roman");
            Assert.AreEqual(date.Get(DateTime.Now.AddDays(100)), "nik");
        }