The error message might be more clear:
CLR protected method `unit_of_work_scope'' called for
MediaAggregator.Models.Lightspeed.AggregatorRepository:MediaAggregator::Models::Lightspeed::AggregatorRepository;
CLR protected methods can only be called with a receiver whose class is a Ruby
subclass of the class declaring the method
You need to derive a Ruby class from the CLR class and use its instance to call
the method. What we need to do internally is emit a CLR subtype of the CLR type
that proxies protected method calls coming from Ruby code. When you monkey-patch
a CLR method it doesn?t mean you are ?in the type?. You are still outside of the
type, so you still have the same visibility restrictions on CLR members as if
they were called from any other Ruby/CLR method. IronRuby just overlays Ruby
methods over the CLR type, it cannot ?open? the type.
Tomas
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Ivan Porto Carrero
Sent: Tuesday, June 09, 2009 12:28 PM
To: ironruby-core
Subject: [Ironruby-core] CLR interop bug?
Hi
What is the nitty gritty around monkey patching CLR classes. When I''m
monkey patching I should be able to get to the protected members of a class
right? And the private members too (I see it kind of like partial classes)?
public class AggregatorRepository :
RepositoryBase<MediaAggregatorModelUnitOfWork>
{
public
AggregatorRepository(UnitOfWorkScopeBase<MediaAggregatorModelUnitOfWork>
unitOfWorkScope) : base(unitOfWorkScope)
{
}
//Some C# methods here that use Linq and Expressions for querying
}
Repository base defines a protected property UnitOfWorkScope
I monkey patched it like so
module MediaAggregator
module Models
module Lightspeed
class AggregatorRepository
def users
uow.method(:find).of(User).call
end
def uow
self.unit_of_work_scope.current
end
end
end
end
end
Calling the users method result in an error complaining about a protected
unit_of_work_scope method. And ironically the error talks about my situation as
being the solution:
CLR protected method `unit_of_work_scope'' called for
MediaAggregator.Models.Lightspeed.AggregatorRepository:MediaAggregator::Models::Lightspeed::AggregatorRepository;
CLR protected methods can only be called with a receiver whose class is a
subclass of the class declaring the method
Do I put this on codeplex or am I reading the error wrong? As far as I can tell
I am subclassing a class.
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20090609/f1d2dad6/attachment.html>