Skip to content

Commit

Permalink
Obsolete function delegates
Browse files Browse the repository at this point in the history
fixes #804
  • Loading branch information
SimonCropp committed Feb 2, 2020
1 parent 1fabfa2 commit 0d8edd0
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 3 deletions.
110 changes: 110 additions & 0 deletions 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;
Expand All @@ -17,40 +18,129 @@ public abstract class BaseModuleWeaver
/// The full element XML from FodyWeavers.xml.
/// </summary>
public XElement Config { get; set; } = Empty;

/// <summary>
/// Write a log entry to MSBuild with the <see cref="MessageImportance.Low"/> level
/// </summary>
public virtual void WriteDebug(string message)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogDebug(message);
}

/// <summary>
/// Handler for writing a log entry at the <see cref="MessageImportance.Low"/> level.
/// </summary>
[Obsolete("Use WriteDebug", false)]
public Action<string> LogDebug { get; set; } = m => { };

/// <summary>
/// Write a log entry to MSBuild with the <see cref="MessageImportance.Normal"/> level
/// </summary>
public virtual void WriteInfo(string message)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogInfo(message);
}

/// <summary>
/// Handler for writing a log entry at the <see cref="MessageImportance.Normal"/> level.
/// </summary>
[Obsolete("Use WriteInfo", false)]
public Action<string> LogInfo { get; set; } = m => { };

/// <summary>
/// Write a log entry to MSBuild with <paramref name="importance"/> level
/// </summary>
public virtual void WriteMessage(string message, MessageImportance importance)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogMessage(message, importance);
}

/// <summary>
/// Handler for writing a log entry at a specific <see cref="MessageImportance"/> level.
/// </summary>
[Obsolete("Use WriteMessage", false)]
public Action<string, MessageImportance> LogMessage { get; set; } = (m, p) => { };

/// <summary>
/// Write a warning to MSBuild.
/// </summary>
public virtual void WriteWarning(string message)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogWarning(message);
}

/// <summary>
/// Write a warning to MSBuild and use <paramref name="sequencePoint"/> for the file and line information.
/// </summary>
public virtual void WriteWarning(string message, SequencePoint? sequencePoint)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogWarningPoint(message, sequencePoint);
}

/// <summary>
/// Write a warning to MSBuild and use <paramref name="method"/> for the file and line information.
/// </summary>
public virtual void WriteWarning(string message, MethodDefinition method)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
Guard.AgainstNull(nameof(method), method);
LogWarningPoint(message, method.GetSequencePoint());
}

/// <summary>
/// Handler for writing a warning.
/// </summary>
[Obsolete("Use WriteWarning", false)]
public Action<string> LogWarning { get; set; } = m => { };

/// <summary>
/// Handler for writing a warning at a specific point in the code
/// </summary>
[Obsolete("Use WriteWarning", false)]
public Action<string, SequencePoint?> LogWarningPoint { get; set; } = (m, p) => { };

/// <summary>
/// Write an error to MSBuild.
/// </summary>
public virtual void WriteError(string message)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogError(message);
}

/// <summary>
/// Write an error to MSBuild and use <paramref name="sequencePoint"/> for the file and line information.
/// </summary>
public virtual void WriteError(string message, SequencePoint? sequencePoint)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogErrorPoint(message, sequencePoint);
}

/// <summary>
/// Write a error to MSBuild and use <paramref name="method"/> for the file and line information.
/// </summary>
public virtual void WriteError(string message, MethodDefinition method)
{
Guard.AgainstNullAndEmpty(nameof(message), message);
LogErrorPoint(message, method.GetSequencePoint());
}

/// <summary>
/// Handler for writing an error.
/// </summary>
[Obsolete("Use WriteError", false)]
public Action<string> LogError { get; set; } = m => { };

/// <summary>
/// Handler for writing an error at a specific point in the code.
/// </summary>
[Obsolete("Use WriteError", false)]
public Action<string, SequencePoint?> LogErrorPoint { get; set; } = (m, p) => { };

/// <summary>
Expand Down Expand Up @@ -143,16 +233,36 @@ public virtual void Cancel()
/// </summary>
public abstract IEnumerable<string> GetAssembliesForScanning();

/// <summary>
/// Find a <see cref="TypeDefinition"/>.
/// Uses all assemblies listed from calling <see cref="GetAssembliesForScanning"/> on all weavers.
/// </summary>
public TypeDefinition FindTypeDefinition(string name)
{
return FindType(name);
}

/// <summary>
/// Handler for searching for a type.
/// Uses all assemblies listed from calling <see cref="GetAssembliesForScanning"/> on all weavers.
/// </summary>
[Obsolete("Use FindTypeDefinition", false)]
public Func<string, TypeDefinition> FindType { get; set; } = _ => throw new WeavingException($"{nameof(FindType)} has not been set.");

/// <summary>
/// Find a <see cref="TypeDefinition"/>.
/// Uses all assemblies listed from calling <see cref="GetAssembliesForScanning"/> on all weavers.
/// </summary>
public bool TryFindTypeDefinition(string name, [NotNullWhen(true)] out TypeDefinition? type)
{
return TryFindType(name, out type);
}

/// <summary>
/// Handler for searching for a type.
/// Uses all assemblies listed from calling <see cref="GetAssembliesForScanning"/> on all weavers.
/// </summary>
[Obsolete("Use TryFindTypeDefinition", false)]
public TryFindTypeFunc TryFindType { get; set; } = (string name, out TypeDefinition? type) => throw new WeavingException($"{nameof(TryFindType)} has not been set.");

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions 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);
}
7 changes: 6 additions & 1 deletion Tests/FodyIsolated/WeaverInitialiserTests.cs
Expand Up @@ -28,8 +28,13 @@ public Task ValidPropsFromBase()
var moduleWeaver = new ValidFromBaseModuleWeaver();
innerWeaver.SetProperties(weaverEntry, moduleWeaver);
var verifySettings = new VerifySettings();
verifySettings.ModifySerialization(settings => { settings.IgnoreMembersWithType<ModuleDefinition>(); });
verifySettings.ModifySerialization(settings =>
{
settings.IgnoreMembersWithType<ModuleDefinition>();
settings.IncludeObsoletes();
});
verifySettings.UniqueForRuntime();

return Verify(moduleWeaver, verifySettings);
}

Expand Down

0 comments on commit 0d8edd0

Please sign in to comment.