IntelliSense不显示部分类方法

时间:2013-09-08 22:54:52

标签: c# linq intellisense

我有LINQtoSQL生成的部分类User,紧接着是:

    [global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.[User]")]
public partial class User : INotifyPropertyChanging, INotifyPropertyChanged
{

    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
 ...

然后我在我的项目中创建了单独的文件夹“Proxy”,并在那里添加了一些User类:

namespace LINQtoSQL_sample.Proxy
{
    public partial class User
    {
        public static string GetActivationUrl()
        {
            return Guid.NewGuid().ToString("N");
         ...

当我尝试从同一项目的另一部分调用额外的静态方法时会发生问题。假设我有一个文件夹“SqlRepositoryImpl”和另一个部分类:

namespace LINQtoSQL_sample.SqlRepositoryImpl
{
    public partial class SqlRepository
    {
        public bool CreateUser(User instance)
        {
            if (instance.ID == 0)
            {
                instance.added_date = DateTime.Now;
                instance.activated_link = LINQtoSQL_sample.Proxy.User.GetActivationUrl();
              ...

正如您所看到的,我明确定义了我要调用的User类的哪个部分,因为IntelliSense没有建议我使用额外的方法。

请告知为何会出现这种情况以及我错在哪里?

1 个答案:

答案 0 :(得分:2)

  

正如您所看到的,我明确定义了我要调用的User类的哪个部分,因为IntelliSense没有建议我使用额外的方法。

当你从一个类中调用一个方法时,该类中没有“部分”了。

如果您需要(并且可以)指定类的完整命名空间来从中调用方法,这意味着您实际上在两个不同的命名空间中有两个不同的类。如果两个partial声明位于不同的名称空间中,那么您实际上已经声明了两个单独的类,而不是来自两个部分的单个类。

相关问题