我有一个简单的业务经理门面,它应该只保留一些库存信息。但是,我不断收到“Home.Services.InventorySvc”是一种用作变量的类型的错误。
我的门面代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Home.Domain;
using Home.Services;
namespace Home.Business
{
public class InventoryMngr
{
public void Create(CreateInventory inv)
{
Factory factory = Factory.GetInstance();
InventorySvc invSvc =
(InventorySvc)factory.GetService(
(InventorySvc).Name);
invSvc.CreateInventory(inv);
}
}
}
InventorySvc 代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Home;
using Home.Domain;
namespace Home.Services
{
public interface InventorySvc : IService
{
void CreateInventory(CreateInventory createinventory);
}
}
最佳答案
您正在使用 (InventorySvc).Name
与 InventorySvc.Name
相同,所以这将访问 InventorySvc
的静态成员类(class)。因为它不是一个类而是一个接口(interface),所以它不能有静态成员。
关于c# - 用作变量的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12664977/