我在C中为驱动程序开发了一个DLL.我用C++编写了一个测试程序,DLL运行正常.
现在我想使用Python来处理这个DLL.我已成功隐藏了大多数用户定义的C结构,但有一点我必须使用C结构.我对python很新,所以我可能会弄错.
我的方法是使用ctype在python中重新定义一些结构,然后将变量传递给我的DLL.但是在这些类中,我有一个自定义链表,其中包含递归类型,如下所示
class EthercatDatagram(Structure):
_fields_ = [("header", EthercatDatagramHeader),
("packet_data_length", c_int),
("packet_data", c_char_p),
("work_count", c_ushort),
("next_command", EthercatDatagram)]
Run Code Online (Sandbox Code Playgroud)
这失败了,因为在EthercatDatagram中,尚未定义EthercatDatagram,因此解析器返回错误.
我应该如何在python中表示这个链表,以便我的DLL能够正确理解它?
许多C++代码使用语法约定来标记成员变量.常见的例子包括
其他人尝试在使用成员变量时强制使用this-> member.
根据我的经验,大多数较大的代码库都无法一致地应用这些规则.
在其他语言中,这些惯例远没有那么普遍.我只偶尔在Java或C#代码中看到它.我想我从未在Ruby或Python代码中看到它.因此,似乎有一种趋势,即更多现代语言不对成员变量使用特殊标记.
这个约定今天在C++中是否仍然有用,或者它只是一个时代错误.特别是因为它在库之间使用不一致.没有其他语言显示没有成员前缀可以做到吗?
如果您有一个接口IFoo和一个类Bar : IFoo,为什么可以执行以下操作:
List<IFoo> foo = new List<IFoo>();
foo.Add(new Bar());
Run Code Online (Sandbox Code Playgroud)
但你做不到:
List<IFoo> foo = new List<Bar>();
Run Code Online (Sandbox Code Playgroud) 我有一个单元测试夹具,我正在尝试在ASP.NET MVC控制器上测试一个ControllerAction,该控制器用于Web应用程序上的成员函数.我正在尝试模拟测试的HttpContext.正在测试的ControllerAction实际上设置了HttpContext的属性,例如Session值,Response.Cookies值等.这不是所有代码,但这里是我试图运行的测试的粗略示例:
[Test]
public void ValidRegistrationDataSuccessfullyCreatesAndRegistersUser()
{
var context = new Mock<HttpContextBase>() {DefaultValue = DefaultValue.Mock};
context.SetupAllProperties();
var provider = new Mock<MembershipProvider>(new object[] {context.Object});
var controller = new AccountController(context.Object, provider.Object);
// This just sets up a local FormCollection object with valid user data
// in it to use to attempt the registration
InitializeValidFormData();
ActionResult result = controller.Register(_registrationData);
Assert.IsInstanceOfType(typeof(ViewResult), result);
// Here is where I'd like to attempt to do Assertions against properties
// of the HttpContext, like ensuring that a Session …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在编写代码时加速可重复任务的方法.我有ReSharper,我认为定制可以做我需要的.
我有两个相同类型的对象.我想将一个对象的所有公共属性复制到另一个对象.我想在这种情况下使用ReSharper工具为我生成代码.我会告诉它第一个对象和第二个对象的名称.我希望它找到第一个对象的所有公共属性,并将值复制到第二个对象.
这是我希望用ReSharper之类的工具生成的代码类型:
foo.Name = moo.Name;
foo.Age = moo.Age;
foo.City = moo.City;
Run Code Online (Sandbox Code Playgroud)
自动化这个从右到左复制值的简单代码可以节省大量时间,我认为ReSharper可以做到这一点.但是,我在搜索时没有看到任何弹出窗口.
我不是在寻找CodeSmith代码生成技术或T4模板,因为我只希望它在我的类中生成这些特定的行,而不是生成整个类或单独的文件.
有没有人知道按下几个按键的方法,输入上面的"foo"和"moo"对象名称并让工具从右到左的代码行生成这些副本?
更新:
我已经找到了一些关于构建ReSharper扩展的文档,这可能是通过该路径实现的,但它看起来真的很复杂.
http://www.jetbrains.net/confluence/display/ReSharper/PowerToys+Pack+3.0+User+Guide
除非其他人已经写过,否则这开始看起来像周末挑战.
[ 编辑插入:可能重复同一张海报的早期问题?]
嗨,我需要从文件中提取:
first
second
third
Run Code Online (Sandbox Code Playgroud)
使用grep命令,以下行:
second
third
Run Code Online (Sandbox Code Playgroud)
grep命令应该如何?
我想要一个ItemsControl,其中项目水平显示.
但是,无论我使用StackPanel的Orientation ="Horizontal"还是WrapPanel,它们仍然会堆叠起来.
如何让ItemsControl中的项目水平?
alt text http://i31.tinypic.com/dd2et5.png
XAML:
<Window x:Class="TestItemsControl2938.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="400">
<Window.Resources>
<DataTemplate x:Key="CustomerListTemplate">
<StackPanel Width="100" Background="#aaa" Margin="5">
<TextBlock Text="{Binding LastName}"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<StackPanel>
<StackPanel Orientation="Horizontal" Background="Orange">
<ItemsControl ItemsSource="{Binding CustomerList}" ItemTemplate="{StaticResource CustomerListTemplate}"/>
</StackPanel>
<WrapPanel Background="Yellow">
<ItemsControl ItemsSource="{Binding CustomerList}" ItemTemplate="{StaticResource CustomerListTemplate}"/>
</WrapPanel>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
代码隐藏:
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace TestItemsControl2938
{
public partial class Window1 : Window, INotifyPropertyChanged
{
private ObservableCollection<Customer> _customerList = new ObservableCollection<Customer>();
public ObservableCollection<Customer> …Run Code Online (Sandbox Code Playgroud) 我想知道是否有人可以让我开始如何使用openGL构建迷宫.我是否需要编写代码来绘制迷宫,还是像在单独的窗口中绘制图片一样?我需要创建一个游戏引擎来开始吗?我正在为iphone开发这样做,所以任何建议对我来说都是一个很好的开始.感谢大家的回复.
我有一个UITextField,当文本输入时,我想从文本字段中获取doubleValue并执行一些计算并在UITableView中显示它们.
UITextField的委托采用UITextFieldDelegate协议,并实现textFieldShouldReturn:和textFieldDidEndEditing:方法.textFieldShouldReturn:取消第一个响应者状态,根据文档也应该触发textFieldDidEndEditing:,但我从未看到textFieldDidEndEditing:调用.
- (BOOL)textFieldShouldReturn:(UITextField*)theTextField {
if (theTextField == thresholdValue) {
[thresholdValue resignFirstResponder];
}
return YES;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
[self updateThresholdValue:textField];
}
Run Code Online (Sandbox Code Playgroud)
值得注意的是,我还尝试将一些文本字段事件连接到委托并直接调用事件updateThresholdValue:但这也不起作用.
c# ×3
objective-c ×2
asp.net ×1
asp.net-mvc ×1
bash ×1
c++ ×1
cocoa-touch ×1
coding-style ×1
css ×1
ctypes ×1
dll ×1
generics ×1
grep ×1
ios ×1
iphone ×1
itemscontrol ×1
moq ×1
python ×1
recursion ×1
resharper ×1
structure ×1
wpf ×1
xaml ×1
xcode ×1