예제 #1
0
            private object /*!*/ ReadUserClass()
            {
                object obj      = UnmarshalNewObject();
                bool   loaded   = false;
                int    typeFlag = _reader.ReadByte();

                switch (typeFlag)
                {
                case '"':
                    MutableString msc = (obj as MutableString);
                    if (msc != null)
                    {
                        msc.Replace(0, msc.Length, ReadString());
                        loaded = true;
                    }
                    break;

                case '/':
                    RubyRegex rsc = (obj as RubyRegex);
                    if (rsc != null)
                    {
                        RubyRegex regex = ReadRegex();
                        rsc.Set(regex.Pattern, regex.Options);
                        loaded = true;
                    }
                    break;

                case '[':
                    RubyArray asc = (obj as RubyArray);
                    if (asc != null)
                    {
                        asc.AddRange(ReadArray());
                        loaded = true;
                    }
                    break;

                case '{':
                case '}':
                    Hash hsc = (obj as Hash);
                    if (hsc != null)
                    {
                        Hash hash = ReadHash(typeFlag);
                        hsc.DefaultProc  = hash.DefaultProc;
                        hsc.DefaultValue = hash.DefaultValue;
                        foreach (var pair in hash)
                        {
                            hsc.Add(pair.Key, pair.Value);
                        }
                        loaded = true;
                    }
                    break;

                default:
                    break;
                }
                if (!loaded)
                {
                    throw RubyExceptions.CreateArgumentError("incompatible base type");
                }
                return(obj);
            }