Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8085591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:10:20+00:00 2026-06-05T18:10:20+00:00

Fairly new to programming. I just can’t wrap my head around how to get

  • 0

Fairly new to programming. I just can’t wrap my head around how to get this to work in reverse. I have a save method and an open method.
Save:

IDictionary<string, IDictionary<string, object>> pluginStates = new Dictionary<string, IDictionary<string, object>>();
signaller.RaiseSaveRequest(pluginStates); <--goes out and gets packed plugins

//loop through plugins to get values and types
//holds all of the plugin arrays
Dictionary<string, object> dictProjectState = new Dictionary<string, object>();

foreach (KeyValuePair<string,IDictionary<string,object>> plugin in pluginStates)
{ 
    //holds jsonRepresented values
    Dictionary<string, object> dictJsonRep = new Dictionary<string, object>(); 
    //holds object types
    Dictionary<string, object> dictObjRep = new Dictionary<string, object>(); 
    object[] arrayDictHolder = new object[2];  //holds all of the dictionaries
    string pluginKey = plugin.Key;
    IDictionary<string, object> pluginValue = new Dictionary<string, object>(); 
    pluginValue = plugin.Value;

    foreach (KeyValuePair<string, object> element in pluginValue)
    {
        string jsonRepresentation = JsonConvert.SerializeObject(element);
        object objType = element.Value.GetType().ToString();
        dictJsonRep.Add(element.Key, jsonRepresentation);
        dictObjRep.Add(element.Key, objType);
    }
    arrayDictHolder[0] = dictJsonRep;
    arrayDictHolder[1] = dictObjRep;
    dictProjectState.Add(pluginKey, arrayDictHolder);
}

JsonSerializer serializer = new JsonSerializer();
using (StreamWriter sw = new StreamWriter(strPathName))
using (JsonWriter writer = new JsonTextWriter(sw))
{
     serializer.Serialize(writer, dictProjectState);
}

So, when someone saves, an event handler goes out and gets the packedState of each plugin, adds it to a dictionary pluginStates. I then go through each plugin in the pluginStates, adding the key, and json string version of the value to 1 dictionary and the key, object type to another dictionary, add those 2 dictionaries to an array and then pack up a dictionary that contains the pluginKey and the array for each plugin. Reasoning: when deserializing, I’m hitting problems going from JArray to type DataTable and other types that are within the dictionary that gets passed back to the plugin to unpack itself upon opening. I’m trying to figure out how to reverse this, so that when user opens project, I have the dictProjectState and need to bring it all the way back through the code to end up with 1 dictionary containing the plugins. How do I mirror this save in the open??
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:10:23+00:00Added an answer on June 5, 2026 at 6:10 pm

    I believe when you deserialize in the open function, you should get an object that can be cast to Dictionary<string, object>.

    The keys of this dictionary would be the names of the plugins in your final dictioary (pluginKey in yoru save method). The values should be the object[] arrayDictHolder objects. You can cast them to object[] and then get at the two values inside (dictJsonRep and dictObjRep in your save function).

    Once those values are both cast to Dictionary<string, object>(), you can iterate through the KeyValuePairs in one of them, and use the key from those pairs to get at the value store in the other dictionary.

    Code would be similar to the following:

    var pluginStates = new Dictionary<string, IDictionary<string, object>>();
    
    var dictProjectState = jsonSerializer.Deserialize(reader) as Dictionary<string, object>;
    
    foreach(var projectStatePair in dictProjectState)
    {
        string pluginKey = projectStatePair.Key;
        var pluginValues = new Dictionary<string, object>();
        object[] arrayDictHolder = projectStatePair.Value as object[];
        var dictJsonRep = arrayDictHolder[0] as Dictionary<string, object>;
        var dictObjRep =  arrayDictHolder[1] as Dictionary<string, object>;
        foreach(var JsonRepPair in dictJsonRep)
        {
            string jsonRepresentation = JsonRepPair.Value;
            // We know both dictionaries have the same keys, so
            // get the objType for this JsonRepresentation
            object objType = dictObjRep[JsonRepPair.Key];
            // Since you're serializing objType to a string, you'll need
            // to get the actual Type before calling DeserializeObject.
            Type jsonType = System.Type.GetType(objType as string);
            object value = JsonConvert.DeserializeObject( jsonRepresentation, jsonType );
            pluginValues.Add( JsonRepPair.Key );
        }
        pluginStates.Add( pluginKey, pluginValues );
    }
    

    Note: You are currently setting objType to element.Value.GetType().ToString(); in your save function. You will either need to update save() to set it to element.Value.GetType(); or convert the type strings back to actual Types before trying to deserialize.

    Note: I am not very familiar with the Json libraries. The above code is focused on creating your pluginStates dictionary out of the deserialized results. You will need to handle the creation of your JsonSerializer and make sure you close any streams after you’ve deserialized them. You may also need to tweak the actual deserialization calls to get the desired results.

    Update: Added conversion of objType to actual System.Type object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just began opengl programming in android and i am fairly new to
I am fairly new to programming and to python and wxpython. I have looked
I'm fairly new to database programming in WinForms, and have been using BindingSource, DataSet,
I'm fairly new to Visual Studio (specifically Visual Basic .NET) but have been programming
I'm fairly new to iOS programming, but have a basic understanding of it. I
I'm fairly new to Python and programming in general. I have done a few
I'm fairly new to programming and have been focussing a great deal on Java
I'm fairly new to Objective-C and iPhone programming so I apologize if this is
I'm fairly new to programming in general but have been working with Java for
Is there any reason I shouldn't do this? I'm fairly new at programming iPhone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.