Created
April 3, 2021 10:15
-
-
Save mdelanno/79468c1a112bca8b4957c87df96da49e to your computer and use it in GitHub Desktop.
SharpDx : implementation of include handler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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