不一致的可访问性错误C#
本文关键字:错误 访问 不一致 | 更新日期: 2023-09-27 18:26:01
试图处理一个项目,但不断收到此错误。
错误1可访问性不一致:参数类型"GICT_Project.IObjects"的可访问性低于方法"GICT_Project.DatabaseService.Insert(GICT_Project.IObjects)"E:''GICT_Poject''GICT_Pject''DatabaseService.cs 86 28 GICT_Product
不知道怎么了。我试着把东西公开,但没有成功。
这是有问题的代码:
public static void Insert(IObjects classType) //insert tool data
{
string query = "";
string type = (classType.GetType()).ToString();
switch (type) {
case "Tools":
query = "INSERT INTO group2.Tools (ToolID, ToolName, Quantity) VALUES(" + classType.GetSqlInfo() + ")";
break;
case "Service":
query = "INSERT INTO group2.Services (ServiceID, ServName, ToolID) VALUES(" + classType.GetSqlInfo() + ")";
break;
case "Location":
query = "INSERT INTO group2.Location (LocationID, Location, Features) VALUES(" + classType.GetSqlInfo() + ")";
break;
case "Appointments":
query = "INSERT INTO group2.Appointments (AppointmentID, CustomerID, ServiceID, LocationID, EmployeeID) VALUES(" + classType.GetSqlInfo() + ")";
break;
case "Employee":
query = "INSERT INTO group2.Employee (EmployeeID, EmpName, EmpBirthday, EmpAddress, LocationID) VALUES(" + classType.GetSqlInfo() + ")";
break;
case "Customer":
query = "INSERT INTO group2.Customer (CustomerID, CusName, CusBirthday, CusAddress) VALUES(" + classType.GetSqlInfo() + ")";
break;
case "Skills":
query = "INSERT INTO group2.Skills (SkillID, SkillName) VALUES(" + classType.GetSqlInfo() + ")";
break;
//many to many tables need to create rows on connecting tables when initialised
}
InsertQuery(query);
}
这是一个单独的类别:
interface IObjects
{
string GetSqlInfo();
int GetId();
void InsertData();
}
您应该将接口定义为public,因为公开接口的方法是public。如果不这样做,则该方法的使用者不知道接收参数的实际类型。
解决方案是在interface
:之前添加public
关键字
public interface IObjects
{
string GetSqlInfo();
int GetId();
void InsertData();
}
或者使方法不是public
,而是internal
,即类和接口的默认可访问性。
internal static void Insert(IObjects classType) //insert tool data
{ }
将您的接口公开。
public interface IObjects
{
string GetSqlInfo();
int GetId();
void InsertData();
}
或者使Insert
方法内部编译器报告此错误,因为您公开了公共方法内部的IObjects
接口,因此在某种程度上,外部dll可以通过Insert
方法访问它。
只需将接口更改为
public interface IObjects