Skip to content

StorageChangedEventArgs Class

Naveen Dharmathunga edited this page Jan 19, 2026 · 1 revision

StorageChangedEventArgs Class

Provides data for events that signal a change to a storage object, such as creation, modification, deletion, or relocation.

Namespace: Rheo.Storage

Assembly: Rheo.Storage.dll

Definition

public class StorageChangedEventArgs : EventArgs

Inheritance

ObjectEventArgs → StorageChangedEventArgs

Constructors

Constructor Description
StorageChangedEventArgs(StorageChangeType, IStorageInformation) Initializes a new instance with the specified change type and storage information.

Properties

Property Type Description
NewInfo IStorageInformation Gets the most recently retrieved storage information, or null if no information is available.
ChangeType StorageChangeType Gets the type of change that occurred to the storage object.

Remarks

Use this class with event handlers to determine which storage object was affected and the type of change that occurred. The NewInfo property contains the storage information for all change types except Deleted, where the storage object may no longer exist and only the change notification is available.


Constructor Details

StorageChangedEventArgs(StorageChangeType, IStorageInformation)

Initializes a new instance of the StorageChangedEventArgs class with the specified change type and storage information.

public StorageChangedEventArgs(
    StorageChangeType changeType,
    IStorageInformation? storageInformation
)

Parameters

changeType StorageChangeType

The type of change that occurred in the storage. Indicates whether the storage was created, modified, deleted, or relocated.

storageInformation IStorageInformation

The storage information associated with the change. Can be null only if the change type is Deleted.

Exceptions

ArgumentNullException

Thrown if storageInformation is null and changeType is not Deleted.


Property Details

NewInfo

Gets the most recently retrieved storage information, or null if no information is available.

public IStorageInformation? NewInfo { get; }

Property Value

IStorageInformation

The updated storage information after the change, or null for deletion events.

Remarks

This property is null when ChangeType is Deleted, as the storage object no longer exists. For all other change types (Created, Modified, Relocated), this property contains the updated storage information.


ChangeType

Gets the type of change that occurred to the storage object.

public StorageChangeType ChangeType { get; }

Property Value

StorageChangeType

A value indicating whether the storage was created, deleted, modified, or relocated.


Examples

Handling Storage Changes

using Rheo.Storage;

using var file = new FileObject(@"C:\Documents\example.txt");

file.Changed += OnStorageChanged;

void OnStorageChanged(object? sender, StorageChangedEventArgs e)
{
    switch (e.ChangeType)
    {
        case StorageChangeType.Created:
            Console.WriteLine($"Created: {e.NewInfo?.AbsolutePath}");
            break;
            
        case StorageChangeType.Modified:
            Console.WriteLine($"Modified: {e.NewInfo?.AbsolutePath}");
            Console.WriteLine($"New size: {e.NewInfo?.Size} bytes");
            break;
            
        case StorageChangeType.Relocated:
            Console.WriteLine($"Relocated to: {e.NewInfo?.AbsolutePath}");
            break;
            
        case StorageChangeType.Deleted:
            Console.WriteLine("Storage object was deleted");
            // NewInfo is null for deletions
            break;
    }
}

// Trigger events
file.Write(new byte[] { 1, 2, 3 });  // Modified
file.Rename("renamed.txt");           // Relocated
file.Delete();                        // Deleted

Monitoring Directory Changes

using Rheo.Storage;

using var dir = new DirectoryObject(@"C:\Projects");

dir.Changed += (sender, e) =>
{
    if (e.ChangeType == StorageChangeType.Modified && e.NewInfo != null)
    {
        var dirInfo = (DirectoryInformation)e.NewInfo;
        Console.WriteLine($"Directory updated:");
        Console.WriteLine($"  Files: {dirInfo.NoOfFiles}");
        Console.WriteLine($"  Directories: {dirInfo.NoOfDirectories}");
        Console.WriteLine($"  Size: {dirInfo.FormattedSize}");
    }
};

See Also


StorageChangeType Enum

Specifies the type of change that occurred to a storage object.

Namespace: Rheo.Storage

Assembly: Rheo.Storage.dll

Definition

public enum StorageChangeType

Fields

Field Value Description
Created 0 The storage object was created.
Deleted 1 The storage object was deleted.
Modified 2 The storage object was modified.
Relocated 3 The storage object was moved or renamed.

Remarks

This enumeration is used with StorageChangedEventArgs to indicate what type of change occurred to a storage object. The Relocated type covers both move and rename operations, as both result in a change to the object's path.

Examples

Filtering by Change Type

using Rheo.Storage;

using var file = new FileObject(@"C:\Documents\log.txt");

file.Changed += (sender, e) =>
{
    // Only process modifications, ignore relocations
    if (e.ChangeType == StorageChangeType.Modified)
    {
        Console.WriteLine("File content was modified");
        ProcessFileUpdate(e.NewInfo);
    }
};

void ProcessFileUpdate(IStorageInformation? info)
{
    if (info != null)
    {
        Console.WriteLine($"New size: {info.Size} bytes");
        Console.WriteLine($"Modified: {info.LastWriteTime}");
    }
}

Handling Different Change Types

bool HandleStorageChange(StorageChangeType changeType, IStorageInformation? info)
{
    return changeType switch
    {
        StorageChangeType.Created => HandleCreation(info),
        StorageChangeType.Modified => HandleModification(info),
        StorageChangeType.Relocated => HandleRelocation(info),
        StorageChangeType.Deleted => HandleDeletion(),
        _ => false
    };
}

See Also

Clone this wiki locally