Static method extensions.
MODIFY
src/Chapter06/Listing06.42.DefiningAStaticMethodOnDirectoryInfo.cs
src/Chapter06/Listing06.42.DefiningAStaticMethodOnDirectoryInfo.cs
@@ -3,8 +3,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42
using System;
using System.IO;
- public class Program
- {
+
#region INCLUDE
public static class DirectoryInfoExtension
{
@@ -14,7 +13,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42
SearchOption option, string searchPattern)
#endregion HIGHLIGHT
{
- if (target[target.Length - 1] !=
+ if (target[^1] !=
Path.DirectorySeparatorChar)
{
target += Path.DirectorySeparatorChar;
@@ -51,23 +50,25 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_42
#region EXCLUDE
private static void Copy(string element, string fileName, string searchPattern)
{
- Console.WriteLine("Copying " + fileName);
+ Console.WriteLine(
+ $"Copying(element: {element}, fileName: {fileName}, searchPattern: {searchPattern})");
}
#endregion EXCLUDE
}
- #region EXCLUDE
- public static void Main()
+ public class Program
{
- #endregion EXCLUDE
- DirectoryInfo directory = new(".\\Source");
- directory.MoveTo(".\\Root");
+ public static void Main(params string[] args)
+ {
+ DirectoryInfo source = new(args[0]);
+ string target = args[1];
+
#region HIGHLIGHT
DirectoryInfoExtension.CopyTo(
- directory, ".\\Target",
+ source, target,
SearchOption.AllDirectories, "*");
#endregion HIGHLIGHT
}
- #endregion INCLUDE
}
+ #endregion INCLUDE
}
\ No newline at end of file

Static method extensions.