开发者

Windows Phone 7 UserExtendedProperties

开发者 https://www.devze.com 2023-02-01 12:31 出处:网络
After being directed here: http://msdn.microsoft.com/en-us/library/microsoft.phone.info.userextendedproperties.getvalue%28v=VS.92%29.a开发者_StackOverflowspx

After being directed here: http://msdn.microsoft.com/en-us/library/microsoft.phone.info.userextendedproperties.getvalue%28v=VS.92%29.a开发者_StackOverflowspx

I tried the following code on my sideloaded application. All that was written out was the 000001 value.

I knew that would be the case in the emulator, but I was hoping to get a real value when it was on my phone. Any ideas?

                 int ANIDLength = 32;  
                 int ANIDOffset = 2;

                 string result = string.Empty;  
                 object anid;  
                 if (UserExtendedProperties.TryGetValue("ANID", out anid))  
                 {
                     if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset))
                     {
                         result = anid.ToString().Substring(ANIDOffset, ANIDLength);
                     }
                     else
                     {
                         result = "000001";
                     } 
                 }   


You need to remove 1 from the calculation of your length check to account for the substring operation working on a zero based index:

 if (anid != null && anid.ToString().Length >= (ANIDLength + ANIDOffset - 1))

This works on my machine:

private string GetAnid()
{
    object anidValue;

    int ANIDLength = 32;
    int ANIDOffset = 2;

    if (UserExtendedProperties.TryGetValue("ANID", out anidValue))
    {
        if (anidValue != null && anidValue.ToString().Length >= (ANIDLength + ANIDOffset - 1))
        {
            return anidValue.ToString().Substring(ANIDOffset, ANIDLength);
        }
        else
        {
            return "???";
        }
    }
    else
    {
        return "???";
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消