Created
March 27, 2019 13:45
-
-
Save MichaelaIvanova/8a6e346eac9024a1caf3e860b52ad7a1 to your computer and use it in GitHub Desktop.
Helper for Filter Attribute to change OnResultExecuted
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
public class MemoryStreamHelper: MemoryStream | |
{ | |
private readonly Stream _responseStream; | |
private readonly Dictionary<string, string> _stringReplacementDictionary; | |
public MemoryStreamHelper(Stream responseStream, Dictionary<string, string> stringReplacementDictionary) | |
{ | |
_responseStream = responseStream; | |
_stringReplacementDictionary = stringReplacementDictionary; | |
} | |
public override void Write(byte[] buffer, int offset, int count) | |
{ | |
string html = Encoding.UTF8.GetString(buffer); | |
//replace values in html | |
html = _stringReplacementDictionary.Aggregate(html, (current, item) => Regex.Replace(current, item.Key + "(?!\" class=\"language)", item.Value)); | |
buffer = Encoding.UTF8.GetBytes(html); | |
_responseStream.Write(buffer, offset, buffer.Length); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment