将CustomAttributeTypedArguement转换为数组

时间:2015-10-06 15:49:39

标签: c# attributes type-conversion

我在自定义属性中有一个数组值。该属性如下所示:

if (!any_list.size)

最终使用relection我得到了BusinessTypes的值,如下所示:

[ValidationTag(EntityPropertyName = "DateOfBirth" , HasBusinessLogic = true, BusinessTypes = new []{"D", "1", "P"})]

然后,我转换为IEnumerable并通过itterate来添加到列表中。

var businessTypeArrayValue = (attr.NamedArguments[2].TypedValue);

这会将数据转换为列表 - 但问题是列表中的值如下所示:

var businessTypeArray = (businessTypeArrayValue.Value) as IEnumerable;

if (businessTypeArray != null)
{
   businessTypeList.AddRange(from object businessType in businessTypeArray select businessType.ToString().Trim());
}

应该是:

 "/"D/"" 

我有关于如何删除多余字符的想法,但我认为我不应该在转换上做任何其他事情。所以问题是,我怎样才能进行转换而不是以额外的字符结束。

谢谢

0 个答案:

没有答案