0

我有一个使用 EF 模型的 RIA Services Silverlight 3.0 应用程序。在模型元数据中,我包含了几个显示名称属性,当在客户端(在文本框等中)引用模型时,我想使用这些属性。

我现在使用反射来获取客户端上模型的属性,这样如果模型随时间发生变化,我就不需要更新客户端代码。我只是不知道如何访问元数据。

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

提前致谢,

4

1 回答 1

1

您应该能够使用GetCustomAttributes并将 DisplayNameAttribute 作为类型传递来执行此操作。

于 2009-11-16T18:59:06.570 回答