Forum Discussion

amarr1143l's avatar
amarr1143l
Contributor
11 years ago

Specify multiple BindingFlags in GetMethods_2

Hi,



I am trying to specify multiple constraints on BindingFlags of GetMethods_2 method.



In c#, multiple BindingFlags are separated using "|" character. However, in TC when I try to do the same, it throws an error stating "Invalid Character"



Please advise.
  • Hi Amar,



    You can create a set of flags using Enum.Parse:

    Set objEnumType = dotNET.System_Reflection.BindingFlags.Public.GetType

    Set objFlags = dotNET.System.Enum.Parse(objEnumType, "Public,Instance,DeclaredOnly")



    Set objMethods = objClass.GetMethods_2(objFlags)
  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)
    Hi Amar,



    You can create a set of flags using Enum.Parse:

    Set objEnumType = dotNET.System_Reflection.BindingFlags.Public.GetType

    Set objFlags = dotNET.System.Enum.Parse(objEnumType, "Public,Instance,DeclaredOnly")



    Set objMethods = objClass.GetMethods_2(objFlags)
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Amar,



    '|' in C# is a bitwise Or operation.

    Use the relevant operation of the script language you are using for your tests.
  • Tried it, still no luck.



    Set objMethods = objClass.GetMethods_2(dotnet.System_Reflection.BindingFlags.Public Or dotnet.System_Reflection.BindingFlags.Instance Or dotnet.System_Reflection.BindingFlags.DeclaredOnly)



    Error:

    Type mismatch: '[string: "Public"]'