473,654 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Proxy

1 5953
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.co m

"David Lojudice S." <dalssoft at gmail dot com> wrote in message
news:uj******** ******@TK2MSFTN GP12.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
17690
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 need to make a socket connection through it. The reason (with code example) is as follows : I am hacking "Tiny HTTP Proxy" by SUZUKI Hisao to make an http proxy that modifies URLs. I haven't got very far - having started from zero knowledge of...
2
1452
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 notified no matter who or what did change the wrapped object - even whenever an object internal methods changes the variables. So I coded the piece of code shown below (just copy and paste it, it's ready-to-run).
6
7923
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 Internet Explorer connection settings (proxy:8080). However, as soon as this setting is enabled, the remoting program running on their pc stops communicating with the server it sends data to. I've disabled proxy setting on the affected pc, rebooted...
10
25113
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 through proxy. eg, _socket = new TcpClient("http://msdn.microsoft.com", port); does not work. Thanx. Ab.
3
9156
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 accessing machine.config, but I do not have access to the client machine.config machine. Therefore every request made from this application must have these proxy server settings. But I am having problems writing the code for this.
9
3445
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. Unfortunately, the .NET Framework does not support automatic proxy discovery scripts. See: http://support.microsoft.com/default.aspx?scid=kb;%5BLN%5D;307220 The article above details that the way to workaround this is to edit the...
7
15419
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 the internet. Then I want to send the answer back to the browser... Sounds simple... But how can I do this?
7
40962
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 cpan.pm , it gives the following error, can any one help, You have no /root/.cpan/sources/MIRRORED.BY I'm trying to fetch one CPAN: LWP::UserAgent loaded ok Fetching with LWP:
2
8158
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 407 Proxy Authentication Required. The same request through the old proxy succeeds. The same request to an HTTP address through the new proxy succeeds. Also, the request succeeds when forced to use Basic authentication but fails on NTLM.
2
2923
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 server that I have built. The code that tries to connect to the web service breaks if the laptop is not within our network. Further debugging has revealed that this is due to a proxy server issue. Our domain sets the proxy server via GPO for all...
0
8372
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7304
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5621
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.