我正在尝试使用System.Xml.Serialization.XmlSerializer序列化动态加载(和编译的类).如果我将有问题的类构建到主程序集中,一切都按预期工作.但是如果我从动态加载的程序集中编译并加载该类,则会XmlSerializer抛出异常.
我究竟做错了什么?
我创建了以下.NET 3.5 C#应用程序来重现该问题:
using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using System.Text;
using System.Reflection;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
public class StaticallyBuiltClass
{
public class Item
{
public string Name { get; set; }
public int Value { get; set; }
}
private List<Item> values = new List<Item>();
public List<Item> Values { get { return values; } set { values = value; } }
}
static class Program
{
static void Main()
{
RunStaticTest();
RunDynamicTest();
} …Run Code Online (Sandbox Code Playgroud) 我的问题不是从基类构造函数调用虚拟成员函数,而是指向虚方法成员函数的指针在基类构造函数中是否有效.
鉴于以下内容
class A
{
void (A::*m_pMember)();
public:
A() :
m_pMember(&A::vmember)
{
}
virtual void vmember()
{
printf("In A::vmember()\n");
}
void test()
{
(this->*m_pMember)();
}
};
class B : public A
{
public:
virtual void vmember()
{
printf("In B::vmember()\n");
}
};
int main()
{
B b;
b.test();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
对于所有兼容的c ++编译器,这会产生"In B :: vmember()"吗?
我有以下python程序:
#!/usr/bin/env python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('arg', choices=['foo', 'bar', 'baz'], default='foo', nargs='*')
args = parser.parse_args()
print(args)
Run Code Online (Sandbox Code Playgroud)
如果我像这样调用程序:
./prog.py
Run Code Online (Sandbox Code Playgroud)
输出是
Namespace(arg='foo')
Run Code Online (Sandbox Code Playgroud)
但是如果我foo以参数的形式调用程序:
./prog.py foo
Run Code Online (Sandbox Code Playgroud)
输出是
Namespace(arg=['foo'])
Run Code Online (Sandbox Code Playgroud)
题
如何才能获得arg默认值list?
我试过了
我尝试过设置,default=['foo']但结果是:
prog.py: error: argument arg: invalid choice: ['foo'] (choose from 'foo', 'bar', 'baz')
Run Code Online (Sandbox Code Playgroud) 我需要将一个短值从主机字节顺序转换为小端.如果目标是大端,我可以使用htons()函数,但唉 - 事实并非如此.
我想我能做到:
swap(htons(val))
Run Code Online (Sandbox Code Playgroud)
但是这可能会导致字节被交换两次,从而使结果正确但给我一个性能损失,这在我的情况下是不正确的.
我正在实现一个构建uint8_t向量的工厂类.我希望能够在返回结果向量时使用移动语义.这似乎有效,但我不相信这是完成我想要的正确方法.
我已经看到了很多关于如何将返回的自动变量视为rvalue并使用调用代码的move构造函数的示例,但在我的示例中,返回的对象是成员.我知道如果调用者将返回值放入移动构造函数中,该成员将丢失其内容 - 这正是我想要的.
我写的是这样的:
#include <cstdint>
#include <iostream>
#include <vector>
class Factory
{
public:
std::vector<uint8_t> _data;
Factory(std::size_t size) :
_data(size, 0)
{
}
void buildContent(int param)
{
// perform operations on the contents of _data
}
std::vector<uint8_t> && data()
{
return std::move(_data);
}
};
int main()
{
Factory factory(42);
factory.buildContent(1);
std::vector<uint8_t> temp(factory.data());
std::cout << "temp has " << temp.size() << " elements" << std::endl;
std::cout << "factory._data has " << factory._data.size() << " elements" << std::endl;
return 0;
} …Run Code Online (Sandbox Code Playgroud) 我有以下C程序:
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
int main()
{
int fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NONBLOCK);
if(fd < 0)
{
perror("Could not open device");
}
printf("Device opened\n");
struct termios options;
tcgetattr(fd, &options);
cfmakeraw(&options);
cfsetispeed(&options, B19200);
cfsetospeed(&options, B19200);
tcsetattr(fd, TCSANOW, &options);
char txpacket[] = {0x23, 0x06, 0x00, 0x00, 0xdd, 0xf9};
ssize_t written = write(fd, txpacket, sizeof(txpacket));
printf("Written %d bytes\n", written);
printf("Starting to wait for target to respond\n");
while(1)
{
fd_set readset;
FD_ZERO(&readset);
FD_SET(fd, &readset);
int nCount = select(fd …Run Code Online (Sandbox Code Playgroud) 我有以下C应用程序:
#include <stdio.h>
void smash()
{
int i;
char buffer[16];
for(i = 0; i < 17; i++) // <-- exceeds the limit of the buffer
{
buffer[i] = i;
}
}
int main()
{
printf("Starting\n");
smash();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我使用以下版本的gcc交叉编译:
armv5l-linux-gnueabi-gcc -v
Using built-in specs.
Target: armv5l-linux-gnueabi
Configured with: /home/tarjeif/svn/builder/build_armv5l-linux-gnueabi/gcc-4.4.1/gcc-4.4.1/configure --target=armv5l-linux-gnueabi --host=i486-linux-gnu --build=i486-linux-gnu --prefix=/home/tarjeif/svn/builder/build_armv5l-linux-gnueabi/toolchain --with-sysroot=/home/tarjeif/svn/builder/build_armv5l-linux-gnueabi/toolchain --with-headers=/home/tarjeif/svn/builder/build_armv5l-linux-gnueabi/toolchain/include --enable-languages=c,c++ --with-gmp=/home/tarjeif/svn/builder/build_armv5l-linux-gnueabi/gmp-5.0.0/gmp-host-install --with-mpfr=/home/tarjeif/svn/builder/build_armv5l-linux-gnueabi/mpfr-2.4.2/mpfr-host-install --disable-nls --disable-libgcj --disable-libmudflap --disable-libssp --disable-libgomp --enable-checking=release --with-system-zlib --with-arch=armv5t --with-gnu-as --with-gnu-ld --enable-shared --enable-symvers=gnu --enable-__cxa_atexit --disable-nls --without-fp --enable-threads
Thread model: posix
gcc version …Run Code Online (Sandbox Code Playgroud) 我有这个实现插件架构的C#Visual Studio解决方案.在构建调试版本时,我希望将几个插件编译到主应用程序中.在构建发布版本时,我希望保留这些.cs文件.
有没有办法可以为调试和发布版本的插件文件指定不同的构建操作?我希望它在调试版本中设置为"Compile",在发布版本中设置为"None".
使用gdb,我需要continue在它之前和之后立即运行额外的命令.我以为我会像这样制作用户定义的命令:
define continue
pre_continue
continue
post_continue
end
Run Code Online (Sandbox Code Playgroud)
当然,这在无底的递归坑中失败了.有没有办法直接调用内置命令,绕过用户定义的命令?
BTW:我需要命名命令,continue以便我正在使用的gdb前端将调用我的用户定义函数.
c++ ×3
c ×2
c# ×2
gdb ×2
argparse ×1
c++11 ×1
endianness ×1
gcc ×1
linux ×1
python ×1
reflection ×1
serial-port ×1