Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C#

Exploring WinRT's ApplicationDataContainer

5.00/5 (2 votes)
6 Jan 2013CPOL 11.7K  
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)