c# - overloading explicit CAST operator with user-defined interface parameter -



c# - overloading explicit CAST operator with user-defined interface parameter -

at these given classes

[activerecord] public class basemoo : activerecordbase [activerecord] public class foo : basemoo { }

somewhere in code do

var fooobj = new foo(); // fooobj basemoo obj = fooobj;

here seek cast

var newfooobj = (foo)obj; // , goes

if changes classes this:

[activerecord(lazy=true)] public class basemoo : activerecordbase [activerecord(lazy=true)] public class foo : basemoo { }

making lazyest @ these lines:

var fooobj = new foo(); // fooobj basemoo obj = fooobj;

the ar creates non foo instance instead basemooproxy object

var newfooobj = (foo)obj; // throws invalidcast exception

as sugested @adam houldsworth in this question

i overloads foo explicit operator in way

public static explicit operator foo(nhibernate.proxy.inhibernateproxy nhproxy) { var resultobj = (foo)nhproxy.insomewayigettheoriginalobject(); // insomewayigettheoriginalobject() not real method, simplify homecoming resultobj; }

but error in operator overload parameter

nhibernate.proxy.inhibernateproxy nhproxy user-defined conversion interface

question:

how can explicit convert basemooproxy (nhibernate.proxy.inhibernateproxy) foo?

as know it's not possible overloads "is" operator, there way work "obj foo" ?

as consumer application 3th part client it's not possible changes way how application casts classes objects.

thanks in advance.

c# nhibernate casting proxy overloading

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -