2017-02-19 11 views
0

私のASP.NETアプリケーションでは、注釈付きのさまざまなViewModelがあります。 XAMARINアプリケーションでこれらのViewModelを使用したいと思います。 注釈は、XAMARINアプリケーションで使用するためのものではありません。 注釈の有無にかかわらずViewModelsは同じViewModels ではありませんが、フィールドは同じです。しかし、コードを最大限に共有するにはどうすればよいですか?ASP.NET MVCとXAMARINで同じViewModelを使用する方法

基本的に、すべてのビューには独自のViewModelが必要です。 しかし、この場合、Web、Android、iOSでViewModelを複数回使用することが魅力的です。 (提示フィールドはすべてplattformsに等しい場合。)

using System.ComponentModel.DataAnnotations; 
namespace ... { 
    public class Review : Atom 
    { 
     /// <summary> 
     ///  Name 
     /// </summary> 
     [Required] 
     [Display(Name = "Name")] 
     [StringLength(40, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 3)] 
     [DataType(DataType.Text)] 
     public string Autor { get; set; } 
    } 
} 

戦車!

答えて

0

あなたが使用することを試みることができるconditional compilation

using System.ComponentModel.DataAnnotations; 
namespace ... { 
    public class Review : Atom 
    { 
     /// <summary> 
     ///  Name 
     /// </summary> 
#if __MOBILE__ 
     // Xamarin iOS or Android-specific code 
     [Required] 
     [Display(Name = "Name")] 
     [StringLength(40, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 3)] 
     [DataType(DataType.Text)] 
#endif 
     public string Autor { get; set; } 
    } 
} 
関連する問題