Exemplo n.º 1
0
        public override T Get <T>(int item = -1)
        {
            if (typeof(T) == typeof(string) || typeof(T) == typeof(object))
            {
                return((T)((object)StringValue));
            }

            if (typeof(T) == typeof(string[]) || typeof(T) == typeof(object[]))
            {
                return((T)(object)(new string[] { StringValue }));
            }

            if (typeof(T).IsSubclassOf(typeof(DicomParseable)))
            {
                return((T)DicomParseable.Parse <T>(StringValue));
            }

#if NETFX_CORE
            if (typeof(T).IsEnum())
#else
            if (typeof(T).IsEnum)
#endif
            { return((T)Enum.Parse(typeof(T), StringValue, true)); }

            throw new InvalidCastException("Unable to convert DICOM " + ValueRepresentation.Code + " value to '" + typeof(T).Name + "'");
        }
Exemplo n.º 2
0
        public override T Get <T>(int item = -1)
        {
            if (_values == null)
            {
                if (String.IsNullOrEmpty(StringValue))
                {
                    _values = new string[0];
                }
                else
                {
                    _values = StringValue.Split('\\');
                }
                _count = _values.Length;
            }

            if (typeof(T) == typeof(string) || typeof(T) == typeof(object))
            {
                if (item == -1)
                {
                    return((T)((object)StringValue));
                }

                if (item < 0 || item >= Count)
                {
                    throw new ArgumentOutOfRangeException("item", "Index is outside the range of available value items");
                }

                return((T)((object)_values[item]));
            }

            if (typeof(T) == typeof(string[]) || typeof(T) == typeof(object[]))
            {
                return((T)(object)_values);
            }

            if (typeof(T).IsSubclassOf(typeof(DicomParseable)))
            {
                return((T)DicomParseable.Parse <T>(_values[item]));
            }

#if NETFX_CORE
            if (typeof(T).IsEnum())
#else
            if (typeof(T).IsEnum)
#endif
            { return((T)Enum.Parse(typeof(T), _values[item], true)); }

            throw new InvalidCastException("Unable to convert DICOM " + ValueRepresentation.Code + " value to '" + typeof(T).Name + "'");
        }
Exemplo n.º 3
0
        public override T Get <T>(int item = -1)
        {
            if (_values == null)
            {
                if (String.IsNullOrEmpty(StringValue))
                {
                    _values = new string[0];
                }
                else
                {
                    _values = StringValue.Split('\\');
                }
            }

            if (typeof(T) == typeof(string) || typeof(T) == typeof(object))
            {
                if (item == -1)
                {
                    return((T)((object)StringValue));
                }

                return((T)((object)_values[item]));
            }

            if (typeof(T) == typeof(string[]) || typeof(T) == typeof(object[]))
            {
                return((T)(object)_values);
            }

            if (typeof(T).IsSubclassOf(typeof(DicomParseable)))
            {
                return((T)DicomParseable.Parse <T>(_values[item]));
            }

            if (typeof(T).IsEnum)
            {
                return((T)Enum.Parse(typeof(T), _values[item]));
            }

            throw new InvalidCastException("Unable to convert DICOM " + ValueRepresentation.Code + " value to '" + typeof(T).Name + "'");
        }
Exemplo n.º 4
0
 public void Parse_NonImplementingClass_Throws()
 {
     Assert.Throws <DicomDataException>(() => DicomParseable.Parse <DicomFile>(@".\Test Data\CT1_J2KI"));
 }
Exemplo n.º 5
0
        public void Parse_ImplementingClass_Succeeds()
        {
            var syntax = DicomParseable.Parse <DicomTransferSyntax>("1.2.840.10008.1.2.4.51");

            Assert.Equal(DicomTransferSyntax.JPEGProcess2_4, syntax);
        }