我正在学习 c#,我正在尝试Console Application
使用Three Tier Architecture
with进行基本登录Factory Method Design Pattern
。我添加了所有层并实现了与登录应用程序相关的所有逻辑。但是当我尝试使用dotnet run
命令运行代码时,它要求输入,输入后它给出错误
未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集“DataAccessLogic,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”。该系统找不到指定的文件。在 C:\Users\xxx\Desktop\FactoryPatternSample\FactoryMethodSampleApplication\FactoryMethod\Program.cs: 14 中的 FactoryMethod.Program.Main(String[] args) 处的 BusinessLogic.User.getUserName()
尽管该文件存在于 BusinessLogic.User.getUserName();
此处提供的代码
ILogin.cs
public interface ILogin
{
bool AttemptLogin();
string getUserName();
}
用户.cs
using System;
using DataAccessLogic;
namespace BusinessLogic
{
class User:ILogin
{
private string m_username;
private string m_password;
public User(string username, string password)
{
this.m_username = username;
this.m_password = password;
}
public bool AttemptLogin()
{
if(m_username.Equals("abc") && m_password.Equals("abc123"))
{
return true;
}
return false;
}
public string getUserName()
{
IGetDetails objectType = GetDetails.getDetails(m_username);
Console.WriteLine(objectType.getStudentName());
return objectType.getStudentName();
}
}
}
IGetDetails.cs
using System;
namespace DataAccessLogic
{
public interface IGetDetails
{
string getStudentName();
string getStudentId();
}
}
获取详细信息.cs
namespace DataAccessLogic
{
public class GetDetails
{
public static IGetDetails getDetails(string username)
{
Console.WriteLine(username);
IGetDetails objectType = null;
objectType = new GetValue(username);
return objectType;
}
}
}
获取值.cs
namespace DataAccessLogic
{
public class GetValue:IGetDetails
{
private string m_username = string.Empty;
public GetValue(string username)
{
this.m_username = username;
}
public string getStudentName()
{
return m_username;
}
public string getStudentId()
{
return "2205";
}
}
在 Program.cs 中
ILogin loginType = Login.attemptLogin(email, password);
if(loginType.AttemptLogin())
{
Console.WriteLine("Name: "+ loginType.getUserName());
}
在 loginType.getUserName() 中给出错误,如果我将getUserName()
方法更改为只返回一个像“hello”这样的字符串,它会给出输出,但是当我尝试从IGetDetails
给出错误的对象返回字符串时。
完整源代码Github
任何帮助,将不胜感激。
提前致谢。