Beispiel #1
0
        public bool ice_isA(string name)
        {
            Type t = this.GetType();
            Type o = IceUtil.IceNameToType(name);

            return(t == o || t.IsSubclassOf(o));
        }
Beispiel #2
0
        public object ReadSlice(object inst)
        {
            string sliceName     = ReadSliceName();
            int    sliceDataSize = ReadInt32();

            sliceDataSize -= 4; // size includes the 4 bytes of the size itself

            Type sliceType = IceUtil.IceNameToType(sliceName);

            if (sliceType == null)
            {
                // this means we have no local definition of this slice;
                // we keep going.  Eventually we will hit an Ice.Object,
                // which is the terminating condition of this recursion,
                // since we know we have Ice.Object defined.
                ReadBytes(sliceDataSize);
                return(ReadSlice(inst));
            }

            if (inst == null)
            {
                // if it's null, it has yet to be created, and this is
                // the first (i.e. most derived) slice that we
                // understand.
                inst = Activator.CreateInstance(sliceType);
            }

            MethodInfo unmarshal = sliceType.GetMethod("ice_unmarshal",
                                                       BindingFlags.Instance |
                                                       BindingFlags.Public |
                                                       BindingFlags.DeclaredOnly);

            if (unmarshal != null)
            {
                object[] args = new object[1];
                args[0] = this;
                try {
                    unmarshal.Invoke(inst, args);
                } catch (TargetInvocationException te) {
                    throw te.InnerException;
                }
            }
            else
            {
                FieldInfo[] fields = sliceType.GetFields(BindingFlags.Instance |
                                                         BindingFlags.Public |
                                                         BindingFlags.DeclaredOnly);
                foreach (FieldInfo field in fields)
                {
                    if (IceChannelUtils.IceByValue(field.FieldType))
                    {
                        object elem = ReadObject(field.FieldType);
                        field.SetValue(inst, elem);
                    }
                    else
                    {
                        // this is a class type
                        int r = ReadClassInstanceRef();
                        if (r == 0)
                        {
                            field.SetValue(inst, null);
                        }
                        else
                        {
                            _instancePatchList.Add(new FieldPatchInfo(r, inst, field));
                        }
                    }
                }
            }

            if (sliceType == typeof(Ice.Object))
            {
                return(inst);
            }
            else
            {
                return(ReadSlice(inst));
            }
        }