GoInterface<Interface,T> creates a wrapper that implements the specified Interface, forwarding calls to methods in T. It is inspired by the duck-typed interfaces in the Go programming language.
Please see GoInterface{Interface} for more information.
|
static bool | IsValidInterface [get] |
| If this value is false, Interface is not valid and ForceFrom will throw InvalidOperationException if called. In that case, the other values such as NumberOfUnmatchedMethods are zero, but have no meaning. More...
|
|
static int | NumberOfUnmatchedMethods [get] |
| The number of methods in the interface for which a matching method in T could not be found. More...
|
|
static int | NumberOfAmbiguousMethods [get] |
| The number of methods in the interface for which a matching method in T could not be found because T contained more than one equally suitable match. More...
|
|
static int | NumberOfMethodsMissingParameters [get] |
| The number of methods in the interface that were matched to a method in T with one or more parameters dropped. For instance, if a method in the interface takes two ints but T's method only takes one int, the second int of More...
|
|
static int | NumberOfMethodsWithRefMismatch [get] |
| The number of methods in the interface that were matched to a method in T, in which there was a mismatch that one parameter was passed by reference ("ref") and the other was passed by value. More...
|
|
|
static Interface | ForceFrom (T obj) |
| Creates a wrapper regardless of whether or not T could be wrapped completely. More...
|
|
static Interface | From (T obj) |
| Creates a wrapper if the interface matches T well. More...
|
|
static Interface | From (T obj, CastOptions opt) |
| Creates a wrapper if T matches Interface according to the specified CastOptions. More...
|
|
static void | DefineCustomWrapperCreator (GoWrapperCreator from, GoWrapperCreator forceFrom) |
| Defines a custom wrapper class for the type pair (Interface, T). If you want to install a custom wrapper, you must do so before From() or ForceFrom() is ever called on this pair of types, otherwise an exception is thrown. Also, you cannot call this method twice on the same pair of types. More...
|
|
static int | GetMatchingParameterCount (ParameterInfo[] argsI, ParameterInfo[] argsT, out int refMismatches, out int missingParams) |
|
Defines a custom wrapper class for the type pair (Interface, T). If you want to install a custom wrapper, you must do so before From() or ForceFrom() is ever called on this pair of types, otherwise an exception is thrown. Also, you cannot call this method twice on the same pair of types.
- Parameters
-
from | A method to be invoked by From(). |
forceFrom | A method to be invoked by ForceFrom(). |
Since generating a wrapper is expensive and the wrapper cannot be garbage-collected, I decided to make sure you don't waste time and memory generating a wrapper you don't intend to use, by restricting this method only to be used on type pairs that have never been used before. Make sure you call this method as soon as possible, before anybody calls From() or ForceFrom().
Creates a wrapper regardless of whether or not T could be wrapped completely.
- Exceptions
-
InvalidOperationException | The Interface is not valid (e.g. it is not public or is not abstract) |
GoInterface maps methods in certain cases where you might not want it to–for example, if the Interface takes two ints and T only takes one, GoInterface maps one to the other by omitting the second parameter. To accept these mappings, call ForceFrom(T) or From(T, CastOptions.AllowMissingParams | CastOptions.AllowRefMismatch); to reject them, call From(T).
ForceFrom always creates a wrapper, even if some methods of Interface couldn't be matched with T at all. If you then call a method that couldn't be wrapped, you'll get a MissingMethodException.
If this value is false, Interface is not valid and ForceFrom will throw InvalidOperationException if called. In that case, the other values such as NumberOfUnmatchedMethods are zero, but have no meaning.
Calling this property or any of the "int" properties forces the wrapper class to be generated, during which the relationship between Interface and T is analyzed.