diff --git a/src/Z.Core/System.Using/TResult.Using.cs b/src/Z.Core/System.Using/TResult.Using.cs new file mode 100644 index 00000000..bd4f64f8 --- /dev/null +++ b/src/Z.Core/System.Using/TResult.Using.cs @@ -0,0 +1,26 @@ +// Description: C# Extension Methods Library to enhances the .NET Framework by adding hundreds of new methods. It drastically increases developers productivity and code readability. Support C# and VB.NET +// Website & Documentation: https://github.com/zzzprojects/Z.ExtensionMethods +// Forum: https://github.com/zzzprojects/Z.ExtensionMethods/issues +// License: https://github.com/zzzprojects/Z.ExtensionMethods/blob/master/LICENSE +// More projects: http://www.zzzprojects.com/ +// Copyright � ZZZ Projects Inc. 2014 - 2016. All rights reserved. +using System; +using System.Text; + +public static partial class Extensions +{ + /// + /// Using statement extension to skip small using blocks. + /// + /// The factory function to create disposable object to act on. + /// The function to use disposable object and return result + /// TResult from specified action function + public static TResult Using(Func factory, Func action) + where TDisposable : IDisposable + { + using (var disposable = factory()) + { + return action(disposable); + } + } +} \ No newline at end of file