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

Add XML docs and reduce warnings. #149

Merged
merged 4 commits into from
Oct 16, 2023
Merged
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
1 change: 0 additions & 1 deletion .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ jobs:
uses: actions/checkout@v3
with:
path: Meadow.Contracts
ref: develop

- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/main-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ jobs:
uses: actions/checkout@v3
with:
path: Meadow.Contracts
ref: main

- name: Setup .NET
uses: actions/setup-dotnet@v1
Expand Down
82 changes: 52 additions & 30 deletions Source/Meadow.Contracts/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,31 @@

namespace Meadow;

/// <summary>
/// ExtensionMethods class
/// </summary>
public static class ExtensionMethods
{
/// <summary>
///
/// Contains static extention method to check if the pattern exists within the source
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <param name="source"></param>
/// <param name="pattern"></param>
/// <returns></returns>
/// <returns>true if the pattern exists</returns>
// TODO: move this into the `CircularBuffer` class? or is it broadly applicable?
public static bool Contains<TSource>(this IEnumerable<TSource> source, TSource[] pattern)
{
return (source.FirstIndexOf(pattern) != -1);
}

/// <summary>
/// FirstIndexOf static extention method for an IEnumerable
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <param name="source"></param>
/// <param name="pattern"></param>
/// <returns>the index position of the found pattern</returns>
// TODO: move this into the `CircularBuffer` class? or is it broadly applicable?
public static int FirstIndexOf<TSource>(this IEnumerable<TSource> source, TSource[] pattern)
{
Expand Down Expand Up @@ -106,51 +116,63 @@ public static int Map(this int sourceValue, int sourceMin, int sourceMax, int ta
return (sourceValue - sourceMin) / (sourceMax - sourceMin) * (targetMax - targetMin) + targetMin;
}

/// <summary>
/// Traverses the handler's invocation list and invokes each via the EventHandler() method
/// </summary>
/// <param name="handler">The delegate we are acting upon.</param>
/// <param name="args">The arguments we want to pass to each delegate.</param>
public static void Fire(this Delegate handler, params object[] args)
{
if (handler == null) return;
foreach (var d in handler.GetInvocationList())
{
try
{
d.DynamicInvoke(args);
}
catch (Exception ex)
{
Resolver.Log.Error($"Event handler threw {ex.GetType().Name}: {ex.Message}");
}
}
EventHandler(handler, args);
}

public static void Fire(this EventHandler h, object sender)
/// <summary>
/// Traverses the handler's invocation list and invokes each via the EventHandler() method
/// </summary>
/// <param name="handler">The eventhandler we are acting upon.</param>
/// <param name="sender">The sender object.</param>
public static void Fire(this EventHandler handler, object sender)
{
Fire(h, sender, EventArgs.Empty);
EventHandler(handler, sender, EventArgs.Empty);
}

/// <summary>
/// Traverses the handler's invocation list and invokes each via the EventHandler() method
/// </summary>
/// <param name="handler">The eventhandler we are acting upon.</param>
/// <param name="sender">The sender object.</param>
/// <param name="args">The arguments we want to pass to each delegate.</param>
public static void Fire(this EventHandler handler, object sender, EventArgs args)
{
if (handler == null) return;
foreach (var d in handler.GetInvocationList())
{
try
{
d.DynamicInvoke(sender, args);
}
catch (Exception ex)
{
Resolver.Log.Error($"Event handler threw {ex.GetType().Name}: {ex.Message}");
}
}
EventHandler(handler, sender, args);
}

/// <summary>
/// Traverses the handler's invocation list and invokes each via the EventHandler() method
/// </summary>
/// <param name="handler">The eventhandler we are acting upon.</param>
/// <param name="sender">The sender object.</param>
/// <param name="args">The arguments we want to pass to each delegate.</param>
public static void Fire<T>(this EventHandler<T> handler, object sender, T args) where T : EventArgs
{
if (handler == null) return;
EventHandler(handler, sender, args);
}

/// <summary>
/// Centralised EventHandler that traverses the handler's invocation list and invokes each with the args
/// </summary>
/// <param name="handler">The delegate we are acting upon.</param>
/// <param name="args">The arguments we want to pass to each delegate.</param>
private static void EventHandler(Delegate handler, params object[] args)
{
if (handler == null)
return;

foreach (var d in handler.GetInvocationList())
{
try
{
d.DynamicInvoke(sender, args);
d.DynamicInvoke(args);
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ IPin this[string name]
/// <summary>
/// Gets or sets the IPinController associated with the IPins
/// </summary>
IPinController Controller { get; set; }
IPinController? Controller { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this impact anything in Meadow.Core?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrianstevens Good question, I was refactoring for Meadow.CLI. I'll load up Meadow.Core to see what it throws. Thanks for pointing it out.

Copy link
Contributor Author

@CartBlanche CartBlanche Oct 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per Slack "Meadow.Core builds without errors or warnings, so in theory Meadow.Core has code to check Controller's nullability.

}
}
12 changes: 12 additions & 0 deletions Source/Meadow.Contracts/Hardware/NamedPinGroup.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
namespace Meadow.Hardware
{
/// <summary>
/// NamedPinGroup class
/// </summary>
public class NamedPinGroup
{
/// <summary>
/// The name property of the <see cref="NamedPinGroup"/> class.
/// </summary>
public string Name { get; protected set; }

/// <summary>
/// The Pins array property of the <see cref="NamedPinGroup"/> class.
/// </summary>
public IPin[] Pins { get; protected set; }

/// <summary>
Expand All @@ -23,6 +32,9 @@ public NamedPinGroup(string name, IPin[] pins)
/// <returns>The Name of the <see cref="NamedPinGroup"/> object.</returns>
public override string ToString() => Name;

/// <summary>
/// => operator overload for the IPin[] array.
/// </summary>
public static implicit operator IPin[](NamedPinGroup namedPinGroup) => namedPinGroup.Pins;
}
}
5 changes: 2 additions & 3 deletions Source/Meadow.Contracts/Hardware/PinDefinitionBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ public abstract class PinDefinitionBase : IPinDefinitions
public IList<IPin> AllPins => _pins;

/// <inheritdoc/>
public IPinController Controller { get; set; }
public IPinController? Controller { get; set; }

/// <inheritdoc/>
public IEnumerator<IPin> GetEnumerator() => _pins.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}

}
8 changes: 8 additions & 0 deletions Source/Meadow.Contracts/Hardware/SerialPortName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
/// </summary>
public class SerialPortName
{
/// <summary>
/// The SerialController in documentation
/// </summary>
public ISerialController? SerialController { get; private set; }

/// <summary>
/// The SerialMessageController in documentation
/// </summary>
public ISerialMessageController? SerialMessageController { get; private set; }

/// <summary>
/// The common name used for the port in documentation
/// </summary>
public string FriendlyName { get; set; }

/// <summary>
/// The assigned driver name for the port
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions Source/Meadow.Contracts/Platform OS/IPlatformOS.Storage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,28 @@ public enum ExternalStorageState
/// </summary>
Ejected
}

/// <summary>
/// Contract for external storage devices.
/// </summary>
public interface IExternalStorage
{
/// <summary>
/// Directory information property
/// </summary>
public DirectoryInfo Directory { get; } // this or string???

/// <summary>
/// Eject Storage Device method
/// </summary>
public void Eject();
}

public partial interface IPlatformOS
{
/// <summary>
/// FileSystemInfo property
/// </summary>
public abstract FileSystemInfo FileSystem { get; }

/// <summary>
Expand Down
Loading