/// <summary> /// Initializes a new instance of the KeyColumnConverter class. /// </summary> public KeyColumnConverter() { const string MakeKeyMethodName = "MakeKey"; Type[] arguments = new[] { typeof(JET_SESID), typeof(JET_TABLEID), typeof(TColumn), typeof(MakeKeyGrbit) }; // Look for a private method in this class that takes the appropriate arguments, // otherwise a method on the Api class. MethodInfo method = typeof(KeyColumnConverter <TColumn>).GetMethod( MakeKeyMethodName, BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.ExactBinding, null, arguments, null) ?? typeof(Api).GetMethod( MakeKeyMethodName, BindingFlags.Static | BindingFlags.Public | BindingFlags.ExactBinding, null, arguments, null); if (null != method) { this.keyMaker = (MakeKeyDelegate)Delegate.CreateDelegate(typeof(MakeKeyDelegate), method); RuntimeHelpers.PrepareDelegate(this.keyMaker); } else { throw new ArgumentOutOfRangeException("type", typeof(TColumn), "Not supported for MakeKey"); } }
/// <summary> /// Initializes a new instance of the KeyColumnConverter class. /// </summary> /// <param name="type">The type to convert to/from.</param> public KeyColumnConverter(Type type) : base(type) { if (!MakeKeyDelegates.ContainsKey(type)) { throw new ArgumentOutOfRangeException("type", type, "Not supported for MakeKey"); } this.makeKey = MakeKeyDelegates[type]; }