1. <small id='NpF5o'></small><noframes id='NpF5o'>

      <bdo id='NpF5o'></bdo><ul id='NpF5o'></ul>

  2. <legend id='NpF5o'><style id='NpF5o'><dir id='NpF5o'><q id='NpF5o'></q></dir></style></legend>
    <tfoot id='NpF5o'></tfoot>

      <i id='NpF5o'><tr id='NpF5o'><dt id='NpF5o'><q id='NpF5o'><span id='NpF5o'><b id='NpF5o'><form id='NpF5o'><ins id='NpF5o'></ins><ul id='NpF5o'></ul><sub id='NpF5o'></sub></form><legend id='NpF5o'></legend><bdo id='NpF5o'><pre id='NpF5o'><center id='NpF5o'></center></pre></bdo></b><th id='NpF5o'></th></span></q></dt></tr></i><div id='NpF5o'><tfoot id='NpF5o'></tfoot><dl id='NpF5o'><fieldset id='NpF5o'></fieldset></dl></div>
    1. 我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?

      Can I define properties in partial classes, then mark them with attributes in another partial class?(我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?)

      <small id='IJPEZ'></small><noframes id='IJPEZ'>

            <tbody id='IJPEZ'></tbody>

            <tfoot id='IJPEZ'></tfoot>
          • <i id='IJPEZ'><tr id='IJPEZ'><dt id='IJPEZ'><q id='IJPEZ'><span id='IJPEZ'><b id='IJPEZ'><form id='IJPEZ'><ins id='IJPEZ'></ins><ul id='IJPEZ'></ul><sub id='IJPEZ'></sub></form><legend id='IJPEZ'></legend><bdo id='IJPEZ'><pre id='IJPEZ'><center id='IJPEZ'></center></pre></bdo></b><th id='IJPEZ'></th></span></q></dt></tr></i><div id='IJPEZ'><tfoot id='IJPEZ'></tfoot><dl id='IJPEZ'><fieldset id='IJPEZ'></fieldset></dl></div>

          • <legend id='IJPEZ'><style id='IJPEZ'><dir id='IJPEZ'><q id='IJPEZ'></q></dir></style></legend>
              • <bdo id='IJPEZ'></bdo><ul id='IJPEZ'></ul>

                本文介绍了我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                有没有办法生成这样的代码文件:

                Is there a way I can have a generated code file like so:

                public partial class A 
                {
                    public string a { get; set; }
                }
                

                然后在另一个文件中:

                public partial class A 
                {
                    [Attribute("etc")]
                    public string a { get; set; }
                }
                

                这样我就可以从数据库中生成一个类,然后使用一个非生成的文件来标记它?

                So that I can have a class generated from the database and then use a non-generated file to mark it up?

                推荐答案

                我在 Scott Guthrie 的一篇文章中看到过类似的事情(接近结尾)——不过,我自己没有尝试过.
                http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

                I've seen something like this done in an article by Scott Guthrie (near the end of it) - didn't try it myself, though.
                http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx

                [MetadataType(typeof(Person_Validation))]
                public partial class Person
                {
                    // Partial class compiled with code produced by VS designer
                }
                
                [Bind(Exclude="ID")]
                public class Person_Validation
                {
                    [Required(ErrorMessage = "First Name Required")]
                    [StringLength(50, ErrorMessage = "Must be under 50 characters")]
                    public string FirstName { get; set; }
                
                    [Required(ErrorMessage = "Last Name Required")]
                    [StringLength(50, ErrorMessage = "Must be under 50 characters")]
                    public string LastName { get; set; }
                
                    [Required(ErrorMessage = "Age Required")]
                    [Range(0, 120, ErrorMessage = "Age must be between 0 and 120")]
                    public int Age { get; set; }
                
                    [Required(ErrorMessage = "Email Required")]
                    [Email(ErrorMessage = "Not a valid email")]
                    public string Email { get; set; }
                }
                

                这篇关于我可以在部分类中定义属性,然后用另一个部分类中的属性标记它们吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Performance overhead of using attributes in .NET(在 .NET 中使用属性的性能开销)
                Accessing attribute info from DTE(从 DTE 访问属性信息)
                c# Hide a property in datagridview with datasource(c#使用数据源隐藏datagridview中的属性)
                Extract Display name and description Attribute from within a HTML helper(从 HTML 帮助器中提取显示名称和描述属性)
                How can I force the PropertyGrid to show a custom dialog for a specific property?(如何强制 PropertyGrid 显示特定属性的自定义对话框?)
                Associate attribute with code generated property in .net(将属性与 .net 中的代码生成属性相关联)

                <small id='H0t2L'></small><noframes id='H0t2L'>

                  <tbody id='H0t2L'></tbody>

                          <bdo id='H0t2L'></bdo><ul id='H0t2L'></ul>

                          <i id='H0t2L'><tr id='H0t2L'><dt id='H0t2L'><q id='H0t2L'><span id='H0t2L'><b id='H0t2L'><form id='H0t2L'><ins id='H0t2L'></ins><ul id='H0t2L'></ul><sub id='H0t2L'></sub></form><legend id='H0t2L'></legend><bdo id='H0t2L'><pre id='H0t2L'><center id='H0t2L'></center></pre></bdo></b><th id='H0t2L'></th></span></q></dt></tr></i><div id='H0t2L'><tfoot id='H0t2L'></tfoot><dl id='H0t2L'><fieldset id='H0t2L'></fieldset></dl></div>
                        • <legend id='H0t2L'><style id='H0t2L'><dir id='H0t2L'><q id='H0t2L'></q></dir></style></legend>
                          <tfoot id='H0t2L'></tfoot>