Note that there are some explanatory texts on larger screens.

plurals
  1. POStackOverFlowError in instance of XmlSerializer
    text
    copied!<p>I don't know why I have Stackoverflow error when Child class call parent class constractor?!</p> <p>first of all: sorry for my long code, because some of my friends request for it, so I put it for u!</p> <pre><code>public class XMLCollection&lt;T&gt;: IList&lt;T&gt; where T: new () { private XmlSerializer ser; private List&lt;T&gt; InnerList= new List&lt;T&gt;(); public XMLCollection() { ser = new XmlSerializer(this.GetType(), new XmlRootAttribute(this.GetType().Name )); } /// &lt;summary&gt; /// /// &lt;/summary&gt; /// &lt;param name="path"&gt;path format: @"D:\FolderName"&lt;/param&gt; public void SaveToXML(string path) { try { using (StreamWriter sw = new StreamWriter(path+ "\\"+this.GetType().Name)) { ser.Serialize(sw, this); } } catch (Exception ex) { Console.WriteLine(ex.Message ); } } public void LoadFromXML(string FullPath) { try { if (File.Exists(FullPath)) { using (StreamReader sr= new StreamReader(FullPath)) { this.InnerList=((XMLCollection&lt;T&gt;) ser.Deserialize(sr)).InnerList ; } } else { Console.WriteLine("File not exist...."); } } catch (Exception ex) { Console.WriteLine(ex.Message ); } } #region Ilist public int IndexOf(T item) { throw new NotImplementedException(); } public void Insert(int index, T item) { throw new NotImplementedException(); } public void RemoveAt(int index) { throw new NotImplementedException(); } public T this[int index] { get { return InnerList[index]; } set { InnerList[index] = value; } } public void Add(T item) { InnerList.Add(item); } public void Clear() { InnerList.Clear(); } public bool Contains(T item) { throw new NotImplementedException(); } public void CopyTo(T[] array, int arrayIndex) { throw new NotImplementedException(); } public int Count { get { throw new NotImplementedException(); } } public bool IsReadOnly { get { throw new NotImplementedException(); } } public bool Remove(T item) { throw new NotImplementedException(); } public IEnumerator&lt;T&gt; GetEnumerator() { return InnerList.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return InnerList.GetEnumerator(); } #endregion </code></pre> <p>this is derived class:</p> <pre><code>public class Moshakhase :XMLCollection&lt;Moshakhase&gt;, IDisposable , IComparable&lt;Moshakhase&gt; , IEquatable&lt;Moshakhase&gt; { [XmlAttribute] public int Id { get; set; } [XmlAttribute] public string Name { get; set; } #region ctor public Moshakhase() { } public Moshakhase(int id, string name) { this.Id = id; this.Name = name; } #endregion public override string ToString() { return string.Format("{0}:\tId:{1}\tName:{2}",this.GetType().Name ,this.Id,this.Name); } #region dispose public void Dispose() { GC.SuppressFinalize(this); } #endregion #region IComparable /// &lt;summary&gt; /// براساس نام /// &lt;/summary&gt; /// &lt;param name="other"&gt;&lt;/param&gt; /// &lt;returns&gt;&lt;/returns&gt; public int CompareTo(Moshakhase other) { return this.Name.CompareTo(other.Name); } #endregion #region IEquatable public bool Equals(Moshakhase other) { if (this.Id== other.Id) { return true; } return false; } #endregion </code></pre> <p>}</p> <p>Thanks for your attention.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload