คุณสามารถใช้Func<T, TResult>ผู้รับมอบสิทธิ์ทั่วไป (ดูMSDN )
Func<MyType, ReturnType> func = (db) => { return new MyType(); }
นอกจากนี้ยังมีผู้รับมอบสิทธิ์ทั่วไปที่มีประโยชน์ซึ่งพิจารณาค่าตอบแทน:
Converter<TInput, TOutput>( MSDN )
Predicate<TInput>- ส่งคืนบูล ( MSDN ) เสมอ
วิธี:
public MyType SimpleUsing.DoUsing<MyType>(Func<TInput, MyType> myTypeFactory)
ผู้รับมอบสิทธิ์ทั่วไป:
Func<InputArgumentType, MyType> createInstance = db => return new MyType();
ดำเนินการ:
MyType myTypeInstance = SimpleUsing.DoUsing(
createInstance(new InputArgumentType()));
หรืออย่างชัดเจน:
MyType myTypeInstance = SimpleUsing.DoUsing(db => return new MyType());