Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#反射:发出日期时间属性值_C#_Datetime_Reflection.emit - Fatal编程技术网

C#反射:发出日期时间属性值

C#反射:发出日期时间属性值,c#,datetime,reflection.emit,C#,Datetime,Reflection.emit,我目前正在使用Reflection.Emit生成动态类型 我有我需要的大部分工作,但是需要在构造函数中设置默认属性值 到目前为止,我已经通过使用例如(为简洁起见,减少)来实现对整数和字符串的处理: Emit(OpCodes.Ldstr,“Hello World”); ctorDefaultIL.Emit(opcode.Ldc_I4,42); 这非常有效,我的问题是如何设置日期时间值。感谢@leppie提供未来参考这是我最终使用的代码。 对于某些上下文,这将被传递到另一个方法: ctorD

我目前正在使用Reflection.Emit生成动态类型

我有我需要的大部分工作,但是需要在构造函数中设置默认属性值

到目前为止,我已经通过使用例如(为简洁起见,减少)来实现对整数和字符串的处理:


Emit(OpCodes.Ldstr,“Hello World”);


ctorDefaultIL.Emit(opcode.Ldc_I4,42);


这非常有效,我的问题是如何设置日期时间值。

感谢@leppie提供未来参考这是我最终使用的代码。 对于某些上下文,这将被传递到另一个方法:

ctorDefaultIL.Emit(OpCodes.Ldc_I8, dateVal.Ticks);
ctorDefaultIL.Emit(OpCodes.Newobj, 
  typeof(DateTime).GetConstructor(new[] { typeof(long) }));

发出对构造函数的调用。将您的解决方案作为答案发布。然后将其标记为解决方案:)你找到了答案,你应该得到代表:p