コード例 #1
0
        public override void Patch(Hashtable instanceHash)
        {
            if (!instanceHash.Contains(instanceID))
            {
                throw new InvalidOperationException
                          ("DictionaryEntryPatchInfo: Attempted to patch, but key object wasn't defined!");
            }

            if (!instanceHash.Contains(valueID))
            {
                throw new InvalidOperationException
                          ("DictionaryEntryPatchInfo: Attempted to patch, but value object wasn't defined!");
            }

            object keyo = instanceHash[instanceID];
            object valo = instanceHash[valueID];

            if (keyo == null)
            {
                throw new InvalidOperationException
                          ("DictionaryEntryPatchInfo: Attempted to patch, but key object is null!");
            }

            Ice.Dictionary dict = target as Ice.Dictionary;
            dict[keyo] = valo;
        }
コード例 #2
0
        public virtual void WriteDictionary(Ice.Dictionary dict)
        {
            WriteSize(dict.Count);
            IDictionaryEnumerator iter = dict.GetEnumerator();

            while (iter.MoveNext())
            {
                // FIXME -- these checks are expensive
                if (iter.Key.GetType() != dict.IceDictInfo.keyType)
                {
                    throw new InvalidOperationException("Dictionary contains key with type " + iter.Key + " but keyType is " + dict.IceDictInfo.keyType);
                }
                if (iter.Value.GetType() != dict.IceDictInfo.valueType)
                {
                    throw new InvalidOperationException("Dictionary contains value with type " + iter.Value + " but valueType is " + dict.IceDictInfo.valueType);
                }

                WriteObject(iter.Key, dict.IceDictInfo.keyType);
                WriteObject(iter.Value, dict.IceDictInfo.valueType);
            }
        }
コード例 #3
0
        // read an object of type t from the stream
        // does NOT handle reading classes, since these
        // have to be read by ref and patched
        public object ReadObject(Type t)
        {
            if (t.IsPrimitive)
            {
                if (t == typeof(bool))
                {
                    return(ReadBoolean());
                }
                if (t == typeof(byte))
                {
                    return(ReadByte());
                }
                if (t == typeof(short))
                {
                    return(ReadInt16());
                }
                if (t == typeof(int))
                {
                    return(ReadInt32());
                }
                if (t == typeof(long))
                {
                    return(ReadInt64());
                }
                if (t == typeof(float))
                {
                    return(ReadSingle());
                }
                if (t == typeof(double))
                {
                    return(ReadDouble());
                }

                throw new NotImplementedException("ReadObject can't read primitive type " + t);
            }

            if (t == typeof(string))
            {
                return(ReadString());
            }

            if (t.IsEnum)
            {
                Type ue = Enum.GetUnderlyingType(t);
                if (ue == typeof(byte))
                {
                    byte i = ReadByte();
                    return(Enum.ToObject(t, i));
                }

                if (ue == typeof(short))
                {
                    short i = ReadInt16();
                    return(Enum.ToObject(t, i));
                }

                if (ue == typeof(int))
                {
                    int i = ReadInt32();
                    return(Enum.ToObject(t, i));
                }

                throw new NotSupportedException("ReadObject can't read enum with underlying type " + ue);
            }

            if (t.IsSubclassOf(typeof(Ice.Dictionary)))
            {
                object         o    = Activator.CreateInstance(t);
                Ice.Dictionary dict = o as Ice.Dictionary;
                return(ReadDictionary(dict));
            }

            if (t.IsArray)
            {
                int  sz     = ReadSize();
                Type eltype = t.GetElementType();
                // System.Console.WriteLine ("Reading Array: {0} {1}", sz, eltype);
                Array ao = Array.CreateInstance(eltype, sz);

                if (IceChannelUtils.IceByValue(eltype))
                {
                    for (int i = 0; i < sz; i++)
                    {
                        object elem = ReadObject(eltype);
                        ao.SetValue(elem, i);
                        // System.Console.WriteLine (" {0}: {1}", i, elem);
                    }
                }
                else
                {
                    // this is a class type (and isn't a string or dictionary)
                    for (int i = 0; i < sz; i++)
                    {
                        int r = ReadClassInstanceRef();
                        if (r == 0)
                        {
                            ao.SetValue(null, i);
                        }
                        else
                        {
                            _instancePatchList.Add(new ArrayPatchInfo(r, ao, i));
                        }
                    }
                }

                return(ao);
            }

            if (t.IsValueType)
            {
                object o = Activator.CreateInstance(t);

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

            Console.WriteLine("ReadObject: can't read type " + t);
            throw new NotSupportedException("ReadObject: can't read type " + t);
        }
コード例 #4
0
 protected override void PatchImpl(object o)
 {
     Ice.Dictionary dict = target as Ice.Dictionary;
     dict[o] = value;
 }
コード例 #5
0
 protected override void PatchImpl(object o)
 {
     Ice.Dictionary dict = target as Ice.Dictionary;
     dict[key] = o;
 }
コード例 #6
0
        public object ReadDictionary(Ice.Dictionary dict)
        {
            Ice.DictionaryInfo dinfo = dict.IceDictInfo;

            int count = ReadSize();

            for (int i = 0; i < count; i++)
            {
                object k, v;
                bool   haveKey, haveValue;

                if (IceChannelUtils.IceByValue(dinfo.keyType))
                {
                    k       = ReadObject(dinfo.keyType);
                    haveKey = true;
                }
                else
                {
                    k = ReadClassInstanceRef();
                    if ((int)k == 0)
                    {
                        throw new InvalidOperationException("Got NULL dictionary key, expected class ref for type " + dinfo.keyType);
                    }
                    else
                    {
                        haveKey = false;
                    }
                }

                if (IceChannelUtils.IceByValue(dinfo.valueType))
                {
                    v         = ReadObject(dinfo.valueType);
                    haveValue = true;
                }
                else
                {
                    v = ReadClassInstanceRef();
                    if ((int)v == 0)
                    {
                        v         = null;
                        haveValue = true;
                    }
                    else
                    {
                        haveValue = false;
                    }
                }

                // if we have both the key and value, we put them in.
                // otherwise, we have to create a patch based on what
                // bits we have.
                if (haveKey && haveValue)
                {
                    dict.Add(k, v);
                }
                else
                {
                    if (haveKey)
                    {
                        _instancePatchList.Add(new DictionaryValuePatchInfo((int)v, dict, k));
                    }
                    else if (haveValue)
                    {
                        _instancePatchList.Add(new DictionaryKeyPatchInfo((int)k, dict, v));
                    }
                    else
                    {
                        _instancePatchList.Add(new DictionaryEntryPatchInfo((int)k, dict, (int)v));
                    }
                }
            }

            return(dict);
        }