Back to list
Views:   6.9K
Replies:  1

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

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

M S, Sep 01, 2010
Reply 1
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.
Dan McMillan, Sep 01, 2010
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.