/// <summary> /// This method will be used when deserializing the property from an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="propertyValue">The XML node to read the property value from.</param> /// <returns>The value to be assigned to the template property.</returns> public object ReadPropertyXml(PropertySerializerContext context, System.Xml.XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(ModalEditorProperty)) { return(null); } // use XPath to select out values XPathNavigator navigator = propertyValue.CreateNavigator(); // we need to import the CodeSmith Namespace XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // expresion to select SampleBoolean value XPathExpression sampleBooleanExpression = XPathExpression.Compile("string(cs:SampleBoolean/text())", manager); string boolString = navigator.Evaluate(sampleBooleanExpression) as string; bool sampleBoolean; bool.TryParse(boolString, out sampleBoolean); // expresion to select SampleString value XPathExpression sampleTextExpression = XPathExpression.Compile("string(cs:SampleString/text())", manager); string sampleString = navigator.Evaluate(sampleTextExpression) as string; ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); modalEditorPropertyValue.SampleBoolean = sampleBoolean; modalEditorPropertyValue.SampleString = sampleString; return(modalEditorPropertyValue); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { if (_modalEditorPropertyEditorForm == null) { _modalEditorPropertyEditorForm = new ModalEditorPropertyEditorForm(); } _modalEditorPropertyEditorForm.Start(editorService, value); editorService.ShowDialog(_modalEditorPropertyEditorForm); if (_modalEditorPropertyEditorForm.DialogResult == DialogResult.OK) { value = new ModalEditorProperty(_modalEditorPropertyEditorForm.SampleStringTextBox.Text, _modalEditorPropertyEditorForm.SampleBooleanCheckBox.Checked); } else { value = null; } } } return(value); }
/// <summary> /// This method will be used when serializing the property value to an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="writer">The XML writer that the property value will be written to.</param> /// <param name="propertyValue">The property to be serialized.</param> public void WritePropertyXml(PropertySerializerContext context, System.Xml.XmlWriter writer, object propertyValue) { if (propertyValue == null) { return; } ModalEditorProperty modalEditorPropertyValue = propertyValue as ModalEditorProperty; if (modalEditorPropertyValue != null) { writer.WriteElementString("SampleBoolean", modalEditorPropertyValue.SampleBoolean.ToString()); writer.WriteElementString("SampleString", modalEditorPropertyValue.SampleString); } }
/// <summary> /// This method will be used to parse a default value for a property when a template is being instantiated. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="defaultValue">The default value.</param> /// <returns>An object that will be assigned to the template property.</returns> public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { if (context.PropertyInfo.PropertyType == typeof(ModalEditorProperty)) { ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); string[] values = defaultValue.Split(','); if (values.Length == 2) { modalEditorPropertyValue.SampleString = values[0]; modalEditorPropertyValue.SampleBoolean = Boolean.Parse(values[1]); return modalEditorPropertyValue; } return null; } return null; }
/// <summary> /// This method will be used to parse a default value for a property when a template is being instantiated. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="defaultValue">The default value.</param> /// <returns>An object that will be assigned to the template property.</returns> public object ParseDefaultValue(PropertySerializerContext context, string defaultValue) { if (context.PropertyInfo.PropertyType == typeof(ModalEditorProperty)) { ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); string[] values = defaultValue.Split(','); if (values.Length == 2) { modalEditorPropertyValue.SampleString = values[0]; modalEditorPropertyValue.SampleBoolean = Boolean.Parse(values[1]); return(modalEditorPropertyValue); } return(null); } return(null); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider != null) { editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (editorService != null) { if (_modalEditorPropertyEditorForm == null) _modalEditorPropertyEditorForm = new ModalEditorPropertyEditorForm(); _modalEditorPropertyEditorForm.Start(editorService, value); editorService.ShowDialog(_modalEditorPropertyEditorForm); if (_modalEditorPropertyEditorForm.DialogResult == DialogResult.OK) { value = new ModalEditorProperty(_modalEditorPropertyEditorForm.SampleStringTextBox.Text, _modalEditorPropertyEditorForm.SampleBooleanCheckBox.Checked); } else { value = null; } } } return value; }
/// <summary> /// This method will be used when deserializing the property from an XML property set. /// </summary> /// <param name="context">Information about the target property.</param> /// <param name="propertyValue">The XML node to read the property value from.</param> /// <returns>The value to be assigned to the template property.</returns> public object ReadPropertyXml(PropertySerializerContext context, System.Xml.XmlNode propertyValue) { if (context.PropertyInfo.PropertyType != typeof(ModalEditorProperty)) return null; // use XPath to select out values XPathNavigator navigator = propertyValue.CreateNavigator(); // we need to import the CodeSmith Namespace XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable); manager.AddNamespace("cs", CodeSmithProject.DefaultNamespace); // expresion to select SampleBoolean value XPathExpression sampleBooleanExpression = XPathExpression.Compile("string(cs:SampleBoolean/text())", manager); string boolString = navigator.Evaluate(sampleBooleanExpression) as string; bool sampleBoolean; bool.TryParse(boolString, out sampleBoolean); // expresion to select SampleString value XPathExpression sampleTextExpression = XPathExpression.Compile("string(cs:SampleString/text())", manager); string sampleString = navigator.Evaluate(sampleTextExpression) as string; ModalEditorProperty modalEditorPropertyValue = new ModalEditorProperty(); modalEditorPropertyValue.SampleBoolean = sampleBoolean; modalEditorPropertyValue.SampleString = sampleString; return modalEditorPropertyValue; }