Show / Hide Table of Contents

Class AgedFileInfo

This class extends a FileInfo object with a custom IComparable interface implementation.

Inheritance
System.Object
AgedFileInfo
Namespace: WizardWrx.Core
Assembly: WizardWrx.Core.dll
Syntax
public class AgedFileInfo : IComparable<AgedFileInfo>
Remarks

This class and AgedFileInfoCollection are designed to be used together to achieve the goal of processing a list of the files that match a file specification from newest to oldest.

These objects are not intended for independent use, since they must go into a collection that can be sorted to leverage the IComparable interface implementation that permits them to be sorted in reverse order by LastWriteTimeUTC.

Each AgedFileInfo is a FileInfo object, wrapped in a small class that augments it with a custom IComparable interface implementation that allows the list to be sorted by LastWriteTimeUTC. Using LastWriteTimeUTC guarantees that the files are always sorted correctly, even when the set includes one or more files that were created during the transition hour that occurs twice annually, on the days when the transitions to and from Daylight Saving Time occur. LastWriteTimeUTC time stamps created during this hour are not guaranteed to sort correctly, especially during the "fall back" transition that occurs in Autumn, when the local time is set back by 1 hour, so that there are two hours during which the same local hour is reported.

In the course of investigating an unexpected exception, I again read the recommendation from Microsoft (published in the MSDN library) about overriding other methods (Equals and GetHashCode), implementing other interfaces (IEquatable and IEqualityComparer), and overloading the equality and inequality operators, all of which I went ahead and did, even though doing so is almost certainly overkill for this class.

Constructors

| Improve this Doc View Source

AgedFileInfo()

The default constructor would be private, except that I believe that it must be marked as Public to satisfy the IComparable and IList interfaces.

Declaration
public AgedFileInfo()
| Improve this Doc View Source

AgedFileInfo(FileInfo)

The single overloaded constructor stashes a reference to a FileInfo, which this class augments with a custom implementation of the IComparable interface that supports inverse ordering.

Declaration
public AgedFileInfo(FileInfo pfileInfo)
Parameters
Type Name Description
FileInfo pfileInfo

Pass in a reference to the FileInfo to be stored in the instance.

Properties

| Improve this Doc View Source

Details

Return a reference to the FileInfo that was loaded into the constructor.

Declaration
public FileInfo Details { get; }
Property Value
Type Description
FileInfo
Remarks

While this protects the reference against destruction, it doesn't prevent callers from changing read/write properties. For that, each property must be individually exposed as a read-only property.

Methods

| Improve this Doc View Source

Equals(Object)

Override the base imp0lementation of the Equals method to return a result that is consistent with the algorithm implemented by the IComparable interface.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The object against which to compare must be another AgedFileInfo, or the return value is False.

Returns
Type Description
System.Boolean

The returned Boolean value is that returned by comparing the two _fileInfo.LastAccessTimeUtc.Ticks property values.

| Improve this Doc View Source

GetHashCode()

Override the base GetHashCode method to return a result that is consistent with the algorithm implemented by the IComparable interface.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

The return value is the HashCode of the LastWriteTimeUTC.Ticks property of the underlying FileInfo object.

| Improve this Doc View Source

ToString()

Override the base class ToString method, so that it renders the most critical properties of the underlying file.

Declaration
public override string ToString()
Returns
Type Description
System.String

The returned string lists the name of the exporting class, as usual, but followed immediately by the key properties that a debugger will most likely need.

  • Improve this Doc
  • View Source
Back to top Generated by DocFX