private object LoadPropertyValue(Type settingObjectType, object settingID, string propertyName, Type expectedValueType) { var key = PropertyNameToKey(settingObjectType, settingID, propertyName); object storedValue = null; // Check if stored value is null var nullCheckValue = NSUserDefaults.StandardUserDefaults.ValueForKey(new NSString(key)); if (nullCheckValue == null || nullCheckValue.ToString() == NullValueString) { return(null); } switch (GetStorageClass(expectedValueType)) { case StorageClass.String: storedValue = NSUserDefaults.StandardUserDefaults.StringForKey(key); break; case StorageClass.Integer: storedValue = (int)(NSUserDefaults.StandardUserDefaults.IntForKey(key)); break; case StorageClass.Bool: storedValue = NSUserDefaults.StandardUserDefaults.BoolForKey(key); break; case StorageClass.Float: storedValue = NSUserDefaults.StandardUserDefaults.FloatForKey(key); break; case StorageClass.Double: storedValue = NSUserDefaults.StandardUserDefaults.DoubleForKey(key); break; case StorageClass.DateTime: storedValue = Tools.Parser.Parse <DateTime?>(NSUserDefaults.StandardUserDefaults.StringForKey(key)); break; case StorageClass.Enum: storedValue = Enum.Parse(expectedValueType, NSUserDefaults.StandardUserDefaults.StringForKey(key)); break; case StorageClass.XMLSerialized: storedValue = XmlProvider.ReadFromString(expectedValueType, NSUserDefaults.StandardUserDefaults.StringForKey(key)); break; default: throw new Exception("Internal Error F1C3E9A8-BAD2-48AF-9533-E78DE234B353"); } return(Tools.Object.ChangeType(storedValue, expectedValueType)); }
private object LoadPropertyValue(string propertyName, Type expectedValueType) { var key = PropertyNameToKey(propertyName); object storedValue = null; switch (GetStorageClass(expectedValueType)) { case StorageClass.String: storedValue = NSUserDefaults.StandardUserDefaults.StringForKey(key); break; case StorageClass.Integer: storedValue = NSUserDefaults.StandardUserDefaults.IntForKey(key); break; case StorageClass.Bool: storedValue = NSUserDefaults.StandardUserDefaults.BoolForKey(key); break; case StorageClass.Float: storedValue = NSUserDefaults.StandardUserDefaults.FloatForKey(key); break; case StorageClass.Double: storedValue = NSUserDefaults.StandardUserDefaults.DoubleForKey(key); break; case StorageClass.XMLSerialized: storedValue = XmlProvider.ReadFromString(expectedValueType, NSUserDefaults.StandardUserDefaults.StringForKey(key)); break; default: throw new Exception("Internal Error F1C3E9A8-BAD2-48AF-9533-E78DE234B353"); } object result; if (storedValue.GetType() != expectedValueType) { var converter = TypeDescriptor.GetConverter(expectedValueType); result = converter.ConvertFrom(storedValue); } else { result = storedValue; } return(result); }
static ExplorerBarInfo() { //if (Tools.DesignModeTool.IsDesignMode) { // XmlSerializer xmlSerializer = new XmlSerializer(typeof(ExplorerBarInfoSurrogate)); // var surrogate = (ExplorerBarInfoSurrogate)xmlSerializer.Deserialize(new System.IO.StringReader(Resources.LunaExplorerBarTheme)); // _default = surrogate.Save(); //} else { // _default = // XmlProvider // .ReadFromString<ExplorerBarInfoSurrogate>(Resources.LunaExplorerBarTheme) // .Save(); //} _default = XmlProvider .ReadFromString <ExplorerBarInfoSurrogate>(Resources.LunaExplorerBarTheme) .Save(); }
private void _deserializeButton_Click(object sender, EventArgs e) { try { var componentRegistry = CreateComponentRegistry(); var serialized = XmlProvider.WriteToString(componentRegistry); var deserialized = XmlProvider.ReadFromString <ComponentRegistryDefinition>(serialized); _outputTextBox.Clear(); var reserialized = XmlProvider.WriteToString(deserialized); if (reserialized != serialized) { _outputTextBox.AppendText("Deserialization did not match - " + Environment.NewLine); _outputTextBox.AppendText(reserialized); } else { _outputTextBox.AppendText("Passed"); } } catch (Exception error) { _outputTextBox.Clear(); _outputTextLogger.LogException(error); } }
public void SelectArtificialKeysFile() { var dialog = new OpenFileDialog(); if (dialog.ShowDialog(this) == DialogResult.OK) { if (string.IsNullOrEmpty(dialog.FileName)) { return; } try { var fileContents = File.ReadAllText(dialog.FileName); var artificialKeys = XmlProvider.ReadFromString <ArtificialKeys>(fileContents); // valid file ArtificialKeysFile = dialog.FileName; this._artificialKeysMenuItem.Text = "Remove Artificial Keys"; } catch (Exception error) { var summaryError = new SoftwareException(error, "The selected file '{0}' is not a valid Artificial Keys file.".FormatWith(dialog.FileName)); ExceptionDialog.Show(this, "Invalid Artificial Keys", summaryError); ArtificialKeysFile = null; } } }
private void _testButton_Click(object sender, EventArgs e) { try { var artificialKeys = #region Create test object new ArtificialKeys { Tables = new[] { new ArtificialKeys.Table() { Name = "Table1", PrimaryKey = new ArtificialKeys.PrimaryKey { Name = "PK1", AutoIncrement = true, Columns = new [] { new ArtificialKeys.Column { Name = "ID" } } }, ForeignKeys = new[] { new ArtificialKeys.ForeignKey { Name = "PK1", ReferenceTable = "Table2", Columns = new [] { new ArtificialKeys.Column { Name = "ID" } } } }, UniqueConstraints = new[] { new ArtificialKeys.UniqueConstraint { Name = "UC1", Columns = new [] { new ArtificialKeys.Column { Name = "X" }, new ArtificialKeys.Column { Name = "Y" }, } } }, }, new ArtificialKeys.Table() { Name = "Table2", PrimaryKey = new ArtificialKeys.PrimaryKey { Name = "PK1", Sequence = "Sequence1", Columns = new [] { new ArtificialKeys.Column { Name = "A" }, new ArtificialKeys.Column { Name = "B" }, new ArtificialKeys.Column { Name = "C" } } } } } }; #endregion var serialized = XmlProvider.WriteToString(artificialKeys); var deserialized = XmlProvider.ReadFromString <ArtificialKeys>(serialized); textBox1.Clear(); textBox1.AppendText(serialized); var reserialized = XmlProvider.WriteToString(deserialized); if (reserialized != serialized) { textBox1.AppendText("Deserialization did not match - " + Environment.NewLine); textBox1.AppendText(reserialized); } } catch (Exception error) { textBox1.Clear(); textBox1.AppendText(error.ToDiagnosticString()); } }
public static ArtificialKeys LoadFromString(string xml) { return(XmlProvider.ReadFromString <ArtificialKeys>(xml)); }
public DBSchema ApplyArtificialKeys(string artificialKeysXML) { return(ApplyArtificialKeys(XmlProvider.ReadFromString <ArtificialKeys>(artificialKeysXML))); }