Exemplo n.º 1
0
        protected object UnmarshalArgument(object arg, ArrayList args)
        {
            if (arg == null)
            {
                return(null);
            }
            CADArgHolder cadargHolder = arg as CADArgHolder;

            if (cadargHolder != null)
            {
                return(args[cadargHolder.index]);
            }
            CADObjRef cadobjRef = arg as CADObjRef;

            if (cadobjRef != null)
            {
                string      typeName     = string.Copy(cadobjRef.TypeName);
                string      uri          = string.Copy(cadobjRef.URI);
                int         sourceDomain = cadobjRef.SourceDomain;
                ChannelInfo cinfo        = new ChannelInfo(new CrossAppDomainData(sourceDomain));
                ObjRef      objectRef    = new ObjRef(typeName, uri, cinfo);
                return(RemotingServices.Unmarshal(objectRef));
            }
            if (arg is Array)
            {
                Array array = (Array)arg;
                Array array2;
                switch (Type.GetTypeCode(arg.GetType().GetElementType()))
                {
                case TypeCode.Boolean:
                    array2 = new bool[array.Length];
                    break;

                case TypeCode.Char:
                    array2 = new char[array.Length];
                    break;

                case TypeCode.SByte:
                    array2 = new sbyte[array.Length];
                    break;

                case TypeCode.Byte:
                    array2 = new byte[array.Length];
                    break;

                case TypeCode.Int16:
                    array2 = new short[array.Length];
                    break;

                case TypeCode.UInt16:
                    array2 = new ushort[array.Length];
                    break;

                case TypeCode.Int32:
                    array2 = new int[array.Length];
                    break;

                case TypeCode.UInt32:
                    array2 = new uint[array.Length];
                    break;

                case TypeCode.Int64:
                    array2 = new long[array.Length];
                    break;

                case TypeCode.UInt64:
                    array2 = new ulong[array.Length];
                    break;

                case TypeCode.Single:
                    array2 = new float[array.Length];
                    break;

                case TypeCode.Double:
                    array2 = new double[array.Length];
                    break;

                case TypeCode.Decimal:
                    array2 = new decimal[array.Length];
                    break;

                default:
                    throw new NotSupportedException();
                }
                array.CopyTo(array2, 0);
                return(array2);
            }
            switch (Type.GetTypeCode(arg.GetType()))
            {
            case TypeCode.Boolean:
                return((bool)arg);

            case TypeCode.Char:
                return((char)arg);

            case TypeCode.SByte:
                return((sbyte)arg);

            case TypeCode.Byte:
                return((byte)arg);

            case TypeCode.Int16:
                return((short)arg);

            case TypeCode.UInt16:
                return((ushort)arg);

            case TypeCode.Int32:
                return((int)arg);

            case TypeCode.UInt32:
                return((uint)arg);

            case TypeCode.Int64:
                return((long)arg);

            case TypeCode.UInt64:
                return((ulong)arg);

            case TypeCode.Single:
                return((float)arg);

            case TypeCode.Double:
                return((double)arg);

            case TypeCode.Decimal:
                return((decimal)arg);

            case TypeCode.DateTime:
                return(new DateTime(((DateTime)arg).Ticks));

            case TypeCode.String:
                return(string.Copy((string)arg));
            }
            if (arg is TimeSpan)
            {
                return(new TimeSpan(((TimeSpan)arg).Ticks));
            }
            if (arg is IntPtr)
            {
                return((IntPtr)arg);
            }
            throw new NotSupportedException("Parameter of type " + arg.GetType() + " cannot be unmarshalled");
        }
Exemplo n.º 2
0
        protected object UnmarshalArgument(object arg, ArrayList args)
        {
            if (arg == null)
            {
                return(null);
            }

            // Check if argument is an holder (then we know that it's a serialized argument)
            CADArgHolder holder = arg as CADArgHolder;

            if (null != holder)
            {
                return(args [holder.index]);
            }

            CADObjRef objref = arg as CADObjRef;

            if (null != objref)
            {
                ObjRef localRef = objref.objref.DeserializeInTheCurrentDomain(objref.SourceDomain, objref.TypeInfo);
                return(RemotingServices.Unmarshal(localRef));
            }

            if (arg is Array)
            {
                Array argb = (Array)arg;
                Array argn;

                // We can't use Array.CreateInstance (arg.GetType().GetElementType()) because
                // GetElementType() returns a type from the source domain.

                switch (Type.GetTypeCode(arg.GetType().GetElementType()))
                {
                case TypeCode.Boolean: argn = new bool [argb.Length]; break;

                case TypeCode.Byte: argn = new Byte [argb.Length]; break;

                case TypeCode.Char: argn = new Char [argb.Length]; break;

                case TypeCode.Decimal: argn = new Decimal [argb.Length]; break;

                case TypeCode.Double: argn = new Double [argb.Length]; break;

                case TypeCode.Int16: argn = new Int16 [argb.Length]; break;

                case TypeCode.Int32: argn = new Int32 [argb.Length]; break;

                case TypeCode.Int64: argn = new Int64 [argb.Length]; break;

                case TypeCode.SByte: argn = new SByte [argb.Length]; break;

                case TypeCode.Single: argn = new Single [argb.Length]; break;

                case TypeCode.UInt16: argn = new UInt16 [argb.Length]; break;

                case TypeCode.UInt32: argn = new UInt32 [argb.Length]; break;

                case TypeCode.UInt64: argn = new UInt64 [argb.Length]; break;

                default: throw new NotSupportedException();
                }

                argb.CopyTo(argn, 0);
                return(argn);
            }

            switch (Type.GetTypeCode(arg.GetType()))
            {
            case TypeCode.Boolean: return((bool)arg);

            case TypeCode.Byte: return((byte)arg);

            case TypeCode.Char: return((char)arg);

            case TypeCode.Decimal: return((decimal)arg);

            case TypeCode.Double: return((double)arg);

            case TypeCode.Int16: return((Int16)arg);

            case TypeCode.Int32: return((Int32)arg);

            case TypeCode.Int64: return((Int64)arg);

            case TypeCode.SByte: return((SByte)arg);

            case TypeCode.Single: return((Single)arg);

            case TypeCode.UInt16: return((UInt16)arg);

            case TypeCode.UInt32: return((UInt32)arg);

            case TypeCode.UInt64: return((UInt64)arg);

            case TypeCode.String: return(string.Copy((string)arg));

            case TypeCode.DateTime: return(new DateTime(((DateTime)arg).Ticks));

            default:
                if (arg is TimeSpan)
                {
                    return(new TimeSpan(((TimeSpan)arg).Ticks));
                }
                if (arg is IntPtr)
                {
                    return((IntPtr)arg);
                }
                break;
            }

            throw new NotSupportedException("Parameter of type " + arg.GetType() + " cannot be unmarshalled");
        }