public class xType {
private static bool OkToSet(Object Obj, PropertyInfo pi, bool Force) {
bool status;
if (Force) return true;
status = pi.GetValue(Obj, null) == null;
return status;
}
private static bool OkToSet(Object Obj, FieldInfo fi, bool Force) {
bool status;
if (Force) return true;
status = fi.GetValue(Obj) == null;
return status;
}
public static void SetPublicDefaults(Object Obj, bool Force) {
Type type, sub_type;
Object sub_obj;
type = Obj.GetType();
foreach (PropertyInfo pi in type.GetProperties()) {
sub_type = pi.PropertyType;
if (sub_type == typeof(System.String)) {
if (OkToSet(Obj, pi, Force)) pi.SetValue(Obj, "", null);
} else
if (diub.Text.Substring(sub_type.ToString(), 0, 31) == "System.Collections.Generic.List") {
if (OkToSet(Obj, pi, Force)) {
sub_obj = Activator.CreateInstance(sub_type);
pi.SetValue(Obj, sub_obj, null);
}
}
else {
if (sub_type.BaseType == typeof(System.Object)) {
if (OkToSet(Obj, pi, Force)) {
try {
sub_obj = Activator.CreateInstance(sub_type);
SetPublicDefaults(sub_obj, Force);
pi.SetValue(Obj, sub_obj, null);
} catch (Exception) {
}
}
else {
try {
sub_obj = pi.GetValue(Obj, null);
SetPublicDefaults(sub_obj, Force);
} catch (Exception) {
}
}
}
}
}
foreach (FieldInfo fi in type.GetFields()) {
sub_type = fi.FieldType;
if (sub_type == typeof(System.String)) {
if (OkToSet(Obj, fi, Force)) fi.SetValue(Obj, "");
} else
if (diub.Text.Substring(sub_type.ToString(), 0, 31) == "System.Collections.Generic.List") {
if (OkToSet(Obj, fi, Force)) {
sub_obj = Activator.CreateInstance(sub_type);
fi.SetValue(Obj, sub_obj);
}
}
else {
if (sub_type.BaseType == typeof(System.Object)) {
if (OkToSet(Obj, fi, Force)) {
try {
sub_obj = Activator.CreateInstance(sub_type);
SetPublicDefaults(sub_obj, Force);
fi.SetValue(Obj, sub_obj);
} catch (Exception) {
}
}
else {
try {
sub_obj = fi.GetValue(Obj);
SetPublicDefaults(sub_obj, Force);
} catch (Exception) {
}
}
}
}
}
}
}