473,508 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Proxy

1 5947
David,

It's not a horrible idea, but with the tools that exist today, you can
do this without compiler support. Basically, you can create a tool that
will scan the metadata and create this code for you. If anything, I would
expect to see it in a refactoring.

Also, I'm a little worried about the syntax. It's a little archaic, and
I think would be frowned upon (but that's a personal inference, I could be
very wrong, I'm just going on what I know of the C# team and their way of
thinking).

One problem you don't address is what do you do if the method/property
is not declared as virtual? The methods end up being shadowed, and when you
cast to the base class, your proxy all of a sudden fails to work (and you
lose what you were trying to achieve in the first place).

For something like this, you might want to consider context bound
objects, which allow you to tag your class with attributes, and intercept
the calls that go into and out of the class. Check out the article in MSDN
magazine titled "Decouple Components by Injecting Custom Services into Your
Object's Interception Chain" by Juval Lowy, located at (watch for line
wrap):

http://msdn.microsoft.com/msdnmag/is...contextsinnet/

It should give you a good idea on how to implement something like this
on your own, without having to generate all that code for each proxy class.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Lojudice S." <dalssoft at gmail dot com> wrote in message
news:uj**************@TK2MSFTNGP12.phx.gbl...
Hi,

I've been reading the Design Patterns (Addison-Wesley, 1995) and, on Proxy
chapter, I was thinking how difficult would be if I wanted to do a proxy for
a big class in C#.

Let's get a big class like Control, from System.WinForm. Imagine that I want
to create a proxy for this class to load an inner control (a private
variable) on demand. It could be for others propose, but let use the same
example used on Design Patterns. I want to use the proxy as the parent class
(Control), hiding the logic of loading on demand. The code would be
something like that:

using System;
using System.Windows.Forms;

public class ControlProxy: Control
{
private Control _control;

public override string Text
{
get
{
LoadInnerObject();
return _control.Text + " [by ControlProxy]";
}
}

private void LoadInnerObject()
{
if (_control == null)
_control = new Control("New Control");
}
}

To use ControlProxy:

ControlProxy cp = new ControlProxy();
string controlText;

controlText = cp.Text;

But, if I want a real proxy I have to override all methods, event,
properties, etc. to get ControlProxy accessing _control's variable and its
members, not its own members.

Well, the strange part of this post comes now.

I'm suggesting to create a new keyword on C# to compiler understands it is a
proxy and generates all the code necessary to have a class witch access an
internal variable and its members.

The code with the new keyword would be something like that:

public class ControlProxy: Control proxy[_control]
{
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
17635
by: Fuzzyman | last post by:
In a nutshell - the question I'm asking is, how do I make a socket conenction go via a proxy server ? All our internet traffic has to go through a proxy-server at location 'dav-serv:8080' and I...
2
1447
by: nitrogenycs | last post by:
Hello, I need a way to get a notification whenever a variable of an object changes. The approach should be non-intrusive so that I can use existing objects without modifying them. I want to be...
6
7903
by: harry | last post by:
Hi, I have a program that runs on multiple client pc's. Occasionally one or more of those pc's use VPN to connect to another corporate network. When using VPN they need to set proxy server in...
10
25085
by: Abubakar | last post by:
hi, I work on a computer that is part of a network and uses proxy to connect to net. I cant connect to servers outside my proxy with simple ConnectTo code. I need to know how to make my requests go...
3
9118
by: Codex Twin | last post by:
Hello apologies if this is the wrong newsgroup to be sending this to. Basically, I have an ASP.NET application that I am trying to force to use a proxy server settings. This can be done by...
9
3442
by: Codex Twin | last post by:
I am re-sending this in the hope that it might illicit a response. I have a corporate client who forces their workstations to get the proxy server details using an automatic proxy discovery script....
7
15395
by: Pro1712 | last post by:
Hello, I need to write a simple proxy server. What I want to do is to use HttpListener to get requests from the browser, add some proxy information and some other stuff and send the request to...
7
40938
by: chandru1782 | last post by:
Dear friends, I am trying to use CPAN for installing some perl modules. i am using a ubuntu system, which has internet connection through lan and authenticated proxy. when trying to install...
2
8128
by: =?Utf-8?B?TGVuc3Rlcg==?= | last post by:
A C# (.NET 2) application which uses the System.Net.HttpWebRequest object to request a resource over HTTPS is failing following the installation of a new proxy server on our internal network with...
2
2909
by: | last post by:
Hi all, I have an asp.net 2.0 website that accesses a locally hosted web service. This works fine on servers that are connected to our network. However, I am having a problem with a laptop...
0
7229
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7129
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7333
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7398
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5637
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
428
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.