Windows Phone 7 UserExtendedProperties

后端 未结 1 446
心在旅途
心在旅途 2021-01-14 23:33

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

I tried the following code

相关标签:
1条回答
  • 2021-01-14 23:57

    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 讨论(0)
提交回复
热议问题