C#技术 - 按字符串获取常量值

Bud*_*Joe 3 .net c# excel vsto constants

有没有什么好的方法可以将像"xlSum","xlAverage"和"xlCount"这样的字符串转换为它们在Microsoft.Office.Interop.Excel.XlConsolidationFunction下的值?

我想反射会很慢(如果可能的话).这些常数值大约有10个.如果可能的话,我试图避免使用大的switch语句.

tva*_*son 5

这是一个枚举,所以你应该可以使用

using Microsoft.Office.Interop.Excel;

XlConslidationFunction func = (XlConsolidationFunction)
                               Enum.Parse( typeof(XlConsolidationFunction),
                                           stringVal );
Run Code Online (Sandbox Code Playgroud)