private static void LoadInstance(object instance, StreamReader streamReader) { while (true) { string text = streamReader.ReadLine(); if (text == null) { break; } string[] array = text.Split('='); if (array.Length == 2) { string nameString = array[0].Trim(); string valueString = array[1].Trim(); InstanceIO.LoadValue(instance, nameString, valueString); } } }
private static void LoadValue(object instance, string nameString, string valueString) { int num = nameString.IndexOf('('); if (num != -1 && num < nameString.IndexOf('.')) { string text = nameString.Substring(0, num).Trim(); int num2 = nameString.IndexOf(')'); if (num2 == -1) { InstanceIO.ThrowStreamError(); } string text2 = nameString.Substring(num + 1, num2 - num - 1).Trim(); if (text2 == string.Empty) { InstanceIO.ThrowStreamError(); } if (nameString.Substring(num2 + 1, 1) != ".") { InstanceIO.ThrowStreamError(); } string nameString2 = nameString.Substring(num2 + 2).Trim(); object obj; if (text != string.Empty) { PropertyInfo property = instance.GetType().GetProperty(text); obj = property.GetValue(instance, null); } else { obj = instance; } if (!(obj is IList)) { InstanceIO.ThrowStreamError(); } IList list = obj as IList; obj = list[int.Parse(text2)]; InstanceIO.LoadValue(obj, nameString2, valueString); } else { int num3 = nameString.IndexOf('.'); if (num3 != -1) { string text3 = nameString.Substring(0, num3).Trim(); string nameString2 = nameString.Substring(num3 + 1).Trim(); if (text3 != null && nameString2 != null && !(text3 == string.Empty) && !(nameString2 == string.Empty)) { PropertyInfo property = instance.GetType().GetProperty(text3); InstanceIO.LoadValue(property.GetValue(instance, null), nameString2, valueString); } } else if (nameString != string.Empty) { PropertyInfo property = instance.GetType().GetProperty(nameString); if (!(property == (PropertyInfo)null)) { object obj = property.GetValue(instance, null); if (obj is IList) { InstanceIO.LoadValue(property.GetValue(instance, null), "", valueString); } else if (property.CanWrite) { obj.GetType(); TypeConverter converter = TypeDescriptor.GetConverter(property.PropertyType); valueString = valueString.Replace("#13", "\r"); valueString = valueString.Replace("#10", "\n"); property.SetValue(instance, converter.ConvertFromString(valueString), null); } } } else if (instance is IList) { IList list = instance as IList; if (valueString.ToUpper() == "LoadingBegin".ToUpper()) { list.Clear(); } else if (!(valueString.ToUpper() == "LoadingEnd".ToUpper()) && valueString.StartsWith("new")) { string text4 = valueString.Substring(4).Trim(); Type.GetType(text4); Assembly assembly = instance.GetType().Assembly; object obj2 = assembly.CreateInstance(text4); if (obj2 == null) { throw new Exception("Failed to create a new (" + text4 + ")."); } list.Add(obj2); } } } }