2015-03-23 2 views
0

У меня есть интерфейс, какКакая ошибка я делаю в приведенном ниже коде C#?

interface IEmpDeptRepository : IEmployeeRepository,IDepartmentRepository 
{ 
     IEnumerable<EmpDept> GetAll();   
} 

interface IEmployeeRepository 
{ 
     IEnumerable<Employee> GetAll();  
} 

interface IDepartmentRepository 
{ 
     IEnumerable<Department> GetAll();   
} 

Класс EmpDept является

class EmpDept 
     { 
      public List<Employee> Employees { get; set; } 
      public List<Department> Departments { get; set; }  
     } 

Теперь класс EmpDeptRepository как под

public class EmpDeptRepository:IEmpDeptRepository 
    { 
     private List<EmpDept> empDepts = new List<EmpDept>(); 

     public EmpDeptRepository() 
     { 

      Add(new EmpDept { Employees = IEmployeeRepository.GetAll(), Departments = IDepartmentRepository.GetAll() });    
     } 

     public EmpDept Add(EmpDept empDept) 
     { 
      if (empDept == null) 
      { 
       throw new ArgumentNullException("Employee Department"); 
      }    
      empDepts.Add(empDept); 
      return empDept; 
     } 


     public IEnumerable<EmpDept> GetAll() 
     { 
      return empDepts; 
     } 

     IEnumerable<Employee> IEmployeeRepository.GetAll() 
     { 
      IEmployeeRepository employeeRepository = new EmployeeRepository(); 
      return employeeRepository.GetAll(); 
     } 

     IEnumerable<Department> IDepartmentRepository.GetAll() 
     { 
      IDepartmentRepository deptRepository = new DepartmentRepository(); 
      return deptRepository.GetAll(); 
     } 
    } 

И я получаю ошибку ниже

Error 1 Inconsistent accessibility: parameter type 'Models.EmpDept' is less accessible than method 'Models.EmpDeptRepository.Add(Models.EmpDept)' 
Error 2 Inconsistent accessibility: return type 'Models.EmpDept' is less accessible than method 'Models.EmpDeptRepository.Add(Models.EmpDept)' 
Error 3 Inconsistent accessibility: return type 'System.Collections.Generic.IEnumerable<Models.EmpDept>' is less accessible than method 'Models.EmpDeptRepository.GetAll()' 

В чем ошибка? Помогите?

+1

yes Приянка меняет класс EmpDept на 'public class EmpDept'. Он устранит ошибки. –

ответ

1

Сделать все ваши классы общественности:

public class EmpDept 
+0

Мои все классы являются общедоступными ... –

+0

'class EmpDept' =>' public class EmpDept' – StuartLC

+0

спасибо, что сработали. теперь другая проблема. для строки Add (новый EmpDept {Employees = IEmployeeRepository.GetAll(), Departments = IDepartmentRepository.GetAll()}); , Ошибка: Ошибка ссылка \t \t 2 Объекта необходима для не-статического поля, методы или свойств «IEmployeeRepository.GetAll()» \t Ошибки Ссылки на объект необходима для не-статического поля, методы, или свойство 'IDepartmentRepository.GetAll()' –

1

Сделать класс EmpDept общественности, потому что, когда вы хотите получить доступ к нему с открытыми методами он должен быть публичным тоже.

Смежные вопросы