Click here to Skip to main content
15,887,485 members
Articles / Programming Languages / C#
Tip/Trick

Exploring WinRT's ApplicationDataContainer

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
6 Jan 2013CPOL 11.6K   1   1
Ever wondered what's inside your ApplicationDataContainer?

Introduction

Have you ever wondered what values are inside your ApplicationDataContainerExtensions?

This extension method will print it out for you like this:

Root
   + Values
      TotalCorrectQuestions = 67
      PreviousGameMode = ArcadeSession
      CampaignDifficulty = Easy
      UserGuid = 2af8a846-1560-4697-87eb-358e6eafb4f6
      TotalQuestions = 82
      LastUsedLanguage = Français
   + Containers
      AzureSessions
         + Values
            demo = demo
            demo_nl = 5
      English
         + Containers
            TenseProfiles
               + Values
                  PastParticiple = False
                  SimplePast = True
            VerbProfiles
               + Values
                  to send = False
                  to take = False

Code use

<yourcontainer>.PrintToDebug();

Code

C#
public static class ApplicationDataContainerExtensions
{
    public static void PrintToDebug(this ApplicationDataContainer adc)
    {
        PrintToDebug(0, adc);
    }

    private static void PrintToDebug(int padding, ApplicationDataContainer adc)
    {
        Debug.WriteLine(new string(' ', padding) + (string.IsNullOrEmpty(adc.Name) ? "Root" : adc.Name));

        if (adc.Values.Count > 1)
        {
            Debug.WriteLine(new string(' ', padding + 3) + "+ Values");
            foreach (var item in adc.Values)
            {
                Debug.WriteLine(new string(' ', padding + 6) + item.Key + " = " + item.Value);
            }
        }

        if (adc.Containers.Count > 0)
        {
            Debug.WriteLine(new string(' ', padding + 3) + "+ Containers");
            foreach (var item in adc.Containers)
            {
                PrintToDebug(padding + 6, item.Value);
            }
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 5 Pin
Joezer BH5-Jan-13 21:31
professionalJoezer BH5-Jan-13 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.