String - ToFileInfo
A string extension method that converts the string object to a file information.
public static string FileName = "test.txt"; public static void Main() { var text = @"<!DOCTYPE html> <html> <body> <h1>This is <b>bold</b> heading</h1> <p>This is <u>underlined</u> paragraph</p> <h2>This is <i>italic</i> heading</h2> </body> </html> "; //C# Extension Method: String - ToFileInfo var file = FileName.ToFileInfo(); // C# Extension Method: FileInfo - WriteAllBytes file.WriteAllText(text); Console.WriteLine(file.ReadAllText()); }
View Source
using System.IO; public static partial class Extensions { /// <summary> /// A string extension method that converts the @this to a file information. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>@this as a FileInfo.</returns> public static FileInfo ToFileInfo(this string @this) { return new FileInfo(@this); } }