From 0d8edd07123a1abab3fc45bb26e25dafacc6dc9a Mon Sep 17 00:00:00 2001 From: SimonCropp Date: Sun, 2 Feb 2020 21:28:03 +1100 Subject: [PATCH] Obsolete function delegates fixes #804 --- FodyHelpers/BaseModuleWeaver.cs | 110 +++++++++++++++++++ FodyHelpers/TryFindTypeFunc.cs | 6 +- Tests/FodyIsolated/WeaverInitialiserTests.cs | 7 +- 3 files changed, 120 insertions(+), 3 deletions(-) diff --git a/FodyHelpers/BaseModuleWeaver.cs b/FodyHelpers/BaseModuleWeaver.cs index c318b41a7..c254938ee 100644 --- a/FodyHelpers/BaseModuleWeaver.cs +++ b/FodyHelpers/BaseModuleWeaver.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Xml.Linq; using Mono.Cecil; using Mono.Cecil.Cil; @@ -17,40 +18,129 @@ public abstract class BaseModuleWeaver /// The full element XML from FodyWeavers.xml. /// public XElement Config { get; set; } = Empty; + + /// + /// Write a log entry to MSBuild with the level + /// + public virtual void WriteDebug(string message) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogDebug(message); + } /// /// Handler for writing a log entry at the level. /// + [Obsolete("Use WriteDebug", false)] public Action LogDebug { get; set; } = m => { }; + + /// + /// Write a log entry to MSBuild with the level + /// + public virtual void WriteInfo(string message) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogInfo(message); + } /// /// Handler for writing a log entry at the level. /// + [Obsolete("Use WriteInfo", false)] public Action LogInfo { get; set; } = m => { }; + /// + /// Write a log entry to MSBuild with level + /// + public virtual void WriteMessage(string message, MessageImportance importance) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogMessage(message, importance); + } + /// /// Handler for writing a log entry at a specific level. /// + [Obsolete("Use WriteMessage", false)] public Action LogMessage { get; set; } = (m, p) => { }; + + /// + /// Write a warning to MSBuild. + /// + public virtual void WriteWarning(string message) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogWarning(message); + } + + /// + /// Write a warning to MSBuild and use for the file and line information. + /// + public virtual void WriteWarning(string message, SequencePoint? sequencePoint) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogWarningPoint(message, sequencePoint); + } + + /// + /// Write a warning to MSBuild and use for the file and line information. + /// + public virtual void WriteWarning(string message, MethodDefinition method) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + Guard.AgainstNull(nameof(method), method); + LogWarningPoint(message, method.GetSequencePoint()); + } /// /// Handler for writing a warning. /// + [Obsolete("Use WriteWarning", false)] public Action LogWarning { get; set; } = m => { }; /// /// Handler for writing a warning at a specific point in the code /// + [Obsolete("Use WriteWarning", false)] public Action LogWarningPoint { get; set; } = (m, p) => { }; + + /// + /// Write an error to MSBuild. + /// + public virtual void WriteError(string message) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogError(message); + } + + /// + /// Write an error to MSBuild and use for the file and line information. + /// + public virtual void WriteError(string message, SequencePoint? sequencePoint) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogErrorPoint(message, sequencePoint); + } + + /// + /// Write a error to MSBuild and use for the file and line information. + /// + public virtual void WriteError(string message, MethodDefinition method) + { + Guard.AgainstNullAndEmpty(nameof(message), message); + LogErrorPoint(message, method.GetSequencePoint()); + } /// /// Handler for writing an error. /// + [Obsolete("Use WriteError", false)] public Action LogError { get; set; } = m => { }; /// /// Handler for writing an error at a specific point in the code. /// + [Obsolete("Use WriteError", false)] public Action LogErrorPoint { get; set; } = (m, p) => { }; /// @@ -143,16 +233,36 @@ public virtual void Cancel() /// public abstract IEnumerable GetAssembliesForScanning(); + /// + /// Find a . + /// Uses all assemblies listed from calling on all weavers. + /// + public TypeDefinition FindTypeDefinition(string name) + { + return FindType(name); + } + /// /// Handler for searching for a type. /// Uses all assemblies listed from calling on all weavers. /// + [Obsolete("Use FindTypeDefinition", false)] public Func FindType { get; set; } = _ => throw new WeavingException($"{nameof(FindType)} has not been set."); + + /// + /// Find a . + /// Uses all assemblies listed from calling on all weavers. + /// + public bool TryFindTypeDefinition(string name, [NotNullWhen(true)] out TypeDefinition? type) + { + return TryFindType(name, out type); + } /// /// Handler for searching for a type. /// Uses all assemblies listed from calling on all weavers. /// + [Obsolete("Use TryFindTypeDefinition", false)] public TryFindTypeFunc TryFindType { get; set; } = (string name, out TypeDefinition? type) => throw new WeavingException($"{nameof(TryFindType)} has not been set."); /// diff --git a/FodyHelpers/TryFindTypeFunc.cs b/FodyHelpers/TryFindTypeFunc.cs index 36ac46474..815fb028c 100644 --- a/FodyHelpers/TryFindTypeFunc.cs +++ b/FodyHelpers/TryFindTypeFunc.cs @@ -1,7 +1,9 @@ -using System.Diagnostics.CodeAnalysis; +using System; +using System.Diagnostics.CodeAnalysis; using Mono.Cecil; namespace Fody { - public delegate bool TryFindTypeFunc(string typeName, [NotNullWhen(true)]out TypeDefinition? type); + [Obsolete("No longer required as BaseModuleWeaver.TryFindType has been replace with BaseModuleWeaver.TryFindTypeDefinition", false)] + public delegate bool TryFindTypeFunc(string typeName, [NotNullWhen(true)] out TypeDefinition? type); } \ No newline at end of file diff --git a/Tests/FodyIsolated/WeaverInitialiserTests.cs b/Tests/FodyIsolated/WeaverInitialiserTests.cs index fb79fd9a4..dadc7daa0 100644 --- a/Tests/FodyIsolated/WeaverInitialiserTests.cs +++ b/Tests/FodyIsolated/WeaverInitialiserTests.cs @@ -28,8 +28,13 @@ public Task ValidPropsFromBase() var moduleWeaver = new ValidFromBaseModuleWeaver(); innerWeaver.SetProperties(weaverEntry, moduleWeaver); var verifySettings = new VerifySettings(); - verifySettings.ModifySerialization(settings => { settings.IgnoreMembersWithType(); }); + verifySettings.ModifySerialization(settings => + { + settings.IgnoreMembersWithType(); + settings.IncludeObsoletes(); + }); verifySettings.UniqueForRuntime(); + return Verify(moduleWeaver, verifySettings); }