public override void EmitString(string prefix, string tag, string s, bool asDictionaryKey, WriteCache cache) { string outString = cache.CacheWrite(Util.MaybePrefix(prefix, tag, s), asDictionaryKey); if (asDictionaryKey) jsonWriter.WritePropertyName(outString); else jsonWriter.WriteValue(outString); }
public override void EmitString(string prefix, string tag, string s, bool asDictionaryKey, WriteCache cache) { string outString = cache.CacheWrite(Util.MaybePrefix(prefix, tag, s), asDictionaryKey); if (asDictionaryKey) { jsonWriter.WritePropertyName(outString); } else { jsonWriter.WriteValue(outString); } }
public void TestWriteCacheDisabled() { WriteCache wc = new WriteCache(false); Assert.AreEqual("foobar", wc.CacheWrite("foobar", false)); Assert.AreEqual("foobar", wc.CacheWrite("foobar", false)); Assert.AreEqual("foobar", wc.CacheWrite("foobar", true)); Assert.AreEqual("foobar", wc.CacheWrite("foobar", true)); }
public void TestWriteCache() { WriteCache wc = new WriteCache(true); Assert.AreEqual("~:foo", wc.CacheWrite("~:foo", false)); Assert.AreEqual("^" + (char)WriteCache.BaseCharIdx, wc.CacheWrite("~:foo", false)); Assert.AreEqual("~$bar", wc.CacheWrite("~$bar", false)); Assert.AreEqual("^" + (char)(WriteCache.BaseCharIdx + 1), wc.CacheWrite("~$bar", false)); Assert.AreEqual("~#baz", wc.CacheWrite("~#baz", false)); Assert.AreEqual("^" + (char)(WriteCache.BaseCharIdx + 2), wc.CacheWrite("~#baz", false)); Assert.AreEqual("foobar", wc.CacheWrite("foobar", false)); Assert.AreEqual("foobar", wc.CacheWrite("foobar", false)); Assert.AreEqual("foobar", wc.CacheWrite("foobar", true)); Assert.AreEqual("^" + (char)(WriteCache.BaseCharIdx + 3), wc.CacheWrite("foobar", true)); Assert.AreEqual("abc", wc.CacheWrite("abc", false)); Assert.AreEqual("abc", wc.CacheWrite("abc", false)); Assert.AreEqual("abc", wc.CacheWrite("abc", true)); Assert.AreEqual("abc", wc.CacheWrite("abc", true)); }