It's hard to tell without knowing what "MonoCollection" is.  Your example
using List<int> isn't a good test since:

1. The overload you used to create d3 works on a newly created instance
(see the help docs for that overload).
2. Even if you had used the correct overload, "Count" is not virtual on
List<int> so it wouldn't have worked anyway.

The feature of creating a proxy for a specific target *does* work, but
without knowing the details of the type you're trying to proxy, it's
difficult to say what is going wrong.


---
Patrick Steele
http://weblogs.asp.net/psteele


On Thu, Jan 24, 2013 at 5:04 AM, Vladimir Perevalov <[email protected]>wrote:

> Hi, I'm try to supplement the logic of external type, that I do not
> instantiate.
> I create a proxy like this:
> var pg = new ProxyGenerator();
> var coll = db.GetCollection(collectionName);
> return
> (MongoCollection)pg.CreateClassProxyWithTarget(typeof(MongoCollection),
> coll, new object[] { db, collectionName, coll.Settings }, new
> RetryingInterceptor { RetryCount = retryCount, PauseBetweenCalls =
> pauseBetweenRetries });
>
> But it will return a new instance instead of supplied. Actually, you can
> test this with any simple type:
> var pg = new ProxyGenerator();
>             var d = new List<int> { 1, 2, 3 };
>             var d2 = pg.CreateInterfaceProxyWithTarget((IList<int>)d, new
> TestInterceptor());
>             var d3 = pg.CreateClassProxyWithTarget(d, new
> TestInterceptor());
>
>             Console.WriteLine(d.Count); // write 3
>             Console.WriteLine(d2.Count); // write 3
>             Console.WriteLine(d3.Count); // This will write 0, because new
> instance have been created, instead of supplied one.
> While with the list, I can use approach with interface, in my real code,
> external class does not have any interfaces, so I can't proxy it by
> interface.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/castle-project-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to