Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made IView Interface and ViewWrapper class public, Exposed Logger.Write Method (#263) #264

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ public static Action<string> Writer
set => writer = value ?? throw new ArgumentNullException(nameof(value));
}

internal static void Write(
/// <summary>
/// Writes message to <see cref="Logger.Writer"/>.
/// </summary>
/// <param name="message">Message to log.</param>
/// <param name="callerFilePath">Calling file path.</param>
/// <param name="callerMemberName">Calling member name.</param>
/// <exception cref="ArgumentNullException" />
public static void Write(
string message,
[CallerFilePath] string callerFilePath = "",
[CallerMemberName] string callerMemberName = "")
Expand All @@ -39,4 +46,4 @@ internal static void Write(

Writer($"[{Path.GetFileNameWithoutExtension(callerFilePath)}.{callerMemberName}] {message}");
}
}
}
4 changes: 2 additions & 2 deletions src/Views/IView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MvvmDialogs.Views;
/// <summary>
/// Interface describing a view in WPF.
/// </summary>
internal interface IView
public interface IView
{
/// <summary>
/// Occurs when the view is laid out, rendered, and ready for interaction.
Expand Down Expand Up @@ -36,4 +36,4 @@ internal interface IView
/// Gets the owning <see cref="Window"/>.
/// </summary>
Window GetOwner();
}
}
36 changes: 33 additions & 3 deletions src/Views/ViewWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,40 @@

namespace MvvmDialogs.Views;

internal class ViewWrapper : IView
/// <summary>
/// Wraps <see cref="FrameworkElement"/> objects for the properties needed.
/// </summary>
public class ViewWrapper : IView
{
private readonly WeakReference viewReference;

internal ViewWrapper(FrameworkElement view)
/// <summary>
/// Initializes a new instance of the <see cref="ViewWrapper"/> class.
/// </summary>
/// <param name="view"><see cref="FrameworkElement"/> that makes up the view.</param>
/// <exception cref="ArgumentNullException" />
public ViewWrapper(FrameworkElement view)
{
if (view == null) throw new ArgumentNullException(nameof(view));

viewReference = new WeakReference(view);
}


/// <inheritdoc />
public event RoutedEventHandler Loaded
{
add => Source.Loaded += value;
remove => Source.Loaded -= value;
}


/// <inheritdoc />
public int Id { get; } = IdGenerator.Generate();


/// <inheritdoc />
/// <exception cref="InvalidOperationException" />
public FrameworkElement Source
{
get
Expand All @@ -33,19 +48,34 @@ public FrameworkElement Source
}
}

/// <inheritdoc />
public object DataContext => Source.DataContext;

/// <inheritdoc />
public bool IsAlive => viewReference.IsAlive;


/// <inheritdoc />
public Window GetOwner() => Source.GetOwner();


/// <summary>
/// GetHashCode override based on the Source property
/// </summary>
/// <returns>HashCode of Source property</returns>
public override int GetHashCode() => Source.GetHashCode();


/// <summary>
/// Equals Override comparing the Source property
/// </summary>
/// <param name="obj">Object of type <see cref="ViewWrapper"/></param>
/// <returns>True if the object is the same</returns>
public override bool Equals(object? obj)
{
if (!(obj is ViewWrapper other))
return false;

return Source.Equals(other.Source);
}
}
}