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()); }
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); }
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); }
public static AssocArray ToAssocArray(AssocArray value) { return value; }
public static ArrayList ToArrayList(AssocArray value) { if (value == null) { return null; } return value.toArrayList(); }
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; } }
public static Array ToArray(AssocArray value, Type conversionType, String charset) { return ToArray(value, conversionType, Encoding.GetEncoding(charset)); }
public static Array ToArray(AssocArray value, Type conversionType) { return ToArray(value, conversionType, UTF8); }
public static Object ToObject(AssocArray value, Type conversionType, Encoding encoding) { if (value == null) { return null; } return ToObject(value.toHashtable(), conversionType, encoding); }
public static Object ToObject(AssocArray value, Type conversionType) { return ToObject(value, conversionType, UTF8); }
public static Hashtable ToHashtable(AssocArray value) { if (value == null) { return null; } return value.toHashtable(); }
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; }
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; }