// // System.Runtime.Remoting.Messaging.CADMessages.cs // // Author: // Patrik Torstensson // // (C) Patrik Torstensson // // // Copyright (C) 2004 Novell, Inc (http://www.novell.com) // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // using System; using System.Collections; using System.IO; using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Remoting; using System.Runtime.Remoting.Channels; using System.Runtime.Remoting.Messaging; using System.Runtime.Remoting.Proxies; namespace System.Runtime.Remoting.Messaging { internal class CADArgHolder { public int index; public CADArgHolder (int i) { index = i; } } internal class CADObjRef { ObjRef objref; public int SourceDomain; public CADObjRef (ObjRef o, int sourceDomain) { objref = o; SourceDomain = sourceDomain; } public string TypeName { get { return objref.TypeInfo.TypeName; } } public string URI { get { return objref.URI; } } } internal class CADMessageBase { protected object [] _args; protected byte [] _serializedArgs = null; protected int _propertyCount = 0; protected CADArgHolder _callContext; internal RuntimeMethodHandle MethodHandle; internal string FullTypeName; internal MethodBase _method; public CADMessageBase (IMethodMessage msg) { MethodHandle = msg.MethodBase.MethodHandle; FullTypeName = msg.MethodBase.DeclaringType.AssemblyQualifiedName; } internal MethodBase method { get { if (_method == null) { _method = GetMethod(); } return _method; } } internal MethodBase GetMethod () { Type tt = Type.GetType (FullTypeName, true); if (tt.IsGenericType || tt.IsGenericTypeDefinition) { _method = MethodBase.GetMethodFromHandleNoGenericCheck (MethodHandle); } else { _method = MethodBase.GetMethodFromHandle (MethodHandle); } if (tt != _method.DeclaringType) { // The target domain has loaded the type from a different assembly. // We need to locate the correct type and get the method from it Type [] signature = GetSignature (_method, true); if (_method.IsGenericMethod) { MethodBase [] methods = tt.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance); Type [] base_args = _method.GetGenericArguments (); foreach (MethodBase method in methods) { if (!method.IsGenericMethod || method.Name != _method.Name) continue; Type [] method_args = method.GetGenericArguments (); if (base_args.Length != method_args.Length) continue; MethodInfo method_instance = ((MethodInfo) method).MakeGenericMethod (base_args); Type [] base_sig = GetSignature (method_instance, false); if (base_sig.Length != signature.Length) { continue; } bool dont = false; for (int i = base_sig.Length - 1; i >= 0; i--) { if (base_sig [i] != signature [i]) { dont = true; break; } } if (dont) continue; return method_instance; } return _method; } MethodBase mb = tt.GetMethod (_method.Name, BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance, null, signature, null); if (mb == null) throw new RemotingException ("Method '" + _method.Name + "' not found in type '" + tt + "'"); return mb; } return _method; } static protected Type [] GetSignature (MethodBase methodBase, bool load) { ParameterInfo[] pars = methodBase.GetParameters (); Type[] signature = new Type [pars.Length]; for (int n=0; n