How to get an enum value from an assembly using late binding in C#

Posted by tetranz on Stack Overflow See other posts from Stack Overflow or by tetranz
Published on 2010-06-17T20:48:42Z Indexed on 2010/06/17 20:53 UTC
Read the original article Hit count: 268

Filed under:
|

Hello

I have a C# 3.0 WinForms application which is occasionally required to control Excel with automation. This is working nicely with normal early binding but I've had some problems when people don't have Excel installed but still want to use my app except for the Excel part. Late binding seems to be a solution to this. Late binding is rather tedious in C# 3 but I'm not doing anything particularly difficult. I'm following http://support.microsoft.com/kb/302902 as a starter and it's working out well.

My question is how can I use an enum by name?

e.g, how can I use reflection to get the value of Microsoft.Office.Interop.Excel.XlFileFormat.xlTextWindows so that I can use it an InvokeMethod call?

I know the easiest way is probably to create my own local enum with the same "magic" integer value but it would be nicer to be able to access it by name. The docs often don't list the value so to get it I probably need to have a little early bound test app that can tell me the value.

Thanks

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection