Pass enum value to method which is called by dynamic object

Posted by user329588 on Stack Overflow See other posts from Stack Overflow or by user329588
Published on 2010-04-30T08:22:04Z Indexed on 2010/04/30 8:27 UTC
Read the original article Hit count: 366

Filed under:
|
|
|

hello.

I'm working on program which dynamically(in runtime) loads dlls.
For an example: Microsoft.AnalysisServices.dll.

In this dll we have this enum:
namespace Microsoft.AnalysisServices
{
[Flags]
public enum UpdateOptions
{
Default = 0,
ExpandFull = 1,
AlterDependents = 2,
}
}
and we also have this class Cube:
namespace Microsoft.AnalysisServices
{
public sealed class Cube : ...
{
public Cube(string name);
public Cube(string name, string id); ..
..
..
}
}

I dynamically load this dll and create object Cube. Than i call a method Cube.Update(). This method deploy Cube to SQL Analysis server. But if i want to call this method with parameters Cube.Update(UpdateOptions.ExpandFull) i get error, because method doesn't get appropriate parameter.

I have already tried this, but doesn't work:
dynamic updateOptions = AssemblyLoader.LoadStaticAssembly("Microsoft.AnalysisServices", "Microsoft.AnalysisServices.UpdateOptions");//my class for loading assembly
Array s = Enum.GetNames(updateOptions);
dynamic myEnumValue = s.GetValue(1);//1 = ExpandFull
dynamicCube.Update(myEnumValue);// == Cube.Update(UpdateOptions.ExpandFull)

I know that error is in parameter myEnumValue but i don't know how to get dynamically enum type from assembly and pass it to the method. Does anybody know the solution?

Thank you very much for answers and help!

© Stack Overflow or respective owner

Related posts about c#

Related posts about dynamic