Magic number in the CustomerImageConverter class in Silverlight Patterns in Action.csproj

 
M S
50   50
Sep 01, 2010
 
What is the 91 in the following code?

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    string size = (string)parameter;
            
    int id = int.Parse(value.ToString());

    
    if (id > 91) 
        id = 0; // New customers are getting the default silhouette icon.





    
    var uri = new Uri(HtmlPage.Document.DocumentUri, "Assets/Images/Customers/" + size + "/" + id + ".jpg");
    return new BitmapImage(uri);
}

 



800   99.9
Sep 01, 2010
Indeed a magic number :-).  The default database holds 91 customer records which is where the number comes from.
The Silverlight Patterns application supports adding a new customer, but not uploading images. So, this check ensures a default silhouette image for each new customer.

Of course, a production type application would include the option to upload customer images and then the "if (id > 91)" condition would be removed. 

Hope this helps.