locked
GetType(Code) failing when retrieving LocalSettings

    Question

  • I am having problems retrieving items from from the local data store.  I insert using this:

    ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
    auto values = localSettings->Values;
    int boolValue = lua_toboolean( L, 2 );
    values->Insert( key, dynamic_cast<PropertyValue^>( PropertyValue::CreateBoolean( boolValue != 0 ) ) );

    I try to retrieve like this:

    ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
    auto values = localSettings->Values;
    IPropertyValue^ prop = dynamic_cast<IPropertyValue^>( localSettings->Values->Lookup( key ) );
    Type^ type = prop->GetType();
    TypeCode tc = Type::GetTypeCode( type );
    
    switch ( tc ) {
    

    However tc is always Object and not TypeCode::Boolean like I expect.  I realize I can cast it to Boolean or whatever and probably get it to work, but this is test code and the real code is only asked to retrieve a key and has no idea the type stored there so I must figure it out at read time. 

    Can someone tell me what I am missing here?

    Regards, Guy

    Monday, April 9, 2012 6:44 PM

Answers

  • Hello,

    You can try to use IPropertyValue::Type property to get the type, please follow these codes.

    	ApplicationDataContainer^ localSettings = ApplicationData::Current->LocalSettings;
    	auto values = localSettings->Values;
    	IPropertyValue^ prop = dynamic_cast<IPropertyValue^>( localSettings->Values->Lookup( key ) );
    	PropertyType type=prop->Type;
    
    	switch(type)
    	{
    	case  Windows::Foundation::PropertyType::Boolean:
    		// your codes
    		break;
    	}

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by gnichola Tuesday, April 10, 2012 5:48 AM
    Tuesday, April 10, 2012 3:17 AM