Skip to content

Serializing a "circular dictionary" (a dictionary made circular with overridden indexer) results in index out of range exception. #2

Open

Description

@arminro

1st things 1st, thank you for your work, it is amazing and easy to use! I encountered a problem, however:

I implemented a simple CircularDictionary for a university project of mine:
public class CircularDictionary<TValue> : Dictionary<int, TValue> { public new TValue this[int i] { get { return base[i % this.Count]; } set { base[i] = value; } } }
For some reason, SharpSerializer's serialization always results in an index out of range exception. When I copy/pasted my data from the ciruclar to a normal one, serialization worked perfectly. Strangely though, it has no problem with my likewise simple CircularList: (GetNextElement and WhatIsNext, as you can see, has no contribution to indexing)
` public class CircularList : ObservableCollection
{
int inc;
public CircularList()
{
inc = 0;
}

    public new T this[int i]
    {
        get
        {
            return base[i % this.Count];
        }
        set
        {
            base[i] = value;
        }
    }

    public T GetNextElement(int number = 1)
    {
        return this[inc+=number];
    }

    public T WhatIsNext()
    {
        return this[inc + 1];
    }
}`

Activity

  1. changed the title [-]Serializing a "circular dictionary" (a dictioanry made circular with overridden indexer) results in index out of range exception.[/-] [+]Serializing a "circular dictionary" (a dictionary made circular with overridden indexer) results in index out of range exception.[/+] on Nov 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions