Пример #1
0
        /// <summary>
        ///     Method used to read out unknown VR types (not in the dictionary).
        /// </summary>
        /// <typeparam name="T">the type of value to try to read out</typeparam>
        /// <param name="outValue">the value read</param>
        /// <param name="tx">the transfer syntax to try (default is Implicit little endian)</param>
        /// <returns>whether or not the read was successfull</returns>
        public bool TryReadAs <T>(out T outValue) where T : IDICOMElement
        {
            VR vr = VRDictionary.GetVRFromType(typeof(T));

            try
            {
                IDICOMElement el = ElementFactory.GenerateElement(Tag, vr, Data_.ToArray(), TransferSyntax);
                outValue = (T)el;
                return(true);
            }
            catch (Exception e)
            {
                EvilLogger.Instance.Log("Couldn't cast unknown type as type {0} for {1}", LogPriority.ERROR, typeof(T),
                                        Tag);
                outValue = default(T);
                return(false);
            }
        }
Пример #2
0
        /// <summary>
        ///     Method used to read out unknown VR types (not in the dictionary).
        /// </summary>
        /// <typeparam name="T">the type of value to try to read out</typeparam>
        /// <param name="outValue">the value read</param>
        /// <param name="tx">the transfer syntax to try (default is Implicit little endian)</param>
        /// <returns>whether or not the read was successfull</returns>
        public bool TryReadAs <T>(out T outValue) where T : IDICOMElement
        {
            var vr = VRDictionary.GetVRFromType(typeof(T));

            try
            {
                var el = ElementFactory.GenerateElement(Tag, vr, Data_.ToArray(), TransferSyntax, StringEncoding.ISO_IR_192);
                outValue = (T)el;
                return(true);
            }
            catch (Exception e)
            {
                _logger.LogInformation("Couldn't cast unknown type as type {0} for {1}", LogPriority.ERROR, typeof(T),
                                       Tag);
                outValue = default(T);
                return(false);
            }
        }