diff --git a/.nuget/packages.config b/.nuget/packages.config deleted file mode 100644 index 489007d..0000000 --- a/.nuget/packages.config +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Weakly.sln b/Weakly.sln index 1890f68..b07d5cc 100644 --- a/Weakly.sln +++ b/Weakly.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Weakly", "src\Weakly\Weakly.csproj", "{AA37F0C0-AA8C-46DE-AC8A-DB844C9AC556}" EndProject @@ -13,11 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build\Weakly.nuspec = build\Weakly.nuspec EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{CD637C73-7382-48F9-BFA2-20CD9469DB23}" - ProjectSection(SolutionItems) = preProject - .nuget\packages.config = .nuget\packages.config - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/build/Weakly.nuspec b/build/Weakly.nuspec index 31957ad..b6d694d 100644 --- a/build/Weakly.nuspec +++ b/build/Weakly.nuspec @@ -3,7 +3,7 @@ Weakly Weakly - 2.5.1 + 2.6.0 Thomas Ibel Weakly is a collection of some useful weak-reference types available as portable class library for net45+win8+wp8+wpa81. en-US @@ -11,7 +11,7 @@ https://github.com/tibel/Weakly https://raw.github.com/tibel/Weakly/master/build/weakly_icon.png false - add APM pattern helper + First Roslyn compatible release Copyright Thomas Ibel 2013-2015 Weakly WeakReference WeakAction WeakFunc WeakDelegate WeakCollection WeakValueDictionary WeakEventHandler WeakEventSource Async Task diff --git a/build/create-package.cmd b/build/create-package.cmd index 53a9155..f6ecccc 100644 --- a/build/create-package.cmd +++ b/build/create-package.cmd @@ -1,4 +1,4 @@ @ECHO OFF del *.nupkg -..\packages\NuGet.CommandLine.2.8.5\tools\NuGet.exe pack Weakly.nuspec -Symbols +..\packages\NuGet.CommandLine.2.8.6\tools\NuGet.exe pack Weakly.nuspec -Symbols pause diff --git a/build/publish-package.cmd b/build/publish-package.cmd index 0ccb7b2..22f4ded 100644 --- a/build/publish-package.cmd +++ b/build/publish-package.cmd @@ -1,4 +1,4 @@ @ECHO OFF for /f "delims=" %%F in ('dir *.nupkg /b /o-n') do set PACKAGE=%%F -..\packages\NuGet.CommandLine.2.8.5\tools\NuGet.exe push %PACKAGE% +..\packages\NuGet.CommandLine.2.8.6\tools\NuGet.exe push %PACKAGE% pause diff --git a/src/GlobalAssemblyInfo.cs b/src/GlobalAssemblyInfo.cs index 2ec5bd7..7094774 100644 --- a/src/GlobalAssemblyInfo.cs +++ b/src/GlobalAssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: CLSCompliant(true)] -[assembly: AssemblyVersion("2.5.0.0")] -[assembly: AssemblyFileVersion("2.5.1.0")] +[assembly: AssemblyVersion("2.6.0.0")] +[assembly: AssemblyFileVersion("2.6.0.0")] diff --git a/src/Weakly/Delegates/WeakAction.cs b/src/Weakly/Delegates/WeakAction.cs index ab680d9..c4eea77 100644 --- a/src/Weakly/Delegates/WeakAction.cs +++ b/src/Weakly/Delegates/WeakAction.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection; namespace Weakly { @@ -18,14 +17,12 @@ public sealed class WeakAction /// /// The class instance on which the current delegate invokes the instance method. /// The method represented by the delegate. - public WeakAction(TTarget target, Action weakAction) + public WeakAction(TTarget target, [EmptyCapture] Action weakAction) { if (target == null) throw new ArgumentNullException("target"); if (weakAction == null) throw new ArgumentNullException("weakAction"); - if (weakAction.Target != null) - throw new ArgumentException("The delegate is not a static method or lambda.", "weakAction"); _target = new WeakReference(target); _weakAction = weakAction; diff --git a/src/Weakly/Delegates/WeakFunc.cs b/src/Weakly/Delegates/WeakFunc.cs index 2fa63e1..4dfb56a 100644 --- a/src/Weakly/Delegates/WeakFunc.cs +++ b/src/Weakly/Delegates/WeakFunc.cs @@ -18,14 +18,12 @@ public sealed class WeakFunc /// /// The class instance on which the current delegate invokes the instance method. /// The method represented by the delegate. - public WeakFunc(TTarget target, Func weakFunc) + public WeakFunc(TTarget target, [EmptyCapture] Func weakFunc) { if (target == null) throw new ArgumentNullException("target"); if (weakFunc == null) throw new ArgumentNullException("weakFunc"); - if (weakFunc.Target != null) - throw new ArgumentException("The delegate is not a static method or lambda.", "weakFunc"); _target = new WeakReference(target); _weakFunc = weakFunc; diff --git a/src/Weakly/EmptyCaptureAttribute.cs b/src/Weakly/EmptyCaptureAttribute.cs new file mode 100644 index 0000000..f538325 --- /dev/null +++ b/src/Weakly/EmptyCaptureAttribute.cs @@ -0,0 +1,12 @@ +using System; + +namespace Weakly +{ + /// + /// Indicates that the delegate parameter should not be an instance method or closure (captures no context). + /// + [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)] + public sealed class EmptyCaptureAttribute : Attribute + { + } +} diff --git a/src/Weakly/Events/WeakCanExecuteChangedHandler.cs b/src/Weakly/Events/WeakCanExecuteChangedHandler.cs index 1a8d6df..848734d 100644 --- a/src/Weakly/Events/WeakCanExecuteChangedHandler.cs +++ b/src/Weakly/Events/WeakCanExecuteChangedHandler.cs @@ -8,7 +8,7 @@ internal sealed class WeakCanExecuteChangedHandler : where TSubscriber : class { public WeakCanExecuteChangedHandler(ICommand source, TSubscriber subscriber, - Action weakHandler) + [EmptyCapture] Action weakHandler) : base(source, subscriber, weakHandler) { source.CanExecuteChanged += OnEvent; diff --git a/src/Weakly/Events/WeakEventHandler.cs b/src/Weakly/Events/WeakEventHandler.cs index 47fd894..ef56af8 100644 --- a/src/Weakly/Events/WeakEventHandler.cs +++ b/src/Weakly/Events/WeakEventHandler.cs @@ -19,7 +19,7 @@ public static class WeakEventHandler /// The weak handler. /// A registration object that can be used to deregister from the event. public static IDisposable RegisterPropertyChangedWeak(this INotifyPropertyChanged source, - TSubscriber subscriber, Action weakHandler) + TSubscriber subscriber, [EmptyCapture] Action weakHandler) where TSubscriber : class { return new WeakNotifyPropertyChangedHandler(source, subscriber, weakHandler); @@ -34,7 +34,7 @@ public static IDisposable RegisterPropertyChangedWeak(this INotifyP /// The weak handler. /// A registration object that can be used to deregister from the event. public static IDisposable RegisterCollectionChangedWeak(this INotifyCollectionChanged source, - TSubscriber subscriber, Action weakHandler) + TSubscriber subscriber, [EmptyCapture] Action weakHandler) where TSubscriber : class { return new WeakNotifyCollectionChangedHandler(source, subscriber, weakHandler); @@ -49,7 +49,7 @@ public static IDisposable RegisterCollectionChangedWeak(this INotif /// The weak handler. /// A registration object that can be used to deregister from the event. public static IDisposable RegisterCanExecuteChangedWeak(this ICommand source, - TSubscriber subscriber, Action weakHandler) + TSubscriber subscriber, [EmptyCapture] Action weakHandler) where TSubscriber : class { return new WeakCanExecuteChangedHandler(source, subscriber, weakHandler); diff --git a/src/Weakly/Events/WeakEventHandlerBase.cs b/src/Weakly/Events/WeakEventHandlerBase.cs index 6eba015..55995f5 100644 --- a/src/Weakly/Events/WeakEventHandlerBase.cs +++ b/src/Weakly/Events/WeakEventHandlerBase.cs @@ -18,14 +18,12 @@ public abstract class WeakEventHandlerBase : IWeakEvent /// /// The event subscriber. /// The weak handler. - protected WeakEventHandlerBase(TSubscriber subscriber, Action weakHandler) + protected WeakEventHandlerBase(TSubscriber subscriber, [EmptyCapture] Action weakHandler) { if (subscriber == null) throw new ArgumentNullException("subscriber"); if (weakHandler == null) throw new ArgumentNullException("weakHandler"); - if (weakHandler.Target != null) - throw new ArgumentException("Cannot create weak event handler from an instance method or closure.", "weakHandler"); _subscriber = new WeakReference(subscriber); _weakHandler = weakHandler; @@ -84,7 +82,7 @@ public abstract class WeakEventHandlerBase : I /// The event source. /// The event subscriber. /// The weak handler. - protected WeakEventHandlerBase(TSource source, TSubscriber subscriber, Action weakHandler) + protected WeakEventHandlerBase(TSource source, TSubscriber subscriber, [EmptyCapture] Action weakHandler) { if (source == null) throw new ArgumentNullException("source"); @@ -92,8 +90,6 @@ protected WeakEventHandlerBase(TSource source, TSubscriber subscriber, Action(source); _subscriber = new WeakReference(subscriber); diff --git a/src/Weakly/Events/WeakNotifyCollectionChangedHandler.cs b/src/Weakly/Events/WeakNotifyCollectionChangedHandler.cs index e7fe334..19c4d14 100644 --- a/src/Weakly/Events/WeakNotifyCollectionChangedHandler.cs +++ b/src/Weakly/Events/WeakNotifyCollectionChangedHandler.cs @@ -8,7 +8,7 @@ internal sealed class WeakNotifyCollectionChangedHandler : where TSubscriber : class { public WeakNotifyCollectionChangedHandler(INotifyCollectionChanged source, TSubscriber subscriber, - Action weakHandler) + [EmptyCapture] Action weakHandler) : base(source, subscriber, weakHandler) { source.CollectionChanged += OnEvent; diff --git a/src/Weakly/Events/WeakNotifyPropertyChangedHandler.cs b/src/Weakly/Events/WeakNotifyPropertyChangedHandler.cs index ea72358..523fce7 100644 --- a/src/Weakly/Events/WeakNotifyPropertyChangedHandler.cs +++ b/src/Weakly/Events/WeakNotifyPropertyChangedHandler.cs @@ -8,7 +8,7 @@ internal sealed class WeakNotifyPropertyChangedHandler : where TSubscriber : class { public WeakNotifyPropertyChangedHandler(INotifyPropertyChanged source, TSubscriber subscriber, - Action weakHandler) + [EmptyCapture] Action weakHandler) : base(source, subscriber, weakHandler) { source.PropertyChanged += OnEvent; diff --git a/src/Weakly/Reflection/ReflectionHelper.cs b/src/Weakly/Reflection/ReflectionHelper.cs index 1983502..b188e1e 100644 --- a/src/Weakly/Reflection/ReflectionHelper.cs +++ b/src/Weakly/Reflection/ReflectionHelper.cs @@ -20,26 +20,6 @@ public static bool IsCompilerGenerated(this MemberInfo memberInfo) return memberInfo.IsDefined(typeof (CompilerGeneratedAttribute)); } - /// - /// Determines whether the specified method is a lambda. - /// - /// The method to examine. - /// True, if the method is a lambda; otherwise false. - public static bool IsLambda(this MethodInfo methodInfo) - { - return methodInfo.IsStatic && methodInfo.IsCompilerGenerated(); - } - - /// - /// Determines whether the specified method is closure. - /// - /// The method to examine. - /// True, if the method is a closure; otherwise false. - public static bool IsClosure(this MethodInfo methodInfo) - { - return !methodInfo.IsStatic && methodInfo.DeclaringType.GetTypeInfo().IsCompilerGenerated(); - } - /// /// Determines whether the specified method is an async method. /// diff --git a/src/Weakly/Weakly.csproj b/src/Weakly/Weakly.csproj index 7baed17..7a4e9e0 100644 --- a/src/Weakly/Weakly.csproj +++ b/src/Weakly/Weakly.csproj @@ -45,6 +45,7 @@ Weakly.snk + @@ -74,6 +75,7 @@ + diff --git a/src/Weakly/packages.config b/src/Weakly/packages.config new file mode 100644 index 0000000..af1b7fd --- /dev/null +++ b/src/Weakly/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file