使用十进制值在C#中的属性PARAMS? [英] use decimal values as attribute params in c#?

查看:165
本文介绍了使用十进制值在C#中的属性PARAMS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用十进制值作为PARAMS一个字段属性,但我得到一个编译错误。

I have been trying to use decimal values as params for a field attribute but i get a compiler error.

我发现这个博客帖子链接说这是不可能的在.net中使用的话,没有任何人知道他们为什么选择这个或者我如何使用十进制PARAMS?

I found this blog post link saying it wasn't possible in .Net to use then, does anybody know why they choose this or how can I use decimal params?

感谢。

推荐答案

这是一个CLR限制。只有原始常量或原语的阵列可以用作属性参数。之所以是一个属性必须是连接$ C $在元数据中完全CD。这是一个比一个方法体这是IL codeD不同。使用元数据只严格限制,可以使用的值的范围。在CLR的当前版本中,元数据值仅限于原语,空,类型和数组基元(可能已经错过了一个小的一个)。

This is a CLR restriction. Only primitive constants or arrays of primitives can be used as attribute parameters. The reason why is that an attribute must be encoded entirely in metadata. This is different than a method body which is coded in IL. Using MetaData only severely restricts the scope of values that can be used. In the current version of the CLR, metadata values are limited to primitives, null, types and arrays of primitives (may have missed a minor one).

小数,而基本类型不是基本类型,因此不能重新在元数据psented $ P $其中prevents它从一种属性参数。

Decimals while a basic type are not a primitive type and hence cannot be represented in metadata which prevents it from being an attribute parameter.

这篇关于使用十进制值在C#中的属性PARAMS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆