[英]dynamically adding an array to a resource in run time
I have a custom ODataResourceSerializer
which under some conditions adds new properties to a resource, that works perfectly. 我有一个自定义的
ODataResourceSerializer
,它在某些条件下为资源添加了新的属性,完美地工作。
I am trying to add a new simple int[] property 我想添加一个新的简单int []属性
the resource is a dynamic resource that is registered at runtime and does not have these properties on the model. 资源是在运行时注册的动态资源,在模型上没有这些属性。
this code 这段代码
case TypeX tx:
propertiesToReturn.Add(new ODataProperty()
{
Name = "TypeX",
Value = new ODataCollectionValue()
{
Items = new int[] {1,2,3}
}
});
gives me whrn the resource is sent to the ODataJsonLightPropertySerializer.WriteCollectionProperty
给我的资源发送到
ODataJsonLightPropertySerializer.WriteCollectionProperty
A type named 'System.Int32[]' could not be resolved by the model.
模型无法解析名为“System.Int32 []”的类型。 When a model is available, each type name must resolve to a valid type.
当模型可用时,每个类型名称必须解析为有效类型。
and when trying to add the value directly to the odata property 并尝试将值直接添加到odata属性时
new ODataProperty()
{
Value = new int[] { 1, 2, 3 }
}
I get on add 我继续补充
An ODataPrimitiveValue was instantiated with a value of type 'System.Int32[]'.
使用类型为“System.Int32 []”的值实例化ODataPrimitiveValue。 ODataPrimitiveValue can only wrap values which can be represented as primitive EDM types
ODataPrimitiveValue只能包装可以表示为原始EDM类型的值
I tried adding int[] to the model builder I tried adding a type to the ODataCollectionValue 我尝试将int []添加到模型构建器中,我尝试将类型添加到ODataCollectionValue
solved using ODataUntypedValue
and serializing the value according to the return type "XML/JSON" 使用
ODataUntypedValue
解决并根据返回类型“XML / JSON”序列化值
for example 例如
Value = new ODataUntypedValue
{
RawValue = JsonConvert.SerializeObject(new int[] { 1, 2, 3 })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.