FormCollectionExtend.MVC
1.0.0
MVC FormCollection 到物件擴充庫。
輕鬆將 FormCollection 轉換為物件。
按一下此處查看我們的 UnitTest 範例。
將 FormCollection 轉換為單一物件。
// Arrange
FormCollection Stub = CreateTestData ( ) ;
// Act
TestModel Test = Stub . ToSingleObject < TestModel > ( ) ;
使用映射字典將 FormCollection 轉換為單一物件。
// Arrange
FormCollection Stub = CreateTestDataWithDifferentNaming ( ) ;
Dictionary < string , string > MappingDictionary = CreateMappingDictionary ( ) ;
// Act
TestModel Test = Stub . ToSingleObject < TestModel > ( MappingDictionary ) ;
將 FormCollection 轉換為 List
// Arrange FormCollection Stub = CreateTestDataSet ( ) ; string PrimaryKeyName = "Name" ; // Act List < TestModel > Test = Stub . ToListObject < TestModel > ( PrimaryKeyName ) ;
使用映射字典將 FormCollection 轉換為 List
// Arrange FormCollection Stub = CreateTestDataSetWithDifferentNaming ( ) ; Dictionary < string , string > MappingDictionary = CreateMappingDictionary ( ) ; string PrimaryKeyName = "Name111" ; // Act List < TestModel > Test = Stub . ToListObject < TestModel > ( MappingDictionary , PrimaryKeyName ) ;
例子:
Dictionary < string , string > CreateMappingDictionary ( ) { // Key.Add( "後端物件屬性", "前端表單欄位Name" ); // Key.Add( "Model Object Property", "Form Field Name" ); Dictionary < string , string > Key = new Dictionary < string , string > ( ) ; Key . Add ( "Name" , "Name111" ) ; Key . Add ( "age" , "age222" ) ; Key . Add ( "PhoneNumber" , "PhoneNumber333" ) ; Key . Add ( "Married" , "Married444" ) ; Key . Add ( "CreatedDateTime" , "CreatedDateTime555" ) ; Key . Add ( "ModifyDateTime" , "ModifyDateTime666" ) ; return Key ; }