コード例 #1
0
        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);
        }
コード例 #2
0
 /// <summary>
 /// Creates a delegate which takes a nullable object and wraps the
 /// non-nullable SetColumn method.
 /// </summary>
 /// <typeparam name="T">The type that will be nullable.</typeparam>
 /// <param name="wrappedSetColumn">The (non-nullable) delegrate to wrap.</param>
 /// <returns>
 /// A SetColumnDelegate that takes a Nullable<typeparamref name="T"/> and
 /// either sets the column to null or calls the wrapped delegate.
 /// </returns>
 private static SetColumnDelegate MakeNullableSetColumn <T>(SetColumnDelegate wrappedSetColumn) where T : struct
 {
     return((s, t, c, o) =>
     {
         if (((T?)o).HasValue)
         {
             wrappedSetColumn(s, t, c, o);
         }
         else
         {
             Api.SetColumn(s, t, c, null);
         }
     });
 }
コード例 #3
0
        /// <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];
            }
        }