예제 #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="atr">Attribute</param>
 /// <param name="fi">Field</param>
 public BinarySerializerCacheEntry(BinaryPropertyAttribute atr, FieldInfo fi) : this(atr, fi.FieldType)
 {
     Name     = fi.Name;
     GetValue = new delGetValue(fi.GetValue);
     SetValue = new delSetValue(fi.SetValue);
     ReadOnly = false;
 }
예제 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="atr">Attribute</param>
 /// <param name="pi">Property</param>
 public BinarySerializerCacheEntry(BinaryPropertyAttribute atr, PropertyInfo pi) : this(atr, pi.PropertyType)
 {
     Name     = pi.Name;
     GetValue = new delGetValue(pi.GetValue);
     SetValue = new delSetValue(pi.SetValue);
     ReadOnly = !pi.CanWrite;
 }
예제 #3
0
        /// <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);
                }
            }
        }