部分方法实现 [英] partial method implementation

查看:80
本文介绍了部分方法实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MVC4互联网应用程序,其模型使用部分类和部分方法。代码如下:

I have a MVC4 internet application, whose Model is using a partial class as well as a partial method. the code is as follows:

namespace ePhoneBookMvc4Application.Models
{
    public partial class PhoneBook : ePhoneBookMvc4Application.Repositories.PhoneBook
    {


        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }


        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(FirstName))
            {
                yield return new RuleViolation("First Name Required", "FirstName");
            }

            if (!OnValidatePropertyForPhonebook.CharStringValidator(FirstName))
            {
                yield return new RuleViolation("Please Enter Valid First Name", "FirstName");
            }

            yield break;
        }

        
        partial void OnValidate(System.Data.Linq.ChangeAction action)
        {
            if(!IsValid)
            {
                throw new ApplicationException("Rule violations prevent saving");
            }
        }

    }
}



但在Build期间,我收到如下错误:


but during Build, i am getting an error as follows:

No defining declaration found for implementing declaration of partial method ePhoneBookMvc4Application.Models.PhoneBook.OnValidate(System.Data.Linq.ChangeAction) 





而部分方法是在 Repositories .designer.cs 文件中定义的。 Repository.cs,IRepository Phonebook.dbml 文件是否必须与 Model.Phonebook 位于同一文件夹中?

请帮忙。



whereas the partial method is defined in the .designer.cs file in the Repositories. Is it necessary that the Repository.cs,IRepository and the Phonebook.dbml files must be in the same folder as the Model.Phonebook ?
Please help.

推荐答案

这就是它:你没有在某些部分类声明中提供匹配的方法声明。你没有提到它,我很想知道你对它的想法是什么。部分方法同样简单:

http://msdn.microsoft。 com / en-us / library / 6b0scde8.aspx [ ^ ]。



-SA
This is what it is: you did not provide matching method declaration in some partial class declaration. As you don''t mention about it, I would be curious to know what was your idea about it. Partial methods are as trivial as this:
http://msdn.microsoft.com/en-us/library/6b0scde8.aspx[^].

—SA


这篇关于部分方法实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆