我使用Visual Studio 2017编译了以下C ++方法:
extern "C" __declspec( dllexport )
Info* __stdcall GetInfo(InfoProvider* infoProvider)
{
static_assert(std::is_pod<Info>::value, "Must be Plain Old Data in order to be safely copied between DLL boundaries");
Info info = new Info();
Info->data1 = infoProvider->data1;
Info->data2 = infoProvider->data2;
return info;
}
Run Code Online (Sandbox Code Playgroud)
在Java代码中,它由Java Native Runtime使用具有以下签名的接口方法进行映射:
Info GetInfo(Pointer infoProvider);
final class Info extends Struct {
public final Signed32 data1;
public final Signed32 data2;
public R2VInfo(final Runtime runtime) {
super(runtime);
data1 = new Signed32();
data2 = new Signed32();
}
}
Run Code Online (Sandbox Code Playgroud)
有用。 …
Visual Studio中的代码度量分析器以及代码度量电源工具,TestMethod将以下代码方法中的代码行数报告为8.
最多,我希望它报告代码行为3.
[TestClass]
public class UnitTest1
{
private void Test(out string str)
{
str = null;
}
[TestMethod]
public void TestMethod()
{
var mock = new Mock<UnitTest1>();
string str;
mock.Verify(m => m.Test(out str));
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释为什么会这样吗?
更多信息
经过一番挖掘后,我发现out从Test方法中删除参数并更新测试代码会导致LOC被报告为2,我认为这是正确的.添加out会导致跳转,因此不是因为大括号或属性.
用dotPeek反编译DLL会显示相当多的额外代码,因为out参数可以被认为是8 LOC,但删除参数和反编译也会显示生成的代码,可以认为是5 LOC,所以它不仅仅是VS的问题计算编译器生成的代码(我不相信它应该做什么).
我创建了WPF应用程序,允许用户借助可视化工具创建图形.该应用程序能够将图形布局,属性和数据序列化为XML文件,然后它可以反序列化XML内容,重建图形并向用户显示可视化.
我需要将此应用程序与Visual Studio 2012集成,作为扩展或插件,以便可以使用我的图形设计器从具有特定扩展名的解决方案资源管理器中打开,修改和保存文件.它在概念上类似于Visual Studio的Entity Framework Designer.
我已经安装了Visual Studio SDK来编写VS Package.我创建了Visual Studio Package项目,然后我选择了"自定义编辑器"选项.生成了一些示例代码,但它使用Windows窗体控件.看起来很难将WPF控件与VS"Custom Editor"接口结合在一起.
如何创建自定义VS2012 WPF设计器?我在Web上找不到任何好的文档或教程来定位我的要求.我已经有一个完整的WPF应用程序,具有使用GUI工具创建图形,序列化和反序列化到文件的功能.我只需要将它与Visual Studio 2012集成.
我有一个单元测试项目,它有自己的app.config文件,它是由正在测试的目标项目定义的真实配置文件的模拟.这个模拟文件由单元测试代码(而不是目标项目)加载和处理,如果我只在这个测试项目中运行测试,它就能正常工作.
ConfigurationManager.GetSection(sectionName)
Run Code Online (Sandbox Code Playgroud)
但是,如果我从多个测试项目运行测试,并且在相关项目之前执行其他测试项目,则返回上述语句null.如果首先执行讨论的测试项目,则加载配置文件没有问题.
如何在单元测试中修复配置文件的加载才能正常工作?
我创建了Visual Studio 2012 Package(使用VS2012 SDK).此扩展(如果安装在客户端的IDE环境中)应该具有从开发人员正在处理的当前打开的解决方案中收集所有特定类型的功能.Visual Studio Designer for ASP.NET MVC Application Project中嵌入了类似的功能,其中开发人员实现模型/控制器类,构建项目,然后能够在Scaffolding UI(Designer的下拉列表)中访问此类型.相应的功能也可用于WPF,WinForms视觉设计师等.
假设我的扩展必须从当前解决方案中收集所有类型,这些解决方案实现了ISerializable接口.步骤如下:开发人员创建特定的类,重建包含项目/解决方案,然后执行扩展UI提供的某些操作,从而涉及执行ISerializable类型收集.
我试图用反射实现收集操作:
List<Type> types = AppDomain.CurrentDomain.GetAssemblies().ToList()
.SelectMany(s => s.GetTypes())
.Where(p => typeof(ISerializable).IsAssignableFrom(p) && !p.IsAbstract).ToList();
Run Code Online (Sandbox Code Playgroud)
但是上面的代码会导致System.Reflection.ReflectionTypeLoadException抛出异常:
System.Reflection.ReflectionTypeLoadException was unhandled by user code
HResult=-2146232830
Message=Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Source=mscorlib
StackTrace:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
(...)
LoaderException: [System.Exception{System.TypeLoadException}]
{"Could not find Windows Runtime type 'Windows.System.ProcessorArchitecture'.":"Windows.System.ProcessorArchitecture"}
(...)
Run Code Online (Sandbox Code Playgroud)
如何正确实施从当前构建的解决方案中收集特定类型的操作?
c# vspackage vsix visual-studio-extensions visual-studio-2012
我使用AutoFixture 3.21.0,AutoFixture.AutoMoq 3.21.0,NUnit 2.6.3和Moq 4.2.1409.1722.
我有以下接口,两个抽象类(其中一个实现此接口)和两个单元测试.
测试通过.
public interface IMigration
{
IMigrationParameters MigrationParameters { get; set; }
}
public abstract class AbstractSutWithoutInterface
{
public IMigrationParameters MigrationParameters { get; set; }
}
public abstract class AbstractSutWithInterface : IMigration
{
public IMigrationParameters MigrationParameters { get; set; }
}
[TestFixture]
public class UnitTests
{
[Test]
public void TestAbstractSutWithoutInterface()
{
var fixture = new Fixture();
fixture.Customize( new AutoConfiguredMoqCustomization() );
var mock = fixture.Create<AbstractSutWithoutInterface>();
Assert.IsNotNull( mock.MigrationParameters ); // test passes
}
[Test]
public …Run Code Online (Sandbox Code Playgroud) 我知道一种方法- memcpy在C ++端使用:
C ++方法:
void CopyData(void* buffer, int size)
{
memcpy(buffer, source, size);
}
Run Code Online (Sandbox Code Playgroud)
JNR映射:
void CopyData(@Pinned @Out ByteBuffer byteBuffer, @Pinned @In int size);
Run Code Online (Sandbox Code Playgroud)
Java调用:
ByteBuffer buffer = ByteBuffer.allocateDirect(size);
adapter.CopyData(buffer, size);
Run Code Online (Sandbox Code Playgroud)
但是我想处理本机代码不复制数据,而只返回指向要复制的内存的情况:
C ++方法:
void* GetData1()
{
return source;
}
// or
struct Data
{
void* data;
};
void* GetData2(Data* outData)
{
outData->data = source;
}
Run Code Online (Sandbox Code Playgroud)
我知道如何编写JNR映射以将数据复制到HeapByteBuffer:
Pointer GetData1();
// or
void GetData2(@Pinned @Out Data outData);
final class Data extends Struct {
public final Struct.Pointer data; …Run Code Online (Sandbox Code Playgroud) 我注意到Visual Studio 2012的以下行为:我创建了VS2012 Package Project(来自SDK).当我编译并运行它时,会启动一个实验性VS实例,因此我可以测试实现的包.但是,如果我从实验VS实例(使用Tools -> Extensions and Updates -> Uninstall)卸载包,那么我尝试重新编译并重新运行包,我得到编译错误,没有输出和错误列表中显示的任何错误.因此,再次开发我的包是不可能的.每个新创建的VS2012包项目都可以重现此问题.
总之,我无法在实验VS实例中运行我的包,因为我以前卸载过它.它似乎是一个包元数据缓存问题.我该如何解决这个问题?
编辑:
重现此问题的步骤:
Tools -> Extensions and Updates并卸载刚刚创建的扩展.此时,再次使用此Package Project无法运行VS Experimental实例.
visual-studio vsix visual-studio-extensions visual-studio-2012 visual-studio-package
我有以下计算表达式构建器:
type ExprBuilder() =
member this.Return(x) =
Some x
let expr = new ExprBuilder()
Run Code Online (Sandbox Code Playgroud)
我理解方法Return,Zero和Combine的目的,但我不明白下面的表达式有什么区别:
let a = expr{
printfn "Hello"
return 1
} // result is Some 1
let c = expr{
return 1
printfn "Hello"
} // do not compile. Combine method required
Run Code Online (Sandbox Code Playgroud)
我也不明白为什么在第一种情况下,零方法不需要printfn语句?
我使用 .NET 6 SDK (6.0.400),并且我有一个涉及StyleCop.Analyzers和stylecop.json的最简单的项目:
类库1.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="stylecop.json" Link="stylecop.json" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
Class1.cs:
// <copyright file="Class1.cs" company="My Company">
// Copyright (c) My Company. All rights reserved.
// </copyright>
namespace ClassLibrary1;
/// <summary>
/// Comment.
/// </summary>
public class Class1
{
/// <summary>
/// Initialises a new instance of the <see cref="Class1"/> class.
/// Comment.
/// </summary> …Run Code Online (Sandbox Code Playgroud) 我是Objective C的新手,我对这个概念感到困惑.
以下方法应该创建作为参数传递的类的实例并编辑实例的变量.
- (void) createObject:(Class)objecttype atPoint: (CGPoint)position {
if ([objecttype isSubclassOfClass:[GameObject class]]){
id theobject = [[objecttype alloc] init];
theobject.x = position.x; //error
theobject.y = position.y; //error
}
}
Run Code Online (Sandbox Code Playgroud)
我收到上面显示的错误消息: Property 'x' not found on object of type '__strong id'
看起来它应该很简单,但我不明白什么是错的.