65.9K
CodeProject is changing. Read more.
Home

Exploring WinRT's ApplicationDataContainer

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Jan 5, 2013

CPOL
viewsIcon

11710

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

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);
            }
        }
    }
}