我正在研究Visual Studio 2015和共享项目的新功能,但我不明白它与使用类库或可移植类库有何不同.谁能解释一下?
编辑:共享项目是Visual Studio 2015中的一项新功能,与便携式类库不同.我理解可移植类库是什么.我想要了解的是共享项目与类库的区别.见下面的链接.
我目前有一个多个项目的解决方案,大多使用相同的类.因此,在我看来,在解决方案中添加包含这些类的类库是一个好主意,而不是在每个项目中重复该类.
但是,我所拥有的一个项目需要一些特定于该项目的类的附加属性,并且不会在其他任何地方使用.结果,我认为我应该使用部分类来添加这些属性.所以我做了类似这样的事情:
在类库中:
namespace MyClassLibrary
{
public partial class Book
{
public string Title { get; set; }
public string AuthorLast { get; set; }
public string AuthorFirst { get; set; }
public string Publisher { get; set; }
public string Edition { get; set; }
public string ISBN10 { get; set; }
public string ISBN13 { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
在项目中(MyProject):
namespace MyClassLibrary
{
public partial class Book
{
public string AdditionalProperty { get; set; }
}
} …Run Code Online (Sandbox Code Playgroud) 考虑到我们在创造一个局部类PROJECT1,我们有一个Project2中有提及PROJECT1.怎么是它可以声明局部类的其他一些方法Project2的?
谢谢
我必须能够连接到两个不同版本的API(1.4和1.5),我们称之为Foo API.我连接到API并处理结果的代码基本上是重复的 - 唯一的区别是从两个API返回的数据类型.我怎样才能重构这个以消除重复?
在Foo14Connector.cs(我自己的类中调用1.4 API)
public class Foo14Connector
{
public void GetAllCustomers()
{
var _foo = new Foo14WebReference.FooService();
Foo14WebReference.customerEntity[] customers = _foo.getCustomerList;
foreach (Foo14WebReference.customerEntity customer in customers)
{
GetSingleCustomer(customer);
}
}
public void GetSingleCustomer(Foo14WebReference.customerEntity customer)
{
var id = customer.foo_id;
// etc
}
}
Run Code Online (Sandbox Code Playgroud)
在几乎完全重复的类Foo15Connector.cs(我自己的类调用1.5 API)中
public class Foo15Connector
{
public void GetAllCustomers()
{
var _foo = new Foo15WebReference.FooService();
Foo15WebReference.customerEntity[] customers = _foo.getCustomerList;
foreach (Foo15WebReference.customerEntity customer in customers)
{
GetSingleCustomer(customer);
}
}
public void GetSingleCustomer(Foo15WebReference.customerEntity customer)
{
var id …Run Code Online (Sandbox Code Playgroud) 可能重复:
是否可以在两个项目中声明一个分部类
说在我的项目解决方案中,我有两个项目,ProjectA和ProjectB.ProjectA创建:MyClassA
然后ProjectB引用了ProjectA.是否可以在ProjectB中为ProjectA的MyClassA创建部分类?
我的项目A的MyClassA:
namespace TestPartial
{
public class MyClassA
{
public string MyName { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我的项目B的MyClassB:
namespace TestPartial
{
public partial class MyClassA
{
public DateTime BirthDate { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
但显然这两个属性都没有合并....所以我想只有它们只在同一个项目中才能工作?或者有一些解决方法吗?