private object GetDefaultValue(Type vtype, DicomFieldDefault deflt)
{
try {
if (vtype == typeof(DicomUID) || vtype == typeof(DicomTransferSyntax) || vtype.IsSubclassOf(typeof(DcmElement)))
return null;
if (deflt == DicomFieldDefault.Null || deflt == DicomFieldDefault.None)
return null;
if (deflt == DicomFieldDefault.DBNull)
return DBNull.Value;
if (deflt == DicomFieldDefault.Default && vtype != typeof(string))
return Activator.CreateInstance(vtype);
if (vtype == typeof(string)) {
if (deflt == DicomFieldDefault.StringEmpty || deflt == DicomFieldDefault.Default)
return String.Empty;
} else if (vtype == typeof(DateTime)) {
if (deflt == DicomFieldDefault.DateTimeNow)
return DateTime.Now;
if (deflt == DicomFieldDefault.MinValue)
return DateTime.MinValue;
if (deflt == DicomFieldDefault.MaxValue)
return DateTime.MaxValue;
} else if (vtype.IsSubclassOf(typeof(ValueType))) {
if (deflt == DicomFieldDefault.MinValue) {
PropertyInfo pi = vtype.GetProperty("MinValue", BindingFlags.Static);
if (pi != null) return pi.GetValue(null, null);
}
if (deflt == DicomFieldDefault.MaxValue) {
PropertyInfo pi = vtype.GetProperty("MaxValue", BindingFlags.Static);
if (pi != null) return pi.GetValue(null, null);
}
return Activator.CreateInstance(vtype);
}
return null;
}
catch (Exception) {
Debug.Log.Error("Error in default value type! - {0}", vtype.ToString());
return null;
}
}