ClassPrivateAccessor
Gives access to the non-public members of a type or instance. This class provides functionality similar to the one that exists in regular reflection classes with the added benefit that it can bypass essential security checks related to accessing non-public members through reflection.
Definition
Namespace:Telerik.JustMock
Assembly:Telerik.JustMock.dll
Syntax:
public sealed class PrivateAccessor : IDynamicMetaObjectProvider
Inheritance: objectPrivateAccessor
Implements:
Constructors
PrivateAccessor(object)
Creates a new PrivateAccessor wrapping the given instance. Can be used to access both instance and static members.
Declaration
public PrivateAccessor(object instance)
Parameters
instance
The instance to wrap.
Properties
Instance
The wrapped instance.
RefReturn
Non public ref return interface for mocking.
Declaration
public IPrivateRefReturnAccessor RefReturn { get; }
Property Value
RethrowOriginalOnCallMethod
Controls whether TargetInvocationException will be thrown, this is the default behavior, or the original exception when an exception occur on using one of the CallMethod overloads.
Declaration
public bool RethrowOriginalOnCallMethod { get; set; }
Property Value
Methods
CallMethod(MethodBase, params object[])
Calls the specified method.
Declaration
public object CallMethod(MethodBase method, params object[] args)
Parameters
method
The method to call.
args
object[]
Arguments to pass to the method.
Returns
Return value of the method.
CallMethod(string, ICollection<Type>, ParameterModifier, object[])
Calls the specified method by name and given argument types and values.
Declaration
public object CallMethod(string name, ICollection<Type> argTypes, ParameterModifier argModifiers, object[] argValues)
Parameters
name
The name of the method to call.
argTypes
The method argument types.
argModifiers
The argument type modifiers, such as out and ref.
argValues
object[]
The argument values to pass to the method.
Returns
The value returned by the specified method.
CallMethod(string, ICollection<Type>, object[])
Calls the specified method by name and given argument types and values.
Declaration
public object CallMethod(string name, ICollection<Type> argTypes, object[] argValues)
Parameters
name
The name of the method to call.
argTypes
The method argument types.
argValues
object[]
The argument values to pass to the method.
Returns
The value returned by the specified method.
CallMethod(string, params object[])
Calls the specified method by name.
CallMethodWithTypeArguments(string, ICollection<Type>, params object[])
Calls the specified generic method by name.
Declaration
public object CallMethodWithTypeArguments(string name, ICollection<Type> typeArguments, params object[] args)
Parameters
name
The name of the method to call.
typeArguments
The type arguments to specialize the generic method.
args
object[]
Arguments to pass to the method.
Returns
The value returned by the specified method.
CallStaticConstructor(bool)
Calls the type's static constructor. The static constructor can be executed even when the runtime has already called it as part of type's initialization.
Declaration
public void CallStaticConstructor(bool forceCall)
Parameters
forceCall
When 'false', the static constructor will not be called if it has already run as part of type initialization. When 'true', the static constructor will be called unconditionally. If the type is not yet initialized and 'true' is given, the static constructor will be run twice.
ForType(Type)
Creates a new PrivateAccessor wrapping the given type. Can be used to access the static members of a type.
Declaration
public static PrivateAccessor ForType(Type type)
Parameters
type
Targeted type.
Returns
PrivateAccessor type.
GetField(string)
Gets the value of a field.
GetIndex(object)
Gets the value returned by the indexer (
this[T index] in C#) for the specified index value.GetMember(string)
Gets the value of a field or property.
GetProperty(string, params object[])
Gets the value of a property by name.
RaiseEvent(string, params object[])
Raises the specified event passing the given arguments to the handlers.
SetField(string, object)
Sets the value of a field.
SetIndex(object, object)
Sets a value to the indexer (
this[T index] in C#) for the specified index value.SetMember(string, object)
Sets the value of a field or property.
SetProperty(string, object, params object[])
Sets the value of a property by name.
Unwrap(dynamic)
Gets the value of a dynamic private accessor expression. Use this when the value to get is of type Object, otherwise cast the expression to the desired type.
Declaration
public static object Unwrap(dynamic privateAccessor)
Parameters
privateAccessor
dynamic
A PrivateAccessor expression built from a dynamic variable.
Returns
The value of the private accessor expression