public void ConceptConstructor()
        {
            var someCodings      = new[] { new P.Code("http://system1", "codeA"), new P.Code("http://system2", "codeB") };
            var sameCodings      = new[] { new P.Code("http://system1", "codeA"), new P.Code("http://system2", "codeB") };
            var someOtherCodings = new[] { new P.Code("http://system1", "codeB"), new P.Code("http://system2", "codeC") };

            var newCds = new P.Concept(someCodings);

            Assert.AreEqual(newCds, new P.Concept(someCodings));
            Assert.AreEqual(newCds, new P.Concept(sameCodings));
            Assert.AreNotEqual(newCds, new P.Concept(someOtherCodings));
            Assert.AreNotEqual(newCds, new P.Concept(someCodings, "bla"));
        }
Esempio n. 2
0
        public static bool TryParse(string value, Type primitiveType, out object?parsed)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }
            if (!typeof(Any).IsAssignableFrom(primitiveType))
            {
                throw new ArgumentException($"Must be a subclass of {nameof(Any)}.", nameof(primitiveType));
            }

            bool success;

            (success, parsed) = parse();
            return(success);

            (bool success, object?p) parse()
            {
                if (primitiveType == typeof(Boolean))
                {
                    return(Boolean.TryParse(value, out var p), p?.Value);
                }
                else if (primitiveType == typeof(Code))
                {
                    return(Code.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(Concept))
                {
                    return(Concept.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(Decimal))
                {
                    return(Decimal.TryParse(value, out var p), p?.Value);
                }
                else if (primitiveType == typeof(Integer))
                {
                    return(Integer.TryParse(value, out var p), p?.Value);
                }
                else if (primitiveType == typeof(Long))
                {
                    return(Long.TryParse(value, out var p), p?.Value);
                }
                else if (primitiveType == typeof(Date))
                {
                    return(Date.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(DateTime))
                {
                    return(DateTime.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(Time))
                {
                    return(Time.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(Ratio))
                {
                    return(Ratio.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(Quantity))
                {
                    return(Quantity.TryParse(value, out var p), p);
                }
                else if (primitiveType == typeof(String))
                {
                    return(String.TryParse(value, out var p), p?.Value);
                }
                else
                {
                    return(false, null);
                }
            }
        }