public CustomConfig(CustomConfig customConfigToCopy) { foreach (var property in customConfigToCopy.GetType().GetProperties()) { var value = property.GetValue(customConfigToCopy); this.GetType().GetProperty(property.Name).SetValue(this, value); } }
public static CustomConfig Load() { CustomConfig obj; if (File.Exists(FILEPATH)) { obj = new CustomConfig(); StreamReader streamReader = new StreamReader(FILEPATH); while (!streamReader.EndOfStream) { var line = streamReader.ReadLine(); if (line.Contains(":")) { var split = line.Split(new char[] { ':' }, 2); var key = split[0]; var value = split[1]; var propInfo = obj.GetType().GetProperty(key); if (propInfo != null) { if (propInfo.PropertyType == typeof(uint)) { propInfo.SetValue(obj, uint.Parse(value)); } else if (propInfo.PropertyType == typeof(float)) { propInfo.SetValue(obj, float.Parse(value)); } else if (propInfo.PropertyType == typeof(bool)) { propInfo.SetValue(obj, bool.Parse(value)); } else if (propInfo.PropertyType == typeof(string)) { propInfo.SetValue(obj, value); } } } } streamReader.Close(); return(obj); } else { return(new CustomConfig()); } }