共用方式為


PrivateObject.Invoke Method (String, BindingFlags, array<Object )

Used to access the members of the private object.

Namespace:  Microsoft.VisualStudio.TestTools.UnitTesting
Assembly:  Microsoft.VisualStudio.QualityTools.UnitTestFramework (in Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll)

Syntax

'Declaration
Public Function Invoke ( _
    name As String, _
    bindingFlags As BindingFlags, _
    ParamArray args As Object() _
) As Object
public Object Invoke(
    string name,
    BindingFlags bindingFlags,
    params Object[] args
)
public:
Object^ Invoke(
    String^ name, 
    BindingFlags bindingFlags, 
    ... array<Object^>^ args
)
member Invoke : 
        name:string * 
        bindingFlags:BindingFlags * 
        args:Object[] -> Object
public function Invoke(
    name : String, 
    bindingFlags : BindingFlags, 
    ... args : Object[]
) : Object

Parameters

  • name
    Type: String

    The name of the member to invoke.

  • bindingFlags
    Type: BindingFlags
  • args
    Type: array<Object[]

    Any arguments that the member requires.

Return Value

Type: Object
An object that represents the return value of a private member.

Remarks

If the private member does not return a reference or value, then this method will not return an object.

You might want your test to decide at runtime which method to invoke. To do this, you can use BindingFlags with the invokeAttr parameter. This lets you search for a type with a specific name or by using modifiers such as static, public, internal, and private, or combinations of modifiers. You can use a set of binding flags to find the method that you want to invoke.

.NET Framework Security

See Also

Reference

PrivateObject Class

Invoke Overload

Microsoft.VisualStudio.TestTools.UnitTesting Namespace