Enhanced C#
Language of your choice: library documentation

Documentation moved to ecsharp.net

GitHub doesn't support HTTP redirects, so you'll be redirected in 3 seconds.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Nested classes | Properties | Public Member Functions | Static Public Member Functions | List of all members
Loyc.Utilities.GoInterface< Interface, T > Class Template Reference

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. More...


Source file:

Remarks

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.

Type Constraints
Interface :class 

Properties

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...
 

Public Member Functions

delegate Interface GoWrapperCreator (T obj)
 

Static Public Member Functions

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)
 

Member Function Documentation

static void Loyc.Utilities.GoInterface< Interface, T >.DefineCustomWrapperCreator ( GoWrapperCreator  from,
GoWrapperCreator  forceFrom 
)
inlinestatic

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
fromA method to be invoked by From().
forceFromA 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().

static Interface Loyc.Utilities.GoInterface< Interface, T >.ForceFrom ( obj)
inlinestatic

Creates a wrapper regardless of whether or not T could be wrapped completely.

Exceptions
InvalidOperationExceptionThe 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.

static Interface Loyc.Utilities.GoInterface< Interface, T >.From ( obj)
inlinestatic

Creates a wrapper if the interface matches T well.

Exceptions
InvalidCastExceptionT does not match the Interface very well. Specifically, NumberOfUnmatchedMethods>0, NumberOfMethodsMissingParameters>0 or NumberOfMethodsWithRefMismatch>0.
Returns
A pointer to a wrapper that implements the Interface.
static Interface Loyc.Utilities.GoInterface< Interface, T >.From ( obj,
CastOptions  opt 
)
inlinestatic

Creates a wrapper if T matches Interface according to the specified CastOptions.

Returns
A pointer to a wrapper that implements the Interface.

See CastOptions for more information.

Property Documentation

bool Loyc.Utilities.GoInterface< Interface, T >.IsValidInterface
staticget

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.

int Loyc.Utilities.GoInterface< Interface, T >.NumberOfAmbiguousMethods
staticget

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.

int Loyc.Utilities.GoInterface< Interface, T >.NumberOfMethodsMissingParameters
staticget

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

int Loyc.Utilities.GoInterface< Interface, T >.NumberOfMethodsWithRefMismatch
staticget

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.

int Loyc.Utilities.GoInterface< Interface, T >.NumberOfUnmatchedMethods
staticget

The number of methods in the interface for which a matching method in T could not be found.