我正在尝试使用自定义异常类型执行一些序列化/反序列化的东西.此类型的字段定义为:
private object[] resourceMessageParams;
我有一些很好的和强类型的代码与一些Linq表达魔术,但我想更进一步,并做这样的事情:
using ResourceMessageParamsType = object[];//<-- "Identifier expected" error here /*...*/ private ResourceMessageParamsType resourceMessageParams; /*...*/ this.resourceMessageParams = (ResourceMessageParamsType)serializationInfo.GetValue( ReflectionHelper.GetPropertyNameFromExpression(() => resourceMessageParams),typeof(ResourceMessageParamsType));
而不是这个:
(object[])serializationInfo.GetValue( ReflectionHelper.GetPropertyNameFromExpression(() => resourceMessageParams),typeof(object[]));
为了适应将来可能更改此字段的类型,因此必须在别名定义中仅更改一次类型.但是,编译器在使用ResourceMessageType = object []时停止在对象;抱怨预计会有一个标识符.更改为Object []有所帮助,但这次括号突出显示相同的错误消息.
有没有办法在c#中为数组类型定义别名?