| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
If a class implements an interface explicitly, you will have to "cast" an object to that interface in order to before invoking its methods. Consider the following C# code:
namespace Example {
interface IExplicit {
int Add(int a, int b);
}
public class ExplicitImpl : IExplicit {
int IExplicit.Add(int a, int b) {
return a + b;
}
}
}The following example demonstrates how to call Add:
from Example import IExplicit, ExplicitImpl
impl = ExplicitImpl()
# Wont work:
impl.Add(1, 2)
# Does work:
ifc = IExplicit(impl)
ifc.Add(1, 2)Python.NET provides two properties for accessing the object implementing the interface:
This is a way to "cast" from an interface to the implementation class.
Here is an example:
import System
clrVal = System.Int32(100)
i = System.IComparable(clrVal)
100 == i.__implementation__ # True
clrVal == i.__raw_implementation__ # True| Back | FazBrowse Home | New Git URL |