From be30397cfd831b94dc03f94d32d475471792c345 Mon Sep 17 00:00:00 2001 From: JohanLarsson Date: Tue, 3 Dec 2019 16:29:57 +0100 Subject: [PATCH] More tests. #206 --- .../REFL013MemberIsOfWrongTypeTests/Valid.cs | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/ReflectionAnalyzers.Tests/REFL013MemberIsOfWrongTypeTests/Valid.cs b/ReflectionAnalyzers.Tests/REFL013MemberIsOfWrongTypeTests/Valid.cs index e44942ed..b20cbf78 100644 --- a/ReflectionAnalyzers.Tests/REFL013MemberIsOfWrongTypeTests/Valid.cs +++ b/ReflectionAnalyzers.Tests/REFL013MemberIsOfWrongTypeTests/Valid.cs @@ -1,4 +1,4 @@ -namespace ReflectionAnalyzers.Tests.REFL013MemberIsOfWrongTypeTests +namespace ReflectionAnalyzers.Tests.REFL013MemberIsOfWrongTypeTests { using Gu.Roslyn.Asserts; using Microsoft.CodeAnalysis; @@ -25,6 +25,75 @@ void M(Type[] types) typeof(C<,>).MakeGenericType(types); } } +}"; + RoslynAssert.Valid(Analyzer, Descriptor, code); + } + + [Test] + public static void Issue206WhenGettingField() + { + var code = @" +namespace ValidCode.Repros +{ + using System; + using System.Reflection; + using NUnit.Framework; + + public delegate void OnModelHandler(object e); + + public interface IThing + { + event OnModelHandler OnModel; + } + + public class Thing : IThing + { + public event OnModelHandler OnModel; + } + + public class C + { + public static MulticastDelegate GetOnModel(IThing sender) + { + return (MulticastDelegate)sender.GetType() + .GetField(""OnModel"", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly) + .GetValue(sender); + } + } +}"; + RoslynAssert.Valid(Analyzer, Descriptor, code); + } + + [Test] + public static void Issue206WhenGettingEvent() + { + var code = @" +namespace ValidCode.Repros +{ + using System; + using System.Reflection; + using NUnit.Framework; + + public delegate void OnModelHandler(object e); + + public interface IThing + { + event OnModelHandler OnModel; + } + + public class Thing : IThing + { + public event OnModelHandler OnModel; + } + + public class C + { + public static EventInfo GetOnModel(IThing sender) + { + return sender.GetType() + .GetEvent(""OnModel"", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + } + } }"; RoslynAssert.Valid(Analyzer, Descriptor, code); }