Hallo,
das kann man auch unter .Net ohne Probleme

Hier ein Beispiel mit Transparent Proxies:
|
csharp Code:
|
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
| using System.Collections.Generic; using System.Diagnostics; using IMethodCallMessage = System.Runtime.Remoting.Messaging.IMethodCallMessage; using RealProxy = System.Runtime.Remoting.Proxies.RealProxy; using ReturnMessage = System.Runtime.Remoting.Messaging.ReturnMessage; namespace De.Tutorials.Training public class DynamicProxyExample public static void Main(string[] args) IDataModel <string> simpleDataModel = (IDataModel <string>)new DataModelProxy (typeof(IDataModel <string>)). GetTransparentProxy(); simpleDataModel.Data = "Bubu"; Console. WriteLine(simpleDataModel is IDataModel <string>); Console.WriteLine(simpleDataModel.Data); Console.WriteLine(simpleDataModel.GetType().FullName); IDataModel <IDataModel <string>> wrappedDataModel = (IDataModel <IDataModel <string>>)new DataModelProxy (typeof(IDataModel <IDataModel <string>>)). GetTransparentProxy(); wrappedDataModel.Data = simpleDataModel; Console.WriteLine("####"); Console. WriteLine(wrappedDataModel is IDataModel <IDataModel <string>>); Console.WriteLine(wrappedDataModel.Data == null); Console.WriteLine(wrappedDataModel.Data.Data); Console.WriteLine(wrappedDataModel.GetType().FullName); public class DataModelProxy : RealProxy IDictionary<string, object> propertyDictionary; public DataModelProxy(Type type) this. propertyDictionary = new Dictionary <string, object>(); public override System.Runtime.Remoting.Messaging.IMessage Invoke(System.Runtime.Remoting.Messaging.IMessage aMessage) IMethodCallMessage methodInvocationMessage = (IMethodCallMessage)aMessage; if (methodInvocationMessage.MethodName.Equals("GetType")) return new ReturnMessage (this. GetType(), null, 0, methodInvocationMessage. LogicalCallContext, methodInvocationMessage ); if (methodInvocationMessage.MethodName.StartsWith("set_")) string propertyName = GetPropertyNameFor(methodInvocationMessage.MethodName); this.propertyDictionary[propertyName] = methodInvocationMessage.Args[0]; return new ReturnMessage (methodInvocationMessage. Args[0], null, 0, methodInvocationMessage. LogicalCallContext, methodInvocationMessage ); else if (methodInvocationMessage.MethodName.StartsWith("get_")) string propertyName = GetPropertyNameFor(methodInvocationMessage.MethodName); if (this.propertyDictionary.ContainsKey(propertyName)) return new ReturnMessage (this. propertyDictionary[propertyName ], null, 0, methodInvocationMessage. LogicalCallContext, methodInvocationMessage ); return new ReturnMessage (null, null, 0, methodInvocationMessage. LogicalCallContext, methodInvocationMessage ); return new ReturnMessage (null, null, 0, methodInvocationMessage. LogicalCallContext, methodInvocationMessage ); private string GetPropertyNameFor(string propertyName) return propertyName.Substring(4); public interface IDataModel<TData>
|
|
Witzig, dass man nach und nach die Java Jünger im .Net Teich plantschen sieht...

Aber wie gesagt, es ist wichtig beides zu kennen!
Es gibt natürlich zahlreiche andere Möglichkeiten Dynamic Proxies zu erzeugen. Transparent Proxies sind ziemlich schwer zu debuggen, da man oft die Meldung bekommt, dass das Objekt nicht ausgewertet werden kann, da es sich um einen Remote Proxy handelt... hab die genaue Meldung nicht mehr im Kopf.
Eine Alternative zu den ätzenden transpoarent Remoting Proxies sind beispielsweise Castles Dynamic Proxies, Springs Dynamic Proxies oder eigene Proxies mit System.Reflection.Emit (machen wir in der Firma auch selbst... und die kann man sogar ordentlich Debuggen

)
Schau mal hier:
http://www.tutorials.de/forum/net-ap...c-proxies.html
http://www.tutorials.de/forum/net-ap...pring-net.html
Gruß Tom