Why is my Type not being Serialized correctly by the XmlSerializer - xml-serialization

The intial problem was that when I called a webservice ( asmx) methos with a type the type was always going through as null . Inspecting the Soap confirmed that the type was going as an empty element. So I tried a simple test.
Here is my type which of course has been generated from WSDL
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.233")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto12.api.echosign")]
public partial class SendDocumentInteractiveOptions {
private bool authoringRequestedField;
private bool authoringRequestedFieldSpecified;
private bool autoLoginUserField;
private bool autoLoginUserFieldSpecified;
private bool noChromeField;
private bool noChromeFieldSpecified;
/// <remarks/>
public bool authoringRequested {
get {
return this.authoringRequestedField;
}
set {
this.authoringRequestedField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool authoringRequestedSpecified {
get {
return this.authoringRequestedFieldSpecified;
}
set {
this.authoringRequestedFieldSpecified = value;
}
}
/// <remarks/>
public bool autoLoginUser {
get {
return this.autoLoginUserField;
}
set {
this.autoLoginUserField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool autoLoginUserSpecified {
get {
return this.autoLoginUserFieldSpecified;
}
set {
this.autoLoginUserFieldSpecified = value;
}
}
/// <remarks/>
public bool noChrome {
get {
return this.noChromeField;
}
set {
this.noChromeField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool noChromeSpecified {
get {
return this.noChromeFieldSpecified;
}
set {
this.noChromeFieldSpecified = value;
}
}
}
Now here is some simple code to serialize it.
SendDocumentInteractiveOptions sdio = new SendDocumentInteractiveOptions();
sdio.authoringRequested = true;
sdio.autoLoginUser = true;
sdio.noChrome = true;
XmlSerializer xmlSer = new XmlSerializer(typeof(SendDocumentInteractiveOptions));
XmlWriter xw = new XmlTextWriter(#"g:\test.xml", null);
xmlSer.Serialize(xw, sdio);
xw.Close();
And here is the resulting XML
<?xml version="1.0"?&gt
&ltSendDocumentInteractiveOptions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
So what am I missing here. Why are my public properties not getting serialized?

This is kind of an old question, but oh well. I think the solution might be in another question "Why isn't my public property serialized by the XmlSerializer?". Part of the answer lists reasons why an attribute would not be serialized and in that list is
it has a public bool FooSpecified {get;set;} property that returned false
In your code, you set the various Boolean values but set the related specified values. I was facing a similar issue and setting the specified value fixed it for me.

Related

context.GetArgument() returning null with ByteGraphType

I´m learning how to use CustomScalar in graphql-dotnet.
I have a tinyint column in my table and from what I have read, I´m supposed to use byte on this column in C#. After research I found out that I need to create a ByteGraphType, but I´m having trouble doing that.
I got the ByteGraphType example from this link https://github.com/graphql-dotnet/graphql-dotnet/issues/458, so I think it will work.
With this code, I can query the table, however, my mutation is not working. I didn´t find an example to demonstrate how the mutation would look like with a byte column. I tried as is stated in my code example, but in this line (var avaliacao = context.GetArgument("avaliacao");), my argument avaliacao.Nota is returning null and I´m not sure on how to proceed.
Can someone help me?
Thank you
THAT´S MY CODE
//Model
[Column("nota")]
public byte Nota { get; set; }
//Type
Field<ByteGraphType>("Nota", resolve: context => context.Source.Nota);
//InputType
Field<ByteGraphType>("nota");
//Query
Field<ListGraphType<AvaliacaoType>>(
"avaliacoes",
resolve: context => contextServiceLocator.AvaliacaoRepository.All());
//Mutation
Field<AvaliacaoType>(
"createAvaliacao",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<AvaliacaoInputType>> { Name = "avaliacao" }
),
resolve: context =>
{
var schema = new Schema();
schema.RegisterValueConverter(new ByteValueConverter());
var avaliacao = context.GetArgument<Avaliacao>("avaliacao");
avaliacao.Nota.AstFromValue(schema, new ByteGraphType());
return contextServiceLocator.AvaliacaoRepository.Add(avaliacao);
});
//ByteGraphType
using GraphQL.Language.AST;
using GraphQL.Types;
using System;
namespace Api.Helpers
{
public class ByteGraphType : ScalarGraphType
{
public ByteGraphType()
{
Name = "Byte";
}
public override object ParseLiteral(IValue value)
{
var byteVal = value as ByteValue;
return byteVal?.Value;
}
public override object ParseValue(object value)
{
if (value == null)
return null;
try
{
var result = Convert.ToByte(value);
return result;
}
catch (FormatException)
{
return null;
}
}
public override object Serialize(object value)
{
return ParseValue(value).ToString();
}
public class ByteValueConverter : IAstFromValueConverter
{
public bool Matches(object value, IGraphType type)
{
return value is byte;
}
public IValue Convert(object value, IGraphType type)
{
return new ByteValue((byte)value);
}
}
public class ByteValue : ValueNode<byte>
{
public ByteValue(byte value)
{
Value = value;
}
protected override bool Equals(ValueNode<byte> node)
{
return Value == node.Value;
}
}
}
}
What I need is to be able to save a record of a table that has a tinyint column. If I change the type in my code to int, I can mutate, but can´t query.
I changed my CustomScalar and it worked:
using GraphQL.Language.AST;
using GraphQL.Types;
using System;
namespace Api.Helpers
{
public class ByteGraphType : ScalarGraphType
{
public ByteGraphType()
{
Name = "Byte";
Description = "ByteGraphType";
}
/// <inheritdoc />
public override object Serialize(object value)
{
return ParseValue(value).ToString();
}
/// <inheritdoc />
public override object ParseValue(object value)
{
byte result;
if (byte.TryParse(value?.ToString() ?? string.Empty, out result))
{
return result;
}
return null;
}
/// <inheritdoc />
public override object ParseLiteral(IValue value)
{
if (value is StringValue)
{
return ParseValue(((StringValue)value).Value);
}
return null;
}
}
}

Delegate command not executing on property change

I am currently trying to make a slider in ViewA change the font size of text in viewA and viewB. I have everything bound correctly, but the delegate command is not calling the execute method when the font size property is changed. If I manually call this function everything works as expected, so it is likely one line of code that is the problem. The ViewAViewModel is below:
public class ViewAViewModel : BindableBase
{
private Person _CoolChick = new Person();
private int _fontSize = 12;
private IEventAggregator _eventAggregator;
public DelegateCommand UpdateSizeCommand { get; set; }
public Person CoolChick
{
get
{
return _CoolChick;
}
set
{
SetProperty(ref _CoolChick, value);
}
}
public int FontSize
{
get { return _fontSize; }
set {
Console.WriteLine(_fontSize + " => Font Size");
SetProperty(ref _fontSize, value);
//Execute();
}
}
public ViewAViewModel(IEventAggregator eventAggregator)
{
CoolChick.Age = 25;
CoolChick.Name = "Methalous";
_eventAggregator = eventAggregator;
//likely the problem in this code
UpdateSizeCommand = new DelegateCommand(Execute, CanExecute).ObservesProperty(() => FontSize);
}
private void Execute()
{
_eventAggregator.GetEvent<UpdateEvent>().Publish(FontSize);
}
private bool CanExecute()
{
return true;
}
}
Why would it? You're not calling UpdateSizeCommand.Execute in the setter of your Font property. The command will not invoke unless you bind it to a command property or invoke it manually.

How to get actual value and validate of CustomTextbox Text in ViewModel

I have created custom component for displaying text with either Simple or Password mode, intention to develop this control is the Silverlight does not support custom TextMode (like Password or Text).
This is my requirement
In addition to the access rights it will be possible for organizations to specify restricted access to certain fields in the database. The access restriction to these fields will be Update and Redacted, thus meaning if a specific field has true against Update then a user will be able to update the field as well as viewing it, and if the field has true against Redacted then the user will only be able to see a redacted value in the filed (possibly asterisks - * * * * *). It will be possible to set a field to being Update-able and Redacted, thus meaning a user will see the redacted view but still be able to go and update the field with a new value. Such a requirement is mostly used when holding sensitive information against a contact or information which could be used to discriminate against the contact.
I have created custom control for this requirement and it is working perfectly. i am able to set TextMode dynamically but i couldn't able to get the original value in my ViewModel. (I am able to get original value in View but can't in ViewModel)
If i am access the original value in View using following then it is work.
string s = UserName.Text;
but not getting this value in ViewModel it is giving me like **.
Following is the complete code for PasswordTextBox control.
namespace QSys.Library.Controls
{
public partial class PasswordTextBox : TextBox
{
#region Variables
private string text = string.Empty;
private string passwordChar = "*";
private int selectionLength = 0;
#endregion
#region Properties
/// <summary>
/// The text associated with the control.
/// </summary>
public new string Text
{
get { return text; }
set
{
text = value;
DisplayMaskedCharacters();
}
}
/// <summary>
/// Indicates the character to display for password input.
/// </summary>
public string PasswordChar
{
get { return passwordChar; }
set { passwordChar = value; }
}
/// <summary>
/// Indicates the input text mode to display for either text or password.
/// </summary>
public Mode TextMode
{
get { return (Mode)GetValue(TextModeProperty); }
set { SetValue(TextModeProperty, value); }
}
public static readonly DependencyProperty TextModeProperty = DependencyProperty.Register("TextMode", typeof(Mode), typeof(PasswordTextBox), new PropertyMetadata(default(Mode)));
#endregion
#region Constructors
public PasswordTextBox()
{
this.Loaded += new RoutedEventHandler(PasswordTextBox_Loaded);
}
#endregion
#region Event Handlers
void PasswordTextBox_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
if (this.TextMode == Mode.Password)
{
text = base.Text;
this.TextChanged += new TextChangedEventHandler(PasswordTextBox_TextChanged);
this.KeyDown += new KeyEventHandler(PasswordTextBox_KeyDown);
this.SelectionChanged += new RoutedEventHandler(PasswordTextBox_SelectionChanged);
DisplayMaskedCharacters();
}
this.Loaded -= PasswordTextBox_Loaded;
}
void PasswordTextBox_SelectionChanged(object sender, RoutedEventArgs e)
{
selectionLength = this.SelectionLength;
}
public void PasswordTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (base.Text.Length >= text.Length)
text += base.Text.Substring(text.Length);
else
{
int cursorPosition = this.SelectionStart;
selectionLength = (selectionLength > 1) ? selectionLength : 1;
text = text.Remove(cursorPosition, selectionLength);
}
DisplayMaskedCharacters();
selectionLength = 0;
}
public void PasswordTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
int cursorPosition = this.SelectionStart;
// Handle Delete and Backspace Keys Appropriately
if (e.Key == System.Windows.Input.Key.Back && cursorPosition > 0)
{
DeleteAt(cursorPosition);
}
else if (e.Key == System.Windows.Input.Key.Delete)
{
DeleteAt(cursorPosition);
}
else
{
if (selectionLength > 0) text = text.Remove(cursorPosition, selectionLength);
base.Text = text;
this.Select((cursorPosition > text.Length ? text.Length : cursorPosition), 0);
DisplayMaskedCharacters();
}
selectionLength = 0;
}
#endregion
#region Private Methods
private void DisplayMaskedCharacters()
{
int cursorPosition = this.SelectionStart;
// This changes the Text property of the base TextBox class to display all Asterisks in the control
base.Text = new string(passwordChar.ToCharArray()[0], text.Length);
this.Select((cursorPosition > text.Length ? text.Length : cursorPosition), 0);
}
private void DeleteAt(int position)
{
if (text.Length > position)
{
text = text.Remove(position, 1);
base.Text = base.Text.Remove(position, 1);
}
}
#endregion
}
}
LoginView.xaml
<control:PasswordTextBox x:Name="UserName" TabIndex="1" Grid.Row="1" TextMode="Password" Text="{Binding Path=LoginModelValue.UserName, Mode=TwoWay,ValidatesOnNotifyDataErrors=True, ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Width="200" Height="25" Validatevalue:UpdateSourceTriggerHelper.UpdateSourceTrigger="True"/>
LoginViewModel.cs
public class LoginViewModel : INotifyPropertyChanged, IRegionMemberLifetime
{
public LoginModel LoginModelValue
{
get { return _LoginModelValue; }
set
{
_LoginModelValue = value;
OnPropertyChanged("LoginModelValue");
}
}
}
LoginModel.cs
namespace QSys.Model
{
public class LoginModel : INotifyPropertyChanged
{
#region Variables
private string _userName;
private string _password;
#endregion
#region Constructor
public LoginModel()
{
}
#endregion
#region Properties
[CustomValidation(typeof(PasswordTextBox), "IsValidUserName")]
[Required(ErrorMessage = "User Name is required")]
[Display(Name = "UserName")]
[StringLength(50)]
//[RegularExpression(#"^[a-zA-Z\\0-9\\.\\,\\'\s]+$", ErrorMessage = "Please enter right format.")]
public string UserName
{
get { return _userName; }
set
{
_userName = value;
OnPropertyChanged("UserName");
ValidateProperty("UserName", value);
}
}
[Required(ErrorMessage = "Password is required")]
[Display(Name = "Password")]
[StringLength(10)]
public string Password
{
get { return _password; }
set
{
_password = value;
OnPropertyChanged("Password");
ValidateProperty("Password", value);
}
}
#endregion
#region INotifyPropertyChanged
public event PropertyChangedEventHandler PropertyChanged = delegate { };
private void OnPropertyChanged(string propertyName)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region Private Methods
public bool IsValidObject()
{
ICollection<ValidationResult> results = new Collection<ValidationResult>();
return Validator.TryValidateObject(this, new ValidationContext(this, null, null), results, true) && results.Count == 0;
}
public void ValidateProperty(string propertyName, object value)
{
Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName = propertyName });
}
#endregion
}
}
**I am looking for solution since two days without any luck.
Please help me if you have any solution, your comments or suggestion would be highly appreciated.**
Thanks
Imdadhusen
Wouldn't it be easier to build your own UserControl around the regular TextBox and PasswordBox and just switching their visibility when your dependency property TextMode changes? You could then have a single VM for the UserControl with property Value and bind in TwoWay mode both the TextProperty of the TextBox and the Password property of the PasswordBox to it.
I have resolved using following code.
I am missing Mode=TwoWay in LoginView.xaml:
<control:RestrictedBox Type="Text" Value="{Binding Path=UserName,Mode=TwoWay}">
Thanks,
Imdadhusen

Create custom control with nested tag like GridView >> Columns >> Paging

Expert,
I would like to create a custom control with following feature and this is successfully created:
<fv:Album Runat="Server" Id="WeddingAlbum" Width="600" Height="600" SkinColor="SkyBlue" AllowedFileExtensions="jpg|png|jpeg|gif" MessageDelay="6000"
SavePageUrl="saveupload.aspx" RemovePageUrl="removeupload.aspx"
ThumbnailHeight="150" Thumbnailwidth="150" ThumbnailFadeIn="slow" ThumbnailFadeOut="slow" ThumbnailShowDelete="true"
PopupView="true" PopupViewType="All" PopupOverlayShow="true" PopupTransitionIn="elastic" PopupTransitionOut="elastic"
</fv:Album>
but i would like to segregate Album with Thumbnail and Popup tag. it look like
<fv:Album Runat="Server" Id="WeddingAlbum" Width="600" Height="600" SkinColor="SkyBlue" AllowedFileExtensions="jpg|png|jpeg|gif" MessageDelay="6000" SavePageUrl="saveupload.aspx" RemovePageUrl="removeupload.aspx">
<fv:Thumbnail Height="150" width="150" FadeIn="slow" FadeOut="slow" ShowDelete="true" />
<fv:Popup View="true" ViewType="All" OverlayShow="true" TransitionIn="elastic" TransitionOut="elastic"/>
</fv:Album>
can any body tell me how can i achieve the above functionality?
Example:
<asp:GridView ID="productGridView" Runat="server" DataSourceID="productsDataSource"
<FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center"></PagerStyle>
<HeaderStyle ForeColor="White" BackColor="#A55129"></HeaderStyle>
</asp:GridView>
Thanks in advance!
Imdadhusen
Album.cs
namespace Imdadhusen.Controls.Web
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:Album runat=\"server\" />")]
[ToolboxBitmap(typeof(Album), "Album.bmp")]
public class Album : WebControl, IScriptControl
{
#region "Popup Properties"
private Popup _popup = new Popup();
//PersistenceMode.InnerProperty: Specifies that the property persists in
//the ASP.NET server control as a nested tag.
//DesignerSerializationVisibility.Content: Specifies that a visual
//designer serializes the contents of this property instead of the
//property itself.
[DefaultValue("")]
[Category("Custom")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Popup Popup
{
get { return _popup; }
set { _popup = value; }
}
#endregion
#region "Popup Properties"
private Thumbnail _thumbnail = new Thumbnail();
[DefaultValue("")]
[Category("Custom")]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public Thumbnail Thumbnail
{
get { return _thumbnail; }
set { _thumbnail = value; }
}
#endregion
#region "Control Properties"
public string UploadButtonID
{
get { return this.ViewState["UploadButtonID"] == null ? string.Empty : (string)this.ViewState["UploadButtonID"]; }
set { this.ViewState["UploadButtonID"] = value; }
}
/// <summary>
/// Location of the server-side upload script
/// </summary>
public string Action
{
get { return this.ViewState["Action"] == null ? string.Empty : (string)this.ViewState["Action"]; }
set { this.ViewState["Action"] = value; }
}
/// <summary>
/// Additional data to send
/// </summary>
public string ExtraData
{
get { return this.ViewState["ExtraData"] == null ? string.Empty : (string)this.ViewState["ExtraData"]; }
set { this.ViewState["ExtraData"] = value; }
}
/// <summary>
/// Callback to fire before file is uploaded
/// You can return false to cancel upload
/// </summary>
public string OnSubmitFunction
{
get { return this.ViewState["OnSubmitFunction"] == null ? string.Empty : (string)this.ViewState["OnSubmitFunction"]; }
set { this.ViewState["OnSubmitFunction"] = value; }
}
/// <summary>
/// Submit file as soon as it's selected
/// </summary>
public bool AutoSubmit
{
get { return this.ViewState["AutoSubmit"] == null ? true : (bool)this.ViewState["AutoSubmit"]; }
set { this.ViewState["AutoSubmit"] = value; }
}
/// <summary>
/// The type of data that you're expecting back from the server.
/// Html and xml are detected automatically.
/// Only useful when you are using json data as a response.
/// Set to "json" in that case.
/// </summary>
public string ResponseType
{
get { return this.ViewState["ResponseType"] == null ? string.Empty : (string)this.ViewState["ResponseType"]; }
set { this.ViewState["ResponseType"] = value; }
}
// When user selects a file, useful with autoSubmit disabled
public string OnChangeFunction
{
get { return this.ViewState["OnChangeFunction"] == null ? string.Empty : (string)this.ViewState["OnChangeFunction"]; }
set { this.ViewState["OnChangeFunction"] = value; }
}
/// <summary>
/// Fired when file upload is completed
/// WARNING! DO NOT USE "FALSE" STRING AS A RESPONSE!
/// </summary>
public string OnCompleteFunction
{
get { return this.ViewState["OnCompleteFunction"] == null ? string.Empty : (string)this.ViewState["OnCompleteFunction"]; }
set { this.ViewState["OnCompleteFunction"] = value; }
}
#endregion
#region "Page Events"
protected override void OnPreRender(EventArgs e)
{
if (!this.DesignMode)
{
//test for the existence of a ScriptManager
ScriptManager sMgr = ScriptManager.GetCurrent(Page);
if (sMgr == null)
throw new HttpException(
"A ScriptManager control must exist on the page.");
sMgr.RegisterScriptControl(this);
}
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter output)
{
Control btnUpload = this.NamingContainer.FindControl(this.UploadButtonID);
if (btnUpload == null) throw new HttpException("A UploadButtonID must point to an existing control on the page.");
StringBuilder startupscript = new StringBuilder();
startupscript.AppendLine("$().ready(function () {");
startupscript.AppendLine(" $(function () {");
startupscript.AppendFormat(" var btnUpload = $('#{0}');\n", btnUpload.ClientID);
startupscript.AppendLine(" new AjaxUpload(btnUpload, {");
startupscript.AppendFormat(" name: '{0}'", this.UniqueID);
if (!string.IsNullOrEmpty(this.OnChangeFunction))
startupscript.AppendFormat(",\n onChange: {0}", this.OnChangeFunction);
if (this.AutoSubmit)
{
startupscript.AppendFormat(",\n action: '{0}'", this.Action);
if (!string.IsNullOrEmpty(this.ResponseType))
startupscript.AppendFormat(",\n responseType: {0}", this.ResponseType);
if (!string.IsNullOrEmpty(this.OnSubmitFunction))
startupscript.AppendFormat(",\n onSubmit: {0}", this.OnSubmitFunction);
if (!string.IsNullOrEmpty(this.OnCompleteFunction))
startupscript.AppendFormat(",\n onComplete: {0}", this.OnCompleteFunction);
}
else
{
startupscript.Append(",\n autoSubmit: false");
}
startupscript.AppendLine("\n });");
startupscript.AppendLine(" });");
startupscript.AppendLine("});");
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "startupscript", startupscript.ToString(), true);
base.Render(output);
}
#endregion
#region "IScriptControl Members"
IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
{
return new ScriptDescriptor[] { };
}
IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
{
ScriptReference reference = new ScriptReference();
reference.Assembly = "PhotoAlbum";
reference.Name = "Imdadhusen.Controls.Web.Script.ajaxupload.3.5.js";
return new ScriptReference[] { reference };
}
#endregion
}
}
Popup.cs
namespace Imdadhusen.Controls.Web
{
/// <summary>
///ExpandableObjectConverter: Provides a type converter to convert expandable
///objects. It adds support for properties on an object to the methods and
///properties that TypeConverter provides.
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Popup
{
//View="true" ViewType="All" OverlayShow="true" TransitionIn="elastic" TransitionOut="elastic"
public Popup()
{
}
//start View
private bool _view;
[DefaultValue(true)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public bool View
{
get { return _view; }
set { _view = value; }
}
//end View
//start ViewType
private _ViewType _viewtype;
public enum _ViewType
{
All,
Single
}
[DefaultValue(_ViewType.All)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public _ViewType ViewType
{
get { return _viewtype; }
set { _viewtype = value; }
}
//end ViewType
//start ShowOverlay
private bool _overlayshow;
[DefaultValue(true)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public bool ShowOverlay
{
get { return _overlayshow; }
set { _overlayshow = value; }
}
//end ShowOverlay
//start TransitionIn
private _TransitionIn _transitionin;
public enum _TransitionIn
{
Elastic,
Fade,
None
}
[DefaultValue("")]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public _TransitionIn TransitionIn
{
get { return _transitionin; }
set { _transitionin = value; }
}
//end TransitionIn
//start TransitionOut
private _TransitionOut _transitionout;
public enum _TransitionOut
{
Elastic,
Fade,
None
}
[DefaultValue(_TransitionOut.Elastic)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public _TransitionOut TransitionOut
{
get { return _transitionout; }
set { _transitionout = value; }
}
//end TransitionOut
}
}
Thumbnail.cs
namespace Imdadhusen.Controls.Web
{
/// <summary>
///ExpandableObjectConverter: Provides a type converter to convert expandable
///objects. It adds support for properties on an object to the methods and
///properties that TypeConverter provides.
/// </summary>
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Thumbnail
{
//<fv:Thumbnail Height="150" width="150" FadeIn="slow" FadeOut="slow" ShowDelete="true" />
public Thumbnail()
{
}
//start Height
private int _height;
[DefaultValue(150)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public int Height
{
get { return _height; }
set { _height = value; }
}
//end Height
//start Width
private int _width;
[DefaultValue(150)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public int Width
{
get { return _width; }
set { _width = value; }
}
//end Width
//start FadeIn
private _FadeIn _fadein;
public enum _FadeIn
{
Slow,
Medium,
Fast
}
[DefaultValue(_FadeIn.Medium)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public _FadeIn FadeIn
{
get { return _fadein; }
set { _fadein = value; }
}
//end FadeIn
//start FadeOut
private _FadeOut _fadeout;
public enum _FadeOut
{
Slow,
Medium,
Fast
}
[DefaultValue(_FadeOut.Medium)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public _FadeOut FadeOut
{
get { return _fadeout; }
set { _fadeout = value; }
}
//end FadeOut
//start ShowDelete
private bool _showdelete;
[DefaultValue(true)]
[NotifyParentProperty(true)]
[RefreshProperties(RefreshProperties.Repaint)]
public bool ShowDelete
{
get { return _showdelete; }
set { _showdelete = value; }
}
//end View
}
}
Index.cshtml

XML Help to C#, Please convert this to c#

<data1>
<ClosedDates>
<ClosedDate>2011-01-09</ClosedDate>
<ClosedDate>2011-01-10</ClosedDate>
<ClosedDate>2011-01-16</ClosedDate>
</ClosedDates>
</data1>
Guys, please help me to convert this XML in to C# class.
If you run the xsd.exe utility (docs here) twice on your data file, you'll get:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4952
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.Xml.Serialization;
//
// This source code was auto-generated by xsd, Version=2.0.50727.3038.
//
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
public partial class data1 {
private data1ClosedDates[] itemsField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ClosedDates", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public data1ClosedDates[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class data1ClosedDates {
private data1ClosedDatesClosedDate[] closedDateField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ClosedDate", Form=System.Xml.Schema.XmlSchemaForm.Unqualified, IsNullable=true)]
public data1ClosedDatesClosedDate[] ClosedDate {
get {
return this.closedDateField;
}
set {
this.closedDateField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class data1ClosedDatesClosedDate {
private string valueField;
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
public string Value {
get {
return this.valueField;
}
set {
this.valueField = value;
}
}
}
The xsd.exe utility is part of the Microsoft Windows SDK currently at v7.1 which you can download for free from here: http://msdn.microsoft.com/en-us/windows/bb980924
Now with this class in hand, you should be able to write something like:
XmlSerializer ser = new XmlSerializer(typeof(data1));
var result = ser.Deserialize(#"C:\test.xml");
Have a look at XmlSerializer.Deserialize Method (hope will help you)