Table of Contents

Class MtFile

Namespace
SharpPluginLoader.Core.IO
Assembly
SharpPluginLoader.Core.dll

Represents a file.

public class MtFile : MtObject, IDisposable
Inheritance
MtFile
Implements
Inherited Members

Constructors

MtFile()

public MtFile()

MtFile(nint)

public MtFile(nint instance)

Parameters

instance nint

Properties

IsReadable

Whether the file is readable.

public bool IsReadable { get; }

Property Value

bool

IsWritable

Whether the file is writable.

public bool IsWritable { get; }

Property Value

bool

Path

Gets the path of the file.

public string Path { get; }

Property Value

string

Position

Gets the file pointer.

public long Position { get; }

Property Value

long

Size

Gets the size of the file.

public long Size { get; }

Property Value

long

Methods

Close()

Closes the file.

public void Close()

Remarks

This is called automatically when the file object is destroyed or disposed.

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

~MtFile()

protected ~MtFile()

Open(string, OpenMode, bool)

Opens a file.

public static MtFile? Open(string path, OpenMode mode, bool createPath = true)

Parameters

path string

The path of the file.

mode OpenMode

The mode to open the file in.

createPath bool

Whether to create the path if it does not exist.

Returns

MtFile

The opened file, or null if the file could not be opened.

Read(long)

Reads the specified number of bytes from the file.

public byte[] Read(long size)

Parameters

size long

The number of bytes to read.

Returns

byte[]

The bytes read.

Exceptions

Exception

Thrown if the number of bytes read does not match the number of bytes requested.

Read(Span<byte>, long)

Reads the specified number of bytes from the file.

public long Read(Span<byte> buffer, long count = -1)

Parameters

buffer Span<byte>

The buffer to read into.

count long

The number of bytes to read. If -1, it will read bytes equal to the length of the buffer.

Returns

long

The number of bytes read.

Reopen(string, OpenMode, bool)

Reopens the file.

public bool Reopen(string path, OpenMode mode, bool createPath = true)

Parameters

path string

The path of the file.

mode OpenMode

The mode to open the file in.

createPath bool

Whether to create the path if it does not exist.

Returns

bool

Whether the file was reopened successfully.

Seek(long, SeekOrigin)

Seeks to the specified position in the file.

public long Seek(long offset, SeekOrigin origin)

Parameters

offset long

The offset to seek to.

origin SeekOrigin

The origin to seek from.

Returns

long

The new position in the file.

SetLength(long)

Sets the length of the file.

public void SetLength(long length)

Parameters

length long

The new length of the file.

Write(ReadOnlySpan<byte>)

Writes the specified bytes to the file.

public long Write(ReadOnlySpan<byte> buffer)

Parameters

buffer ReadOnlySpan<byte>

The bytes to write.

Returns

long

The number of bytes written.