Inheritance: IDictionary, IList, ICollection, IEnumerable, ICloneable
Beispiel #1
0
        public static Hashtable GetDHParams(UInt32 len)
        {
            AssocArray dhParams = (AssocArray)dhParamsGen[len];
            Random     ran      = new Random((Int32)DateTime.Now.Ticks);

            return(((AssocArray)dhParams[ran.Next(dhParams.Count)]).toHashtable());
        }
Beispiel #2
0
        public virtual Object Clone()
        {
            AssocArray result = new AssocArray();

            result.arrayList   = (ArrayList)arrayList.Clone();
            result.hashtable   = (Hashtable)hashtable.Clone();
            result.arrayLength = arrayLength;
            result.maxNumber   = maxNumber;
            return(result);
        }
Beispiel #3
0
        private AssocArray ReadAssocArray(Stream stream, ArrayList objectContainer)
        {
            Int32 n = ReadInteger(stream);

            stream.Position++;
            AssocArray a = new AssocArray(n);

            objectContainer.Add(a);
            for (Int32 i = 0; i < n; i++)
            {
                Int32 tag = stream.ReadByte();
                if (tag < 0)
                {
                    throw new SerializationException("End of Stream encountered before parsing was completed.");
                }
                Int32  index;
                String key;
                switch (tag)
                {
                case PHPSerializationTag.Integer:
                    index    = ReadInteger(stream);
                    a[index] = Deserialize(stream, objectContainer);
                    break;

                case PHPSerializationTag.BinaryString:
                    key    = GetString(ReadBinaryString(stream));
                    a[key] = Deserialize(stream, objectContainer);
                    break;

                case PHPSerializationTag.EscapedBinaryString:
                    key    = GetString(ReadEscapedBinaryString(stream));
                    a[key] = Deserialize(stream, objectContainer);
                    break;

                case PHPSerializationTag.UnicodeString:
                    key    = ReadUnicodeString(stream);
                    a[key] = Deserialize(stream, objectContainer);
                    break;

                default:
                    throw new SerializationException("Unexpected Tag: '" + (Char)tag + "'.");
                }
            }
            stream.Position++;
            return(a);
        }
Beispiel #4
0
 public static AssocArray ToAssocArray(AssocArray value)
 {
     return value;
 }
Beispiel #5
0
 public static ArrayList ToArrayList(AssocArray value)
 {
     if (value == null) {
         return null;
     }
     return value.toArrayList();
 }
Beispiel #6
0
 public static Array ToArray(ICollection value, Type conversionType, Encoding encoding)
 {
     if (value == null) {
         return null;
     }
     if (conversionType == null) {
         throw new ArgumentNullException("conversionType");
     }
     if (!conversionType.IsArray) {
         throw new ArgumentException("Must be an array type.");
     }
     ArrayList arraylist = new AssocArray(value).toArrayList();
     if (conversionType == typeofObjectArray) {
         return arraylist.ToArray();
     }
     try {
         return arraylist.ToArray(conversionType.GetElementType());
     }
     catch (InvalidCastException) {
         Int32 length = arraylist.Count;
         Type elementType = conversionType.GetElementType();
         Array array = Array.CreateInstance(elementType, length);
         if (array.GetType() != conversionType) {
             throw new RankException("Only single dimension arrays are supported here.");
         }
         for (Int32 i = 0; i < length; i++) {
             array.SetValue(ChangeType(arraylist[i], elementType, encoding), i);
         }
         return array;
     }
 }
Beispiel #7
0
 public static Array ToArray(AssocArray value, Type conversionType, String charset)
 {
     return ToArray(value, conversionType, Encoding.GetEncoding(charset));
 }
Beispiel #8
0
 public static Array ToArray(AssocArray value, Type conversionType)
 {
     return ToArray(value, conversionType, UTF8);
 }
Beispiel #9
0
 public static Object ToObject(AssocArray value, Type conversionType, Encoding encoding)
 {
     if (value == null) {
         return null;
     }
     return ToObject(value.toHashtable(), conversionType, encoding);
 }
Beispiel #10
0
 public static Object ToObject(AssocArray value, Type conversionType)
 {
     return ToObject(value, conversionType, UTF8);
 }
Beispiel #11
0
 public static Hashtable ToHashtable(AssocArray value)
 {
     if (value == null) {
         return null;
     }
     return value.toHashtable();
 }
Beispiel #12
0
 private AssocArray ReadAssocArray(Stream stream, ArrayList objectContainer)
 {
     Int32 n = ReadInteger(stream);
     stream.Position++;
     AssocArray a = new AssocArray(n);
     objectContainer.Add(a);
     for (Int32 i = 0; i < n; i++) {
         Int32 tag = stream.ReadByte();
         if (tag < 0) {
             throw new SerializationException("End of Stream encountered before parsing was completed.");
         }
         Int32 index;
         String key;
         switch (tag) {
         case PHPSerializationTag.Integer:
             index = ReadInteger(stream);
             a[index] = Deserialize(stream, objectContainer);
             break;
         case PHPSerializationTag.BinaryString:
             key = GetString(ReadBinaryString(stream));
             a[key] = Deserialize(stream, objectContainer);
             break;
         case PHPSerializationTag.EscapedBinaryString:
             key = GetString(ReadEscapedBinaryString(stream));
             a[key] = Deserialize(stream, objectContainer);
             break;
         case PHPSerializationTag.UnicodeString:
             key = ReadUnicodeString(stream);
             a[key] = Deserialize(stream, objectContainer);
             break;
         default:
             throw new SerializationException("Unexpected Tag: '" + (Char)tag + "'.");
         }
     }
     stream.Position++;
     return a;
 }
Beispiel #13
0
 public virtual Object Clone() {
     AssocArray result = new AssocArray();
     result.arrayList = (ArrayList)arrayList.Clone();
     result.hashtable = (Hashtable)hashtable.Clone();
     result.arrayLength = arrayLength;
     result.maxNumber = maxNumber;
     return result;
 }