protected void MarshalTop(object obj, WriteCache cache) { IWriteHandler handler = GetHandler(obj); if (handler == null) { throw new NotSupportedException( string.Format("Cannot marshal type {0} ({1})", obj != null ? obj.GetType() : null, obj)); } string tag = handler.Tag(obj); if (tag == null) { throw new NotSupportedException( string.Format("Cannot marshal type {0} ({1})", obj != null ? obj.GetType() : null, obj)); } if (tag.Length == 1) { obj = new Quote(obj); } Marshal(obj, false, cache); }
private IWriteHandler CheckBaseTypes(Type type, IEnumerable <Type> baseTypes) { IDictionary <Type, IWriteHandler> possibles = new Dictionary <Type, IWriteHandler>(); foreach (Type item in baseTypes) { // TODO Better way to decide the most appropriate possibility if (possibles.Count < 1) { IWriteHandler h; if (handlers.TryGetValue(item, out h)) { possibles.Add(item, h); } } } switch (possibles.Count) { case 0: return(null); case 1: { IWriteHandler h = possibles.First().Value; handlers = handlers.Add(type, h); return(h); } default: throw new TransitException("More thane one match for " + type); } }
protected void Marshal(object o, bool asDictionaryKey, WriteCache cache) { bool supported = false; IWriteHandler h = GetHandler(o); if (h != null) { string t = h.Tag(o); if (t != null) { supported = true; if (t.Length == 1) { switch (t[0]) { case '_': EmitNull(asDictionaryKey, cache); break; case 's': EmitString(null, null, Escape((string)h.Representation(o)), asDictionaryKey, cache); break; case '?': EmitBoolean((bool)h.Representation(o), asDictionaryKey, cache); break; case 'i': EmitInteger(h.Representation(o), asDictionaryKey, cache); break; case 'd': EmitDouble(h.Representation(o), asDictionaryKey, cache); break; case 'b': EmitBinary(h.Representation(o), asDictionaryKey, cache); break; case '\'': EmitTagged(t, h.Representation(o), false, cache); break; default: EmitEncoded(t, h, o, asDictionaryKey, cache); break; } } else { if (t.Equals("array")) { EmitList(h.Representation(o), asDictionaryKey, cache); } else if (t.Equals("map")) { EmitDictionary(h.Representation(o), asDictionaryKey, cache); } else { EmitEncoded(t, h, o, asDictionaryKey, cache); } } FlushWriter(); } } if (!supported) { throw new NotSupportedException("Not supported: " + o.GetType()); } }
public static string WritePrintableToString(IEDNWritable printable, IWriteHandler handler) { using (MemoryStream ms = new MemoryStream()) { printable.WriteEDN(ms, handler); ms.Position = 0; var sr = new StreamReader(ms); return(sr.ReadToEnd()); } }
public static string WritePrintableToString(IEDNWritable printable, IWriteHandler handler) { using (MemoryStream ms = new MemoryStream()) { printable.WriteEDN(ms, handler); ms.Position = 0; var sr = new StreamReader(ms); return sr.ReadToEnd(); } }
public string GetTag(object obj) { IWriteHandler handler = GetHandler(obj); if (handler == null) { return(null); } return(handler.Tag(obj)); }
private IWriteHandler GetHandler(object obj) { Type type = (obj != null) ? obj.GetType() : typeof(NullType); IWriteHandler handler = null; if (!handlers.TryGetValue(type, out handler)) { handler = CheckBaseClasses(type); if (handler == null) { handler = CheckBaseGenericInterfaces(type); if (handler == null) { handler = CheckBaseInterfaces(type); } } } return(handler); }
protected void EmitEncoded(string t, IWriteHandler handler, object obj, bool asDictionaryKey, WriteCache cache) { if (t.Length == 1) { object r = handler.Representation(obj); if (r is string) { EmitString(Constants.EscStr, t, (string)r, asDictionaryKey, cache); } else if (PrefersStrings() || asDictionaryKey) { string sr = handler.StringRepresentation(obj); if (sr != null) { EmitString(Constants.EscStr, t, sr, asDictionaryKey, cache); } else { throw new TransitException("Cannot be encoded as a string " + obj); } } else { EmitTagged(t, r, asDictionaryKey, cache); } } else { if (asDictionaryKey) { throw new TransitException("Cannot be used as a map key " + obj); } else { EmitTagged(t, handler.Representation(obj), asDictionaryKey, cache); } } }
public void DelegatePerformanceTest() { int runs = 5000000; StopWatch sw; sw = new StopWatch(); using (sw.Start("Time:{0}")) { for (int i = 0; i < runs; i++) { PerformanceTestTarget(1, null, null); } } // Trace.WriteLine( string.Format("Time:{0}", sw.Elapsed.TotalSeconds) ); WriteHandler writeHandler = new WriteHandler(PerformanceTestTarget); using (sw.Start("Time:{0}")) { for (int i = 0; i < runs; i++) { writeHandler(1, null, null); } } // Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds)); IWriteHandler writeHandler2 = this; using (sw.Start("Time:{0}")) { for (int i = 0; i < runs; i++) { writeHandler2.PerformanceTestTarget(1, null, null); } } // Trace.WriteLine(string.Format("Time:{0}", sw.Elapsed.TotalSeconds)); }
public string WriteEDN(IWriteHandler handler) { return Utils.getSymbolString(prefix, name); }
public string WriteEDN(IWriteHandler handler) { return(Utils.WritePrintableToString(this, handler)); }
public string WriteEDN(IWriteHandler handler) { return ":" + this.ToString(); }
public void WriteEDN(System.IO.Stream stream, IWriteHandler handler) { stream.Write(Utils.openSetBytes, 0, Utils.openSetBytes.Length); handler.handleEnumerable(this, stream, this); stream.Write(Utils.closeSetBytes, 0, Utils.closeSetBytes.Length); }
public string WriteEDN(IWriteHandler handler) { return(Utils.getSymbolString(prefix, name)); }
protected CreateService(IWriteHandler <TModel> handler) { Handler = handler; }
public void WriteEDN(System.IO.Stream stream, IWriteHandler handler) { Utils.WriteEDNToStream(this.ToString(), stream); }
public Workbook ExportData(IWriteHandler handler, Dictionary <string, object> param) { var wb = handler.ExecuteWork(_workbook, param); return(wb); }
public string WriteEDN(IWriteHandler handler) { return(":" + this.ToString()); }