@@ -658,6 +658,46 @@ public void Test_ObservableProperty_InheritedModelWithCommandUsingInheritedObser
658
658
Assert . IsTrue ( model . SaveCommand . CanExecute ( null ) ) ;
659
659
}
660
660
661
+ [ TestMethod ]
662
+ public void Test_ObservableProperty_ForwardsSpecialCasesDataAnnotationAttributes ( )
663
+ {
664
+ PropertyInfo propertyInfo = typeof ( ModelWithAdditionalDataAnnotationAttributes ) . GetProperty ( nameof ( ModelWithAdditionalDataAnnotationAttributes . Name ) ) ! ;
665
+
666
+ DisplayAttribute ? displayAttribute = ( DisplayAttribute ? ) propertyInfo . GetCustomAttribute ( typeof ( DisplayAttribute ) ) ;
667
+
668
+ Assert . IsNotNull ( displayAttribute ) ;
669
+ Assert . AreEqual ( displayAttribute ! . Name , "MyProperty" ) ;
670
+ Assert . AreEqual ( displayAttribute . ResourceType , typeof ( List < double > ) ) ;
671
+ Assert . AreEqual ( displayAttribute . Prompt , "Foo bar baz" ) ;
672
+
673
+ KeyAttribute ? keyAttribute = ( KeyAttribute ? ) propertyInfo . GetCustomAttribute ( typeof ( KeyAttribute ) ) ;
674
+
675
+ Assert . IsNotNull ( keyAttribute ) ;
676
+
677
+ EditableAttribute ? editableAttribute = ( EditableAttribute ? ) propertyInfo . GetCustomAttribute ( typeof ( EditableAttribute ) ) ;
678
+
679
+ Assert . IsNotNull ( keyAttribute ) ;
680
+ Assert . IsTrue ( editableAttribute ! . AllowEdit ) ;
681
+
682
+ UIHintAttribute ? uiHintAttribute = ( UIHintAttribute ? ) propertyInfo . GetCustomAttribute ( typeof ( UIHintAttribute ) ) ;
683
+
684
+ Assert . IsNotNull ( uiHintAttribute ) ;
685
+ Assert . AreEqual ( uiHintAttribute ! . UIHint , "MyControl" ) ;
686
+ Assert . AreEqual ( uiHintAttribute . PresentationLayer , "WPF" ) ;
687
+ Assert . AreEqual ( uiHintAttribute . ControlParameters . Count , 3 ) ;
688
+ Assert . IsTrue ( uiHintAttribute . ControlParameters . ContainsKey ( "Foo" ) ) ;
689
+ Assert . IsTrue ( uiHintAttribute . ControlParameters . ContainsKey ( "Bar" ) ) ;
690
+ Assert . IsTrue ( uiHintAttribute . ControlParameters . ContainsKey ( "Baz" ) ) ;
691
+ Assert . AreEqual ( uiHintAttribute . ControlParameters [ "Foo" ] , 42 ) ;
692
+ Assert . AreEqual ( uiHintAttribute . ControlParameters [ "Bar" ] , 3.14 ) ;
693
+ Assert . AreEqual ( uiHintAttribute . ControlParameters [ "Baz" ] , "Hello" ) ;
694
+
695
+ ScaffoldColumnAttribute ? scaffoldColumnAttribute = ( ScaffoldColumnAttribute ? ) propertyInfo . GetCustomAttribute ( typeof ( ScaffoldColumnAttribute ) ) ;
696
+
697
+ Assert . IsNotNull ( scaffoldColumnAttribute ) ;
698
+ Assert . IsTrue ( scaffoldColumnAttribute ! . Scaffold ) ;
699
+ }
700
+
661
701
public abstract partial class BaseViewModel : ObservableObject
662
702
{
663
703
public string ? Content { get ; set ; }
@@ -1066,4 +1106,15 @@ public override void Save()
1066
1106
{
1067
1107
}
1068
1108
}
1109
+
1110
+ public partial class ModelWithAdditionalDataAnnotationAttributes : ObservableValidator
1111
+ {
1112
+ [ ObservableProperty ]
1113
+ [ Display ( Name = "MyProperty" , ResourceType = typeof ( List < double > ) , Prompt = "Foo bar baz" ) ]
1114
+ [ Key ]
1115
+ [ Editable ( true ) ]
1116
+ [ UIHint ( "MyControl" , "WPF" , new object [ ] { "Foo" , 42 , "Bar" , 3.14 , "Baz" , "Hello" } ) ]
1117
+ [ ScaffoldColumn ( true ) ]
1118
+ private string ? name ;
1119
+ }
1069
1120
}
0 commit comments