Skip to content

Instantly share code, notes, and snippets.

@mdelanno
Created April 3, 2021 10:15
Show Gist options
  • Save mdelanno/79468c1a112bca8b4957c87df96da49e to your computer and use it in GitHub Desktop.
Save mdelanno/79468c1a112bca8b4957c87df96da49e to your computer and use it in GitHub Desktop.
SharpDx : implementation of include handler
class IncludeHandler : Include
{
readonly string directoryName;
public IncludeHandler(string directoryName)
{
this.directoryName = directoryName;
}
public void Dispose()
{
}
public IDisposable Shadow { get; set; }
public Stream Open(IncludeType type, string fileName, Stream parentStream)
{
switch (type)
{
case IncludeType.Local:
string d = parentStream switch
{
null => directoryName,
FileStream fileStream => Path.GetDirectoryName(fileStream.Name),
_ => throw new NotSupportedException()
};
return File.OpenRead(Path.Combine(d, fileName));
default:
throw new ArgumentOutOfRangeException(nameof(type), type, null);
}
}
public void Close(Stream stream)
{
stream.Close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment