Dynamic invoking and enumerations and indexes

Hi

I've been able to dynamically create instances then invoke methods and properties of those instances using classes using the 2.0 framework.

For example ..

ObjectHandle objectHandle = Activator.CreateInstance("Microsoft.SqlServer.Smo, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91", "Microsoft.SqlServer.Management.Smo.Index", new object[] { tableInstance, "NewIndex" } );
object instance = objectHandle.Unwrap();
Type instanceType = instance.GetType();
PropertyInfo propertyInfo = indexInstanceType.GetProperty("Clustered");
propertyInfo.SetValue(instance, true, null);

The above code is the same as ...

Index index = new Index(table, "NewIndexName);
index.Clustered = true;

 

The only problem is that I have been unable to determine how to set then compare an enumeration as in the following code.

index.IndexKeyType = IndexKeyType.DriPrimaryKey;
if (index.IndexKeyType == IndexKeyType.DriPrimaryKey)
{
  Console.Write("AOK");
}

 

Could someone please let me know how to do this.

Thanks

 

 

 

 

 



Answer this question

Dynamic invoking and enumerations and indexes

  • Greg Roberts

    Hi

    Could you please provide a code sample

    Thanks

  • Jimvh28

    You would have to search by enumeration member name if you wanted to compare similarly to your sample code. Otherwise you'd have to know the actual int value and compare values.

  • Dynamic invoking and enumerations and indexes