一种解决方案(the.sln)
一个C++项目(2010年的mycppproject.vcxproj或2008年的mycppproject.vcproj)编译导出某些函数的本机DLL.在调试中,这构建了c:\ output\Debug\mycppproject_d.dll,在发行版中,这构建了c:\ output\Release\mycppproject.dll.
一个包含PInvoke的C#控制台应用程序(mycsharpconsole.csproj)调用DLL.
所有编译都很好.
当我构建时,我希望能够将csharp项目中的引用添加到cpp DLL项目中,以便它可以将相应目录中的相应文件复制到内置csharp项目的\ bin\Debug目录中.
这应该是可能的,因为IDE知道有关构建DLL的位置以及构建C#应用程序的位置的所有内容.
在Visual Studio 2010中:
我在csharp项目上尝试了"Dependencies ..."并添加了对mycppproject的依赖,但这没有任何效果.
我在csharp项目上尝试了"Add Reference ..."并添加了对cpp项目的引用,但是我收到一条警告消息'项目的Target Framework版本"mycppproject"高于当前项目Target Framework版本.您是否要将此引用添加到项目中?(是/否/取消).
单击"是"将生成错误消息"无法添加对mycppproject的引用".
Clone()
只有一个浅层副本,似乎没有直接的方法在C#中做这个没有一些样板代码包装序列化(如何在.NET中执行对象的深层复制(特别是C#)?).有没有一种简单的方法在Powershell中执行此操作而不引用外部库?
该BuildingInsideVisualStudio属性提供检测项目是否在Visual Studio中建立的能力.
有没有办法确定使用哪个版本的Visual Studio?
例如,WCF服务可以充当其他WCF服务的工厂吗?例如:
[ServiceContract(Namespace = "Foo")]
interface IThing
{
[OperationContract]
void DoSomething();
}
[ServiceContract(Namespace = "Foo")]
interface IMakeThings
{
[OperationContract]
IThing Create(string initializationData);
}
Run Code Online (Sandbox Code Playgroud)
同样,接口可以将另一个接口作为参数吗?
[ServiceContract(Namespace = "Foo")]
interface IUseThings
{
[OperationContract]
void UseThing(IThing target);
}
Run Code Online (Sandbox Code Playgroud)
这需要调整已知类型吗?
所有接口都是预先定义的,并且客户端和服务都知道.
使用隐式转换编写代码会生成CS0266.
Dictionary<Int32, string[]> d1 = new Dictionary<int, string[]>();
IDictionary<int, IEnumerable<string>> ide1 = d1; // CS0266
Run Code Online (Sandbox Code Playgroud)
显式强制转换存在的提示表明显式强制转换可以解决问题.
IDictionary<int, IEnumerable<string>> ide1 = (IDictionary<int, IEnumerable<string>>)d1; // No error, but throws an exception
Run Code Online (Sandbox Code Playgroud)
有没有办法让这个演员表演?它会为工作string[][]
和IEnumerable<IEnumerable<string>>
?
namespace Quickie
{
class QuickieArray
{
private static void TestCastDictionaryWithArrayValue()
{
Console.WriteLine();
Console.WriteLine("===TestCastDictionaryWithArrayValue===");
Dictionary<Int32, string[]> d1 = new Dictionary<int, string[]>();
d1[1] = new string[]{"foo"};
IDictionary<int, string[]> id1 = d1;
Console.WriteLine("id1 is null: {0}", id1 == null);
IDictionary<int, IEnumerable<string>> ide1 = id1 as IDictionary<int, IEnumerable<string>>; …
Run Code Online (Sandbox Code Playgroud) 调试时,有各种变量窗口(autos,locals,watch),其中包含Name,Value,Type列.该值通常似乎显示对象的类名.在特定情况下,我想根据类实例的属性显示更有意义的内容.
作为一个具体的例子,对于CodeTypeReference,我想看到基于BaseType字符串或ArrayElementType值引用的类型的文本表示(where valid),而不是看到"System.CodeDom.CodeTypeReferenceExpression".
可视化器似乎提供单独的对话框窗口,而不是填充值列的方法.
数据提示是每个变量而不是每种类型.
最接近的似乎是DebuggerTypeProxyAttribute,在这种情况下,我想我问"是否有可能将属性应用于其他人的类?"
我主要处理Visual Studio 2010,尽管Visual Studio 2008的答案很有用.