views:

342

answers:

1

I have an RIA Services Silverlight 3.0 app using an EF model. In the model metadata I've included several Display Name properties that I'd like to use when referring to the model on the client-side (in TextBoxes, etc.. .)

I'm using reflection now to get the properties of the model on the client so that if the model changes over time, I don't need to update the client code. I just can't figure out how to access the metadata.

private void Field_Loaded(object sender, RoutedEventArgs e)
{
    System.Reflection.MemberInfo[] members = this.ModelType.GetMembers(); 
    foreach (System.Reflection.MemberInfo member in members)
    {
     System.Reflection.PropertyInfo property = member as System.Reflection.PropertyInfo;
     if (property != null && property.PropertyType == typeof(System.String))
     {
      ComboBoxItem item = new ComboBoxItem();
      item.Content = property.Name; // <--- This is where I want to use Display Name
      this._field.Items.Add(item);
     }
    }
}

Thanks in advance,

+1  A: 

You should be able to do this using GetCustomAttributes and passing the DisplayNameAttribute as the type.

Bryant
Thanks Bryant but I can't find System.ComponentModel.DisplayNameAttribute in the Silverlight assembly. It shows up in the space on the server but not the client. Do I need to reference something special to get it in Silverlight?
Nick Gotch
I think it is actually call DisplayAttribute, not DisplayNameAttribute.
Bryant
It's weird, I found DescriptionAttribute and that's working fine but nothing starting with 'Display' shows up in Intellisense.
Nick Gotch
Found it; it's in System.ComponentModel.DataAnnotations.DisplayAttribute . Thanks!!
Nick Gotch