可访问性不一致的问题

可访问性不一致的问题

本文介绍了可访问性不一致的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面罗布科纳MVC店面教程系列,我从下面的构造公共SqlCatalogRepository(DB的DataContext)得到一个可访问性不一致错误:

I am following Rob Conery MVC Storefront tutorial series and I get an Inconsistent accessibility error from the following constructor public SqlCatalogRepository(DB dataContext) :

public class SqlCatalogRepository : ICatalogRepository
{
    DB db;

    public SqlCatalogRepository()
    {
        db = new DB();
        //turn off change tracking
        db.ObjectTrackingEnabled = false;
    }


    public SqlCatalogRepository(DB dataContext)
    {
        //override the current context
        //with the one passed in
        db = dataContext;
    }

下面是错误消息:
错误1可访问性不一致:参数类型'SqlRepository.DB'大于法Data.SqlCatalogRepository.SqlCatalogRepository(SqlRepository.DB)

Here is the error message :Error 1 Inconsistent accessibility: parameter type 'SqlRepository.DB' is less accessible than method 'Data.SqlCatalogRepository.SqlCatalogRepository(SqlRepository.DB)'

推荐答案

DB 类是不公开的,所以你不能使该把它作为一个参数公共方法(或构造函数) 。 (你会有什么装配外部来电吗?)

Your DB class is not public, so you can't make a public method (or constructor) that takes it as a parameter. (What would callers outside your assembly do?)

您需要或者让 DB 公共或使 SqlCatalogRepository 类(或它的构造函数)内部

You need to either make the DB class public or make the SqlCatalogRepository class (or its constructor) internal.

你做哪一个将取决于在那里正在使用你的类型。结果
。如果 SqlCatalogRepository 是只是意味着你的组件内使用,你应该让内部。 (内部表示,这只是其他类型的可见在相同的程序集)

Which one you do will depend where your types are being used.
If the SqlCatalogRepository is only meant to be used inside your assembly, you should make it internal. (internal means that it's only visible to other types in the same assembly)

如果它的意思被曝光您装配到其他组件,您应该使类公共,但构造内部

If it's meant to be exposed by your assembly to other assemblies, you should make the class public but the constructor internal.

如果在 DB 类本身意味着要通过各类程序集之外使用,你应该让 DB 类本身公共

If the DB class itself is meant to be used by types outside your assembly, you should make the DB class itself public.

这篇关于可访问性不一致的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:49