.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 7th, 2008, 02:19 AM
s70n3d s70n3d is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 130 s70n3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 46 m 23 sec
Reputation Power: 5
Error Durring XML Serialization

I am currently creating a Library class that is completely independant of dictionaries since dictionaries do not xml serialize properly. I have created the class and it works great, except I can not get the XMLSerializer to properly serialize the class.

The exception is: "There was an error reflecting type 'ClassLibrary1.Library`3[System.String,System.String,System.String]'."

and the code is

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ClassLibrary1
{
    public class Program
    {
        static void Main(string[] args)
        {
            Library<string, string, string> Lib = new Library<string, string, string>();
            Lib.Subjects.Add(new LibrarySubject<string,string,string>("Test!"));
            Lib["Test!"].Entries.Add(new LibrarySubjectEntry<string,string>("Rawr!", "RARRR"));
            Console.WriteLine(Lib["Test!"]["Rawr!"]);
            System.IO.FileStream FS = System.IO.File.Create("Test.xml");
            XmlSerializer S = new XmlSerializer(Lib.GetType());
            S.Serialize(FS, Lib);
            FS.Flush();
            FS.Close();
        }
    }
    public class Library<TSubKey, TKey, TVal>
        where TSubKey : IComparable
        where TKey : IComparable
    {
        public Library()
        {
            Subjects = new List<LibrarySubject<TSubKey, TKey, TVal>>();
        }
        [XmlIgnore]
        public LibrarySubject<TSubKey, TKey, TVal> this[TSubKey SubjectKey]
        {
            get
            {
                return Subjects[Subjects.FindIndex((LibrarySubject<TSubKey, TKey, TVal> Subject) => Subject.SubjectKey.CompareTo(SubjectKey) == 0)];
            }
            set
            {
                Subjects[Subjects.FindIndex((LibrarySubject<TSubKey, TKey, TVal> Subject) => Subject.SubjectKey.CompareTo(SubjectKey) == 0)] = value;
            }
        }
        public List<LibrarySubject<TSubKey, TKey, TVal>> Subjects;
    }

    public class LibrarySubject<TSubKey, TKey, TVal>
        where TSubKey : IComparable
        where TKey : IComparable
    {
        public LibrarySubject(TSubKey SubjectKey)
        {
            this.SubjectKey = SubjectKey;
            this.Entries = new List<LibrarySubjectEntry<TKey, TVal>>();
        }
        [XmlIgnore]
        public TVal this[TKey Key]
        {
            get
            {
                return Entries[Entries.FindIndex((LibrarySubjectEntry<TKey, TVal> Entry) => Entry.Key.CompareTo(Key) == 0)].Value;
            }
            set
            {
                Entries[Entries.FindIndex((LibrarySubjectEntry<TKey, TVal> Entry) => Entry.Key.CompareTo(Key) == 0)].Value = value;
            }
        }
        public TSubKey SubjectKey;
        public List<LibrarySubjectEntry<TKey, TVal>> Entries;
    }
    public class LibrarySubjectEntry<TKey, TVal>
        where TKey : IComparable
    {
        public LibrarySubjectEntry(TKey Key, TVal Value)
        {
            this.Key = Key;
            this.Value = Value;
        }
        public TKey Key;
        public TVal Value;
    }
}


Is there any possible way I can get this to serialize using XMLSerializer??

Reply With Quote
  #2  
Old May 7th, 2008, 03:15 PM
s70n3d s70n3d is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 130 s70n3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 h 46 m 23 sec
Reputation Power: 5
I just figured out why! I forgot a few default constructors >.< thank you anyways though

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Error Durring XML Serialization


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT