由于其保护级别,该类无法访问
我有三节课。所有这些都是同一名称空间的一部分。这是三个类的基础知识。
//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 类公开并不能解决问题。
有什么想法吗?
编辑询问。文件中是否存在某些设置导致此问题?
I have three classes. all are part of the same namespace. here are the basics of the three classes.
//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);
}
}
}
I'm getting the following errors
'StubGenerator.PropGenerator.Method' is inaccessible due to its protection level
which refers to the following line in the FBlock.cs file
private List<Method> pMethods;
and
'StubGenerator.PropGenerator.Method' is inaccessible due to its protection level
which refers to the following line in the FBlock.cs file
public Method AddMethod(string aName)
and
Inconsistent accessibility: return type 'StubGenerator.PropGenerator.Method' is less accessible than method 'StubGenerator.PropGenerator.FBlock.AddMethod(string)'
which refers to the following line in the FBlock.cs file
public Method AddMethod(string aName)
making the class Method public does not resolve the errors. I can't figure out why I don't get the errors when calling the Property class. And I don't understand why making the Method class public doesn't fix the problem.
Any ideas?
Edited to ask. could there be some setting on the file that causes this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
首先,尝试完全重建。清理并构建(或仅使用重建)。每隔很长一段时间,它就会为我解决奇怪的构建问题。
接下来,注释掉您发布的示例中未包含的其余代码。编译。那有用吗?
如果是这样,请开始添加片段,直到有人破坏它。
如果不是,请将所有类设为
public
,然后重试。如果仍然失败,也许尝试将修剪后的类放在同一个文件中并重建。到那时,绝对不会出现访问问题。如果还是不行,那就去干木工吧。
First thing, try a full rebuild. Clean and build (or just use rebuild). Every once in a long while that resolves bizarre build issues for me.
Next, comment out the rest of the code that is not in your example you have posted. Compile. Does that work?
If so, start adding segments back until one breaks it.
If not, make all the classes
public
and try again.If that still fails, maybe try putting the trimmed down classes in the same file and rebuilding. At that point, there would be absolutely no reason for access issues. If that still fails, take up carpentry.
有一个项目使用链接文件。我还需要将 method.cs 文件作为链接文件添加到该项目中,因为 FBlock.cs 文件就在那里。我以前从未听说过链接文件,我什至不知道这是可能的。
There was a project that used linked files. I needed to add the method.cs file to that project as a linked file as well, since the FBlock.cs file was there. I've never heard of linked files before, I didn't even know that was possible.
尝试将以下代码添加到您要使用的类中
Try adding the below code to the class that you want to use
也可能是包含相关类的库未使用强名称正确签名。
It may also be the case that the library containing the class in question is not properly signed with a strong name.
您发布的代码不会产生您引用的错误消息。您应该提供一个实际展示问题的(小)示例。
The code you posted does not produce the error messages you quoted. You should provide a (small) example that actually exhibits the problem.
默认情况下,所有类都是
internal
标记
public
并没有达到目的。您确定没有两个名为 Method 的类,并且可能包含了错误的 Method 类吗?
All your classes are
internal
by defaultMarking
public
did not do the trick.Are you sure you do not have two classes named Method, and perhaps are including the wrong Method class?
我猜测 public Method AddMethod(string aName) 是在 FBlock 实现的公共接口上定义的。不保证该接口的使用者能够访问方法。
I'm guessing
public Method AddMethod(string aName)
is defined on a public interface that FBlock implements. Consumers of that interface are not guaranteed to have access to Method.您好,您需要将按钮属性从私有更改为公共。
您可以在按钮>>下更改属性>>设计>>修饰符>> “民众”
一旦更改,保护错误就会消失。
布迪
Hi You need to change the Button properties from private to public.
You can change Under Button >> properties >> Design >> Modifiers >> "public"
Once change the protection error will gone.
Budi
你的类应该是公共
公共类FBlock:IDesignRegionInserts,IFormRegionInserts,IAPIRegionInserts,IConfigurationInserts,ISoapProxyClientInserts,ISoapProxyServiceInserts
your class should be public
public class FBlock : IDesignRegionInserts, IFormRegionInserts, IAPIRegionInserts, IConfigurationInserts, ISoapProxyClientInserts, ISoapProxyServiceInserts