简体   繁体   English

即兴:无法加载类型,因为它试图将一个类实现为接口

[英]Impromptu: Could not load type because it attempts to implement a class as an interface

I have just started using Impromptu after a recommendation from someone on stack. 经过栈上某人的推荐后,我才刚刚开始使用Impromptu。

I believe I have implemented it correctly but I am getting the error "Could not load type because it attempts to implement a class as an interface" 我相信我已经正确实现了它,但是却收到错误“由于试图将类实现为接口而无法加载类型”

In my portable class library I have the following model: 在我的可移植类库中,我具有以下模型:

public class Route
{
    public User user { get; set; }
}

public class User
{
    public Name name { get; set; }
}

public class Name
{
    public string title { get; set; }
    public string firstName { get; set; }
    public string middleName { get; set; }
    public string lastName { get; set; }
}

and I have created the following IClasses in my MVC project: 并且在我的MVC项目中创建了以下IClass:

public class IRoute
{
    public IUser user { get; set; } 
}

public class IUser
{
    public IName name { get; set; }
}

public class IName
{
    [Required]
    public string firstName { get; set; }
    [Required]
    public string lastName { get; set; }
}

and in my controller I have the following being sent to the view: 在控制器中,我将以下内容发送到视图:

Route sendthis = new Route();
return View(sendthis.ActLike<IRoute>());

but I get the error "Could not load type because it attempts to implement a class as an interface" 但出现错误“由于试图将类实现为接口而无法加载类型”

I cannot work out what I have done wrong. 我无法弄清楚我做错了什么。 Can anyone help please? 有人可以帮忙吗?

Thanks 谢谢

I hadn't changed the local classes to "Interface". 我没有将本地类更改为“接口”。

public interface IRoute
{
    IUser user { get; set; } 
}

public interface IUser
{
    IName name { get; set; }
}

public interface IName
{
    [Required]
    string firstName { get; set; }
    [Required]
    string lastName { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用即兴接口来获取属性的类型 - Using Impromptu-Interface to obtain the type of a property 无法实现接口,因为任务没有匹配的返回类型<custom class>方法</custom> - Cannot implement interface because does not have matching returning type for Task<Custom class> method 更改接口时无法加载类型 - Could not load type when changing the interface 无法实现接口成员,因为它没有匹配的返回类型 - unable to implement interface member because it does not have the matching return type 无法实现接口成员,因为它没有匹配的返回类型 - Cannot implement interface member because it does not have the matching return type 如何使用泛型类实现具有接口类型签名的接口 - How to implement interface having a signature of interface type with generic class 无法创建类型的实例。 类型是接口或抽象类,不能被实例化 - Could not create an instance of type . Type is an interface or abstract class and cannot be instantiated 自定义类实现接口 IDictionary<type, type> 那可能是静态的? - Custom class implementing interface IDictionary<type, type> that could be static? C#查找没有泛型类型的所有类实现接口 - C# find all class implement interface without generic type Select 实现多个协变接口的 class 中的协变接口类型 - Select the type of a covariant interface in a class that implement multiple covariant interfaces
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM