15

我有三个班。都是同一个命名空间的一部分。这是三个类的基础知识。

//FBlock.cs
namespace StubGenerator.PropGenerator
{
    class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts,  IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts
    {
        private List<Property> pProperties;
        private List<Method> pMethods;
        public FBlock(string aFBlockName)
        { 
            pProperties = new List<Property>();
            pMethods = new List<Method>();
        }

        public Property AddProperty(string aName)
        {
            Property loProp = new Property(this, aName, pProperties.Count);
            pProperties.Add(loProp);
            return loProp;
         }

         public Method AddMethod(string aName)
         {
             Method loMeth = new Method(this, aName);
             pMethods.Add(loMeth);
             return loMeth;
         }
     }

 //Method.cs
 namespace StubGenerator.PropGenerator
 {
     class Method : IPropertyName
     {
         private List<StubGenerator.PropGenerator.PropertyAttribute> pPropertyAttributes;
         private string pName;
         private string pFBlockName;

         public Method(FBlock aFBlock,string aName)
         {
             pPropertyAttributes = new List<PropertyAttribute>();
             pName = aName;
             pFBlockName = aFBlock.Name;
         }
      }
 }

 //Property.cs
 namespace StubGenerator.PropGenerator
 {
    class Property : StubGenerator.PropGenerator.IPropertyName, StubGenerator.PropGenerator.IDesignRegionInserts, StubGenerator.PropGenerator.IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts
    {
        private string pName;
        private string pExpandedName;
        private string pFBlockInitials;

        private Group pPropertyGroup;
        private FlowLayoutPanel pGroupFlowPanel;
        private Button pUpdateButton;
        private CheckBox pShowProperty;


         private string pFBlockName;


         public Property(FBlock aFBlock, string aName, int aIndex)
         {
             pPropertyAttributes = new List<PropertyAttribute>();
             pFBlockName = aFBlock.FBlockName;

             ExpandName();
             GetInitials();

             pShowProperty = new CheckBox(this, 10, (aIndex + 1) * 20, aIndex);
             pPropertyGroup = new Group(this);
             pGroupFlowPanel = new FlowLayoutPanel(this);

             pUpdateButton = new Button(this, 10, 18, aIndex);
         }
     }
}

我收到以下错误

'StubGenerator.PropGenerator.Method' 由于其保护级别而无法访问

它指的是 FBlock.cs 文件中的以下行

private List<Method> pMethods;

'StubGenerator.PropGenerator.Method' 由于其保护级别而无法访问

它指的是 FBlock.cs 文件中的以下行

 public Method AddMethod(string aName)

可访问性不一致:返回类型“StubGenerator.PropGenerator.Method”比方法“StubGenerator.PropGenerator.FBlock.AddMethod(string)”更难访问

它指的是 FBlock.cs 文件中的以下行

 public Method AddMethod(string aName)

使类 Method 公开并不能解决错误。我无法弄清楚为什么在调用 Property 类时我没有收到错误。而且我不明白为什么公开 Method 类并不能解决问题。

有任何想法吗?

编辑问。文件上可能有一些设置会导致这种情况吗?

4

9 回答 9

21

首先,尝试完全重建。清理并构建(或仅使用重建)。每隔一段时间,它就会为我解决奇怪的构建问题。

接下来,注释掉您发布的示例中没有的其余代码。编译。那样有用吗?

如果是这样,开始添加段,直到一个打破它。

如果没有,请完成所有课程并重public试。

如果仍然失败,也许尝试将修剪的类放在同一个文件中并重建。那时,绝对没有理由出现访问问题。如果仍然失败,请使用木工。

于 2010-09-08T14:19:28.957 回答
7

有一个使用链接文件的项目。我还需要将 method.cs 文件作为链接文件添加到该项目中,因为 FBlock.cs 文件在那里。我以前从未听说过链接文件,我什至不知道这是可能的。

于 2010-09-08T14:37:24.743 回答
4

尝试将以下代码添加到您要使用的类中

[Serializable()]
public partial class Class
{
于 2013-04-11T23:49:05.887 回答
3

也可能是包含相关类的库未使用强名称正确签名的情况。

于 2010-09-12T02:40:09.467 回答
2

您发布的代码不会产生您引用的错误消息。您应该提供一个实际展示问题的(小)示例。

于 2010-09-08T13:21:24.343 回答
2

internal默认情况下,您的所有课程

标记public并没有起到作用。

您确定没有两个名为 Method 的类,并且可能包含错误的 Method 类吗?

于 2010-09-08T13:22:04.267 回答
0

我猜public Method AddMethod(string aName)是在 FBlock 实现的公共接口上定义的。不保证该接口的使用者可以访问 Method。

于 2010-09-08T13:21:40.277 回答
0

嗨,您需要将 Button 属性从私有更改为公共。您可以在 Button >> properties >> Design >> Modifiers >> "public" 下更改一旦更改,保护错误就会消失。

布迪

于 2017-07-17T07:46:46.857 回答
0

你的课应该是公开的

公共类 FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts

于 2020-10-21T17:45:39.430 回答