public ArrayType(Type type, int maxLength, delReadValue get, delWriteValue set) { MaxLength = maxLength; GetValue = get; SetValue = set; Type = type; }
static bool TryRecursive(Type btype, out delReadValue readValue, out delWriteValue writeValue) { BinarySerializerCache cache = BinarySerializer.InternalCacheTypesOf(btype); if (cache == null) { readValue = null; writeValue = null; return(false); } RecursiveType r = new RecursiveType(btype); readValue = r.GetRecursiveValue; writeValue = r.SetRecursiveValue; return(true); }
/// <summary> /// Constructor /// </summary> /// <param name="atr">Attribute</param> /// <param name="btype">Type</param> BinarySerializerCacheEntry(BinaryPropertyAttribute atr, Type btype) { Type type = btype; MaxLength = atr.MaxLength; bool array = type.IsArray; bool list = _iListType.IsAssignableFrom(type); if (type == typeof(byte[])) { ReadValue = new delReadValue(GetByteArrayValue); WriteValue = new delWriteValue(SetByteArrayValue); } else { if (array || list) { // Extract type of array type = type.GetElementType(); } if (type.IsEnum) { type = Enum.GetUnderlyingType(type); } if (type == typeof(string)) { ReadValue = new delReadValue(GetStringValue); WriteValue = new delWriteValue(SetStringValue); } else if (type == typeof(long)) { ReadValue = new delReadValue(GetInt64Value); WriteValue = new delWriteValue(SetInt64Value); } else if (type == typeof(ulong)) { ReadValue = new delReadValue(GetUInt64Value); WriteValue = new delWriteValue(SetUInt64Value); } else if (type == typeof(int)) { ReadValue = new delReadValue(GetInt32Value); WriteValue = new delWriteValue(SetInt32Value); } else if (type == typeof(uint)) { ReadValue = new delReadValue(GetUInt32Value); WriteValue = new delWriteValue(SetUInt32Value); } else if (type == typeof(short)) { ReadValue = new delReadValue(GetInt16Value); WriteValue = new delWriteValue(SetInt16Value); } else if (type == typeof(ushort)) { ReadValue = new delReadValue(GetUInt16Value); WriteValue = new delWriteValue(SetUInt16Value); } else if (type == typeof(byte)) { ReadValue = new delReadValue(GetByteValue); WriteValue = new delWriteValue(SetByteValue); } else if (type == typeof(sbyte)) { ReadValue = new delReadValue(GetSByteValue); WriteValue = new delWriteValue(SetSByteValue); } else if (type == typeof(bool)) { ReadValue = new delReadValue(GetBoolValue); WriteValue = new delWriteValue(SetBoolValue); } else if (type == typeof(double)) { ReadValue = new delReadValue(GetDoubleValue); WriteValue = new delWriteValue(SetDoubleValue); } else if (!TryRecursive(type, out ReadValue, out WriteValue)) { throw (new NotImplementedException()); } if (array) { ArrayType ar = new ArrayType(btype, MaxLength, ReadValue, WriteValue); ReadValue = new delReadValue(ar.GetArrayValue); WriteValue = new delWriteValue(ar.SetArrayValue); } else if (list) { ListType ls = new ListType(btype, MaxLength, ReadValue, WriteValue); ReadValue = new delReadValue(ls.GetListValue); WriteValue = new delWriteValue(ls.SetListValue); } } }