Skip to content

Commit

Permalink
Fix Roslyn compatibility (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
tibel committed Sep 1, 2015
1 parent 13f9c1c commit 7d0b3cc
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 56 deletions.
4 changes: 0 additions & 4 deletions .nuget/packages.config

This file was deleted.

9 changes: 2 additions & 7 deletions Weakly.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions build/Weakly.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<metadata>
<id>Weakly</id>
<title>Weakly</title>
<version>2.5.1</version>
<version>2.6.0</version>
<authors>Thomas Ibel</authors>
<description>Weakly is a collection of some useful weak-reference types available as portable class library for net45+win8+wp8+wpa81.</description>
<language>en-US</language>
<licenseUrl>https://raw.github.com/tibel/Weakly/master/LICENSE</licenseUrl>
<projectUrl>https://github.com/tibel/Weakly</projectUrl>
<iconUrl>https://raw.github.com/tibel/Weakly/master/build/weakly_icon.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<releaseNotes>add APM pattern helper</releaseNotes>
<releaseNotes>First Roslyn compatible release</releaseNotes>
<copyright>Copyright Thomas Ibel 2013-2015</copyright>
<tags>
Weakly WeakReference WeakAction WeakFunc WeakDelegate WeakCollection WeakValueDictionary WeakEventHandler WeakEventSource Async Task
Expand Down
2 changes: 1 addition & 1 deletion build/create-package.cmd
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion build/publish-package.cmd
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/GlobalAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
5 changes: 1 addition & 4 deletions src/Weakly/Delegates/WeakAction.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Reflection;

namespace Weakly
{
Expand All @@ -18,14 +17,12 @@ public sealed class WeakAction<TTarget>
/// </summary>
/// <param name="target">The class instance on which the current delegate invokes the instance method.</param>
/// <param name="weakAction">The method represented by the delegate.</param>
public WeakAction(TTarget target, Action<TTarget> weakAction)
public WeakAction(TTarget target, [EmptyCapture] Action<TTarget> 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<TTarget>(target);
_weakAction = weakAction;
Expand Down
4 changes: 1 addition & 3 deletions src/Weakly/Delegates/WeakFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public sealed class WeakFunc<TTarget, TResult>
/// </summary>
/// <param name="target">The class instance on which the current delegate invokes the instance method.</param>
/// <param name="weakFunc">The method represented by the delegate.</param>
public WeakFunc(TTarget target, Func<TTarget, TResult> weakFunc)
public WeakFunc(TTarget target, [EmptyCapture] Func<TTarget, TResult> 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<TTarget>(target);
_weakFunc = weakFunc;
Expand Down
12 changes: 12 additions & 0 deletions src/Weakly/EmptyCaptureAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Weakly
{
/// <summary>
/// Indicates that the delegate parameter should not be an instance method or closure (captures no context).
/// </summary>
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public sealed class EmptyCaptureAttribute : Attribute
{
}
}
2 changes: 1 addition & 1 deletion src/Weakly/Events/WeakCanExecuteChangedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class WeakCanExecuteChangedHandler<TSubscriber> :
where TSubscriber : class
{
public WeakCanExecuteChangedHandler(ICommand source, TSubscriber subscriber,
Action<TSubscriber, object, EventArgs> weakHandler)
[EmptyCapture] Action<TSubscriber, object, EventArgs> weakHandler)
: base(source, subscriber, weakHandler)
{
source.CanExecuteChanged += OnEvent;
Expand Down
6 changes: 3 additions & 3 deletions src/Weakly/Events/WeakEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static class WeakEventHandler
/// <param name="weakHandler">The weak handler.</param>
/// <returns>A registration object that can be used to deregister from the event.</returns>
public static IDisposable RegisterPropertyChangedWeak<TSubscriber>(this INotifyPropertyChanged source,
TSubscriber subscriber, Action<TSubscriber, object, PropertyChangedEventArgs> weakHandler)
TSubscriber subscriber, [EmptyCapture] Action<TSubscriber, object, PropertyChangedEventArgs> weakHandler)
where TSubscriber : class
{
return new WeakNotifyPropertyChangedHandler<TSubscriber>(source, subscriber, weakHandler);
Expand All @@ -34,7 +34,7 @@ public static IDisposable RegisterPropertyChangedWeak<TSubscriber>(this INotifyP
/// <param name="weakHandler">The weak handler.</param>
/// <returns>A registration object that can be used to deregister from the event.</returns>
public static IDisposable RegisterCollectionChangedWeak<TSubscriber>(this INotifyCollectionChanged source,
TSubscriber subscriber, Action<TSubscriber, object, NotifyCollectionChangedEventArgs> weakHandler)
TSubscriber subscriber, [EmptyCapture] Action<TSubscriber, object, NotifyCollectionChangedEventArgs> weakHandler)
where TSubscriber : class
{
return new WeakNotifyCollectionChangedHandler<TSubscriber>(source, subscriber, weakHandler);
Expand All @@ -49,7 +49,7 @@ public static IDisposable RegisterCollectionChangedWeak<TSubscriber>(this INotif
/// <param name="weakHandler">The weak handler.</param>
/// <returns>A registration object that can be used to deregister from the event.</returns>
public static IDisposable RegisterCanExecuteChangedWeak<TSubscriber>(this ICommand source,
TSubscriber subscriber, Action<TSubscriber, object, EventArgs> weakHandler)
TSubscriber subscriber, [EmptyCapture] Action<TSubscriber, object, EventArgs> weakHandler)
where TSubscriber : class
{
return new WeakCanExecuteChangedHandler<TSubscriber>(source, subscriber, weakHandler);
Expand Down
8 changes: 2 additions & 6 deletions src/Weakly/Events/WeakEventHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@ public abstract class WeakEventHandlerBase<TSubscriber, TEventArgs> : IWeakEvent
/// </summary>
/// <param name="subscriber">The event subscriber.</param>
/// <param name="weakHandler">The weak handler.</param>
protected WeakEventHandlerBase(TSubscriber subscriber, Action<TSubscriber, object, TEventArgs> weakHandler)
protected WeakEventHandlerBase(TSubscriber subscriber, [EmptyCapture] Action<TSubscriber, object, TEventArgs> 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<TSubscriber>(subscriber);
_weakHandler = weakHandler;
Expand Down Expand Up @@ -84,16 +82,14 @@ public abstract class WeakEventHandlerBase<TSource, TSubscriber, TEventArgs> : I
/// <param name="source">The event source.</param>
/// <param name="subscriber">The event subscriber.</param>
/// <param name="weakHandler">The weak handler.</param>
protected WeakEventHandlerBase(TSource source, TSubscriber subscriber, Action<TSubscriber, object, TEventArgs> weakHandler)
protected WeakEventHandlerBase(TSource source, TSubscriber subscriber, [EmptyCapture] Action<TSubscriber, object, TEventArgs> weakHandler)
{
if (source == null)
throw new ArgumentNullException("source");
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");

_source = new WeakReference<TSource>(source);
_subscriber = new WeakReference<TSubscriber>(subscriber);
Expand Down
2 changes: 1 addition & 1 deletion src/Weakly/Events/WeakNotifyCollectionChangedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class WeakNotifyCollectionChangedHandler<TSubscriber> :
where TSubscriber : class
{
public WeakNotifyCollectionChangedHandler(INotifyCollectionChanged source, TSubscriber subscriber,
Action<TSubscriber, object, NotifyCollectionChangedEventArgs> weakHandler)
[EmptyCapture] Action<TSubscriber, object, NotifyCollectionChangedEventArgs> weakHandler)
: base(source, subscriber, weakHandler)
{
source.CollectionChanged += OnEvent;
Expand Down
2 changes: 1 addition & 1 deletion src/Weakly/Events/WeakNotifyPropertyChangedHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal sealed class WeakNotifyPropertyChangedHandler<TSubscriber> :
where TSubscriber : class
{
public WeakNotifyPropertyChangedHandler(INotifyPropertyChanged source, TSubscriber subscriber,
Action<TSubscriber, object, PropertyChangedEventArgs> weakHandler)
[EmptyCapture] Action<TSubscriber, object, PropertyChangedEventArgs> weakHandler)
: base(source, subscriber, weakHandler)
{
source.PropertyChanged += OnEvent;
Expand Down
20 changes: 0 additions & 20 deletions src/Weakly/Reflection/ReflectionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,6 @@ public static bool IsCompilerGenerated(this MemberInfo memberInfo)
return memberInfo.IsDefined(typeof (CompilerGeneratedAttribute));
}

/// <summary>
/// Determines whether the specified method is a lambda.
/// </summary>
/// <param name="methodInfo">The method to examine.</param>
/// <returns>True, if the method is a lambda; otherwise false.</returns>
public static bool IsLambda(this MethodInfo methodInfo)
{
return methodInfo.IsStatic && methodInfo.IsCompilerGenerated();
}

/// <summary>
/// Determines whether the specified method is closure.
/// </summary>
/// <param name="methodInfo">The method to examine.</param>
/// <returns>True, if the method is a closure; otherwise false.</returns>
public static bool IsClosure(this MethodInfo methodInfo)
{
return !methodInfo.IsStatic && methodInfo.DeclaringType.GetTypeInfo().IsCompilerGenerated();
}

/// <summary>
/// Determines whether the specified method is an async method.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Weakly/Weakly.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<None Include="..\Weakly.snk">
<Link>Weakly.snk</Link>
</None>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\GlobalAssemblyInfo.cs">
Expand Down Expand Up @@ -74,6 +75,7 @@
<Compile Include="Builders\IOpenActionBuilder.cs" />
<Compile Include="Builders\IOpenFuncBuilder.cs" />
<Compile Include="Delegates\WeakFunc.cs" />
<Compile Include="EmptyCaptureAttribute.cs" />
<Compile Include="Events\IWeakEventHandler.cs" />
<Compile Include="Delegates\WeakAction.cs" />
<Compile Include="Events\WeakCanExecuteChangedHandler.cs" />
Expand Down
4 changes: 4 additions & 0 deletions src/Weakly/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NuGet.CommandLine" version="2.8.6" targetFramework="portable45-net45+win8+wp8+wpa81" />
</packages>

0 comments on commit 7d0b3cc

Please sign in to comment.