emh!! it works because the NHibernate3.0 cookbook know the rules of Object
Relational Mapping where:
*A POID should be unique in whole hierarchy, better if it is unique in the
whole domain.*

That is the reason because it works.

public int Sum(int a, int b) { return a + b; }
but if you change the implementation to
public int Sum(int a, int b) { return a; }
it doesn't works.


On Thu, Apr 21, 2011 at 3:41 AM, cremor <[email protected]> wrote:

> Ok, this works, but only because a proxy type can be assigned to an
> entity type. The GetUnproxyType() method doesn't do anything, it
> stills returns the proxy type.
> If you change the Equals to this, it won't work any more:
>
>      public virtual bool Equals(Entity obj) {
>         if (obj == null) {
>            return false;
>         }
>
>         var thisType = GetUnproxyType();
>         var otherType = obj.GetUnproxyType();
>          return thisType.Equals(otherType);
>      }
>
> I'm wondering if that GetUnproxyType() method actually worked with
> Castle or if the Equals() just worked because it uses
> IsAssignableFrom() instead of requiring the types to be exactly equal.
> But ok, you have convinced me that there is no breaking change at run
> time if you don't expect the new default ProxyFactory to be exactly
> like LinFu :-)
>
>
> On Apr 20, 6:47 pm, Fabio Maulo <[email protected]> wrote:
> > Implementation from NHibernate3.0 cookbook
> > public class Entity
> > {
> > private System.Type GetUnproxyType()
> > {
> > return GetType();}
> >
> > public override bool Equals(object obj)
> > {
> > return Equals(obj as Entity);}
> >
> > public virtual bool Equals(Entity obj)
> > {
> > if (obj == null)
> > {
> > return false;}
> >
> > var thisType = GetUnproxyType();
> > var otherType = obj.GetUnproxyType();
> > return thisType.IsAssignableFrom(otherType) ||
> > otherType.IsAssignableFrom(thisType);
> >
> > }
> > }
> >
> > public class Fixturexx
> > {
> > [Test]
> > public void Proxy()
> > {
> > var factory = new ProxyFactory();
> > var c = (Entity)factory.CreateProxy(typeof(Entity), new
> > PassThroughInterceptor(new Entity()), null);
> > c.Equals(new Entity()).Should().Be.True();
> > (new Entity()).Equals(c).Should().Be.True();}
> > }
> >
> > The test pass
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > On Wed, Apr 20, 2011 at 12:31 PM, cremor <[email protected]> wrote:
> > > I don't have code or a compiler available now, but shouldn't the
> > > Equals() in your last example use "obj.GetUnproxyType()" instead of
> > > "obj.GetType()"? Otherwise it will for sure fail if "obj" is a proxy
> > > and "this" is not.
> >
> > > I have tested exactly that case (private method which is called on
> > > "this" and "obj") today and it failed (obj.GetUnproxyType() returned
> > > the proxy type). With a public/protected virtual method it works of
> > > course, because that method is intercepted.
> >
> > > On 20 Apr., 15:56, Fabio Maulo <[email protected]> wrote:
> > > > I think that you are making too many suppositions instead try it.
> > > > 1) LinFu is not the embedded DynProxy. It was the start point, but as
> > > some
> > > > committer known ;), was not a matter of just copy&paste
> > > > 2) LinFu and the embedded DynProxy... well... code
> > > > protected virtual System.Type GetUnproxyType()
> > > > {
> > > > return GetType();}
> >
> > > > public virtual System.Type GetMyType()
> > > > {
> > > > return GetUnproxyType();
> >
> > > > }
> >
> > > > Console.WriteLine(proxy.GetMyType()); <= returns the correct type
> >
> > > > Other
> > > > private System.Type GetUnproxyType()
> > > > {
> > > > return GetType();}
> >
> > > > public virtual System.Type GetMyType()
> > > > {
> > > > return GetUnproxyType();}
> >
> > > > Returns the correct type
> >
> > > > Other
> > > > private System.Type GetUnproxyType()
> > > > {
> > > > return GetType();}
> >
> > > > public override bool Equals(object obj)
> > > > {
> > > > return GetUnproxyType() == obj.GetType();
> >
> > > > }
> >
> > > > var factory = new ProxyFactory();
> > > > var c =
> >
> > >
> (ClassWithVarietyOfMembers)factory.CreateProxy(typeof(ClassWithVarietyOfMembers),
> > > > new PassThroughInterceptor(new ClassWithVarietyOfMembers()), null);
> > > > c.Equals(new ClassWithVarietyOfMembers()).Should().Be.True();
> > > > Pass the test
> >
> > > > On Wed, Apr 20, 2011 at 10:18 AM, cremor <[email protected]> wrote:
> > > > > Seems like I mixed up some things here, sorry about that.
> > > > > The NHibernate 3.0 Cookbook uses a private method. I have never
> tried
> > > > > that, maybe it worked with Castle. If yes it's a possible breaking
> > > > > change.
> > > > > The Sharp-Architecture code uses a protected virtual method. That
> > > > > worked with Castle (and maybe Spring) but didn't work with LinFu
> > > > > (because LinFu didn't proxy protected methods). I assume most
> people
> > > > > don't even know that LinFu didn't proxy protected methods, so no
> need
> > > > > to mention this as breaking change.
> >
> > > > > But I still think that the new default ProxyFactory should be more
> > > > > visible in the release notes than a short line between all those
> other
> > > > > improvements ;-)
> >
> > > > > On Apr 20, 2:33 pm, Fabio Maulo <[email protected]> wrote:
> > > > > > This method works
> > > > > > public virtual System.Type GetUnproxyType()
> > > > > > {
> > > > > > return GetType();
> >
> > > > > > }
> > > > > > On Wed, Apr 20, 2011 at 9:25 AM, cremor <[email protected]> wrote:
> > > > > > > Compile time: There is no NHibernate.ByteCode.*.dll any more so
> the
> > > > > > > reference to it and the NHibernate configuration for it is
> invalid.
> > > > > > > Run time: Possible breaking change if you switch from Castle to
> new
> > > > > > > internal ProxyFactory and use the GetUnproxiedType() trick I
> > > explained
> > > > > > > above.
> >
> > > > > > > On Apr 20, 2:16 pm, Fabio Maulo <[email protected]> wrote:
> > > > > > > > but, which is the breaking change ?
> >
> > > > > > > > On Wed, Apr 20, 2011 at 9:06 AM, cremor <[email protected]>
> wrote:
> > > > > > > > > Yeah, I saw that. But I meant that it's not listed under
> > > breaking
> > > > > > > > > changes at the top of the file.
> >
> > > > > > > > > On Apr 20, 1:53 pm, Fabio Maulo <[email protected]>
> wrote:
> > > > > > > > > > In release notes
> > > > > > > > > > ** Improvement
> > > > > > > > > >     * [NH-2586] - Default ProxyFactory
> >
> > > > > > > > > > On Wed, Apr 20, 2011 at 7:34 AM, cremor <[email protected]>
> > > wrote:
> > > > > > > > > > > Wouldn't it be a good idea if the breaking change to
> the
> > > > > > > ProxyFactory
> > > > > > > > > > > would be mentioned in the release notes? It's quite a
> big
> > > > > change
> > > > > > > that
> > > > > > > > > > > you don't need (and have) that seperate assemblies any
> more
> > > by
> > > > > > > > > > > default.
> >
> > > > > > > > > > > And there is not only the compile time breaking change.
> If
> > > you
> > > > > have
> > > > > > > > > > > previously used Castle and your entities use the quite
> > > common
> > > > > > > > > > > GetUnproxiedType() trick (e.g. from Sharp-Architecture
> or
> > > the
> > > > > > > > > > > NHibernate 3.0 Cookbook), there will be a bug in your
> code
> > > if
> > > > > you
> > > > > > > > > > > switch to the new default ProxyFactory (because that
> > > > > > > > > > > GetUnproxiedType() trick doesn't work with it, like it
> > > didn't
> > > > > work
> > > > > > > > > > > with LinFu and Spring).
> >
> > > > > > > > > > --
> > > > > > > > > > Fabio Maulo
> >
> > > > > > > > --
> > > > > > > > Fabio Maulo
> >
> > > > > > --
> > > > > > Fabio Maulo
> >
> > > > --
> > > > Fabio Maulo
> >
> > --
> > Fabio Maulo
>



-- 
Fabio Maulo

Reply via email to