我有三个类,它们都属于同一个命名空间。以下是这三个类的基础知识。
//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类设为public并不能解决错误。当调用Property类时却不会出现错误,我不明白为什么。而且我也不知道为什么将Method类设为public无法解决问题。
有任何想法吗?
编辑后再问一下,可能是文件上的某些设置导致了这个问题吗?
Property
构造函数引用了一个不存在的字段pPropertyAttributes
。你显然没有发布产生错误的代码。 - Timwi