Example #1
0
        /// <summary>
        /// Use reflection to get strongly-typed constructor info from <paramref name="item"/>.
        /// </summary>
        /// <param name="item">DICOM item for which to get constructor.</param>
        /// <param name="parameterTypes">Expected parameter types in the requested constructor.</param>
        /// <returns>Constructor info corresponding to <paramref name="item"/> and <paramref name="parameterTypes"/>.</returns>
        private static ConstructorInfo GetConstructor(DicomItem item, params Type[] parameterTypes)
        {
#if PORTABLE || NETSTANDARD || NETFX_CORE
            return(item.GetType().GetTypeInfo().DeclaredConstructors.Single(
                       ci =>
            {
                var pars = ci.GetParameters().Select(par => par.ParameterType);
                return pars.SequenceEqual(parameterTypes);
            }));
#else
            return(item.GetType().GetConstructor(parameterTypes));
#endif
        }
Example #2
0
        /// <summary>Evaluates whether a DICOM item is of type Other*</summary>
        /// <param name="item"></param>
        /// <returns>A boolean flag indicating whether the item is of the expected type, otherwise false</returns>
        private static bool IsOtherElement(DicomItem item)
        {
            var t = item.GetType();

            return(t == typeof(DicomOtherByte) || t == typeof(DicomOtherDouble) || t == typeof(DicomOtherFloat) ||
                   t == typeof(DicomOtherLong) || t == typeof(DicomOtherWord) || t == typeof(DicomUnknown));
        }
Example #3
0
        /// <summary>Evaluates whether an element has a generic valueType</summary>
        /// <param name="item"></param>
        /// <returns>The data type if found, otherwise null</returns>
        private static Type ElementValueType(DicomItem item)
        {
            var t = item.GetType();

#if NET35
            if (t.IsGenericType && !t.ContainsGenericParameters && t.GetGenericTypeDefinition() == typeof(DicomValueElement <>))
            {
                return(t.GetGenericArguments()[0]);
            }
#else
            if (t.IsConstructedGenericType && t.GetGenericTypeDefinition() == typeof(DicomValueElement <>))
            {
                return(t.GenericTypeArguments[0]);
            }
#endif
            return(null);
        }