public ColumnConverter() { Type underlyingType = IsNullableType(typeof(TColumn)) ? GetUnderlyingType(typeof(TColumn)) : typeof(TColumn); if (RetrieveColumnMethodNamesMap.ContainsKey(underlyingType)) { this.columnSetter = CreateSetColumnDelegate(); this.columnRetriever = CreateRetrieveColumnDelegate(); this.coltyp = ColumnTypeMap[underlyingType]; } #if ESENTCOLLECTIONS_SUPPORTS_SERIALIZATION else if (IsSerializable(typeof(TColumn))) { this.columnSetter = (s, t, c, o) => Api.SerializeObjectToColumn(s, t, c, o); this.columnRetriever = (s, t, c) => (TColumn)Api.DeserializeObjectFromColumn(s, t, c); this.coltyp = JET_coltyp.LongBinary; } #endif else { throw new ArgumentOutOfRangeException("TColumn", typeof(TColumn), "Not supported for SetColumn"); } // Compile the new delegates. RuntimeHelpers.PrepareDelegate(this.columnSetter); RuntimeHelpers.PrepareDelegate(this.columnRetriever); }
/// <summary> /// Initializes a new instance of the ColumnConverter class. /// </summary> /// <param name="type">The type to convert to/from.</param> public ColumnConverter(Type type) { if (null == type) { throw new ArgumentNullException("type"); } if (!SetColumnDelegates.ContainsKey(type)) { if (!IsSerializable(type)) { throw new ArgumentOutOfRangeException("type", type, "Not supported for SetColumn"); } this.setColumn = (s, t, c, o) => Api.SerializeObjectToColumn(s, t, c, o); } else { this.setColumn = SetColumnDelegates[type]; } if (!RetrieveColumnDelegates.ContainsKey(type)) { if (!IsSerializable(type)) { throw new ArgumentOutOfRangeException("type", type, "Not supported for RetrieveColumn"); } this.retrieveColumn = (s, t, c) => Api.DeserializeObjectFromColumn(s, t, c); } else { this.retrieveColumn = RetrieveColumnDelegates[type]; } if (!Coltyps.ContainsKey(type)) { if (!IsSerializable(type)) { throw new ArgumentOutOfRangeException("type", type, "Has no matching ESENT column type"); } this.coltyp = JET_coltyp.LongBinary; } else { this.coltyp = Coltyps[type]; } }