相关疑难解决方法(0)

将类型作为参数传递给属性

我写了一个有点通用的反序列化机制,它允许我从C++应用程序使用的二进制文件格式构造对象.

为了保持清洁和易于更改,我创建了一个Field扩展的类,Attribute构造Field(int offset, string type, int length, int padding)并应用于我希望反序列化的类属性.这是它的样子:

[Field(0x04, "int")]
public int ID = 0;

[Field(0x08, "string", 0x48)]
public string Name = "0";

[Field(0x6C, "byte", 3)]
public byte[] Color = { 0, 0, 0 };

[Field(0x70, "int")]
public int BackgroundSoundEffect = 0;

[Field(0x74, "byte", 3)]
public byte[] BackgroundColor = { 0, 0, 0 };

[Field(0x78, "byte", 3)]
public byte[] BackgroundLightPower = { 0, 0, 0 };

[Field(0x7C, "float", 3)]
public float[] BackgroundLightAngle = …
Run Code Online (Sandbox Code Playgroud)

c# generics custom-attributes

9
推荐指数
1
解决办法
6775
查看次数

标签 统计

c# ×1

custom-attributes ×1

generics ×1