Dicom.Data.DcmDataset.LoadDicomFieldValue C# (CSharp) Method

LoadDicomFieldValue() private method

private LoadDicomFieldValue ( DcmElement elem, Type vtype, DicomFieldDefault deflt, bool udzl ) : object
elem DcmElement
vtype System.Type
deflt DicomFieldDefault
udzl bool
return object
        private object LoadDicomFieldValue(DcmElement elem, Type vtype, DicomFieldDefault deflt, bool udzl)
        {
            if (vtype.IsSubclassOf(typeof(DcmElement))) {
                if (elem != null && vtype != elem.GetType())
                    throw new DicomDataException("Invalid binding type for Element VR!");
                return elem;
            } else if (vtype.IsArray) {
                if (elem != null) {
                    if (vtype.GetElementType() != elem.GetValueType())
                        throw new DicomDataException("Invalid binding type for Element VR!");
                    if (elem.GetValueType() == typeof(DateTime))
                        return (elem as DcmDateElementBase).GetDateTimes();
                    else
                        return elem.GetValueObjectArray();
                } else {
                    if (deflt == DicomFieldDefault.EmptyArray)
                        return Array.CreateInstance(vtype, 0);
                    else
                        return null;
                }
            } else {
                if (elem != null) {
                    if (elem.Length == 0 && udzl) {
                        return GetDefaultValue(vtype, deflt);
                    }
                    if (vtype != elem.GetValueType()) {
                        if (vtype == typeof(string)) {
                            return elem.GetValueString();
                        } else if (vtype == typeof(DicomUID) && elem.VR == DicomVR.UI) {
                            return (elem as DcmUniqueIdentifier).GetUID();
                        } else if (vtype == typeof(DicomTransferSyntax) && elem.VR == DicomVR.UI) {
                            return (elem as DcmUniqueIdentifier).GetTS();
                        } else if (vtype == typeof(DcmDateRange) && elem.GetType().IsSubclassOf(typeof(DcmDateElementBase))) {
                            return (elem as DcmDateElementBase).GetDateTimeRange();
                        } else if (vtype == typeof(Int32)) {
                            return Convert.ToInt32(elem.GetValueString(), 10);
                        } else if (vtype == typeof(object)) {
                            return elem.GetValueObject();
                        } else
                            throw new DicomDataException("Invalid binding type for Element VR!");
                    } else {
                        return elem.GetValueObject();
                    }
                } else {
                    return GetDefaultValue(vtype, deflt);
                }
            }
        }