public string GenClientSerialize(IEnumerable <ModelMeta> ast, IEnumerable <Type> types) { var topTemplate = ResourceLoader.Load("AutoClientTemplate.txt"); var coder = GenSerializeCoder(true); return(string.Format(topTemplate, dumpCoder.Code(types) + "\n" + coder.Code(ast), GenModelVersion(ast))); }
public string Code(T meta) { try { return(pred(meta) ? coder.Code(meta) : ZeroCoder <T> .Instance.Code(meta)); } catch (Exception e) { Console.WriteLine(e); throw; } }
public override string Code(IEnumerable <T> meta) { bool first = true; return(meta.Where(m => predicate(m)).Select(m => coder.Code(m)).Aggregate("", (val, cur) => { if (first) { first = false; return val + cur; } return val + seperator + cur; })); }
public static byte[] Code(this ICoder coder, byte[] input, int outputStreamLength, int minimumOutputLength = -1) { Contract.Requires(coder != null); Contract.Requires(input != null); Contract.Requires(outputStreamLength >= 0); Contract.Requires(minimumOutputLength >= -1); Contract.Ensures(Contract.Result <byte[]>() != null); using (var inStream = new MemoryStream(input)) { using (var outStream = new MemoryStream(outputStreamLength)) { coder.Code(inStream, outStream, input.Length, minimumOutputLength, null); return(outStream.ToArray()); } } }
public static ICoder <T> GenCombineReverse <T, T1>(ICoder <T1> tCoder, ICoder <T> t1Coder, Func <T, T1> selector) where T : class where T1 : class { return(new SequenceCoder <T>(meta => tCoder.Code(selector(meta)), t1Coder.Code)); }
public static ICoder <T> GenCombine <T, T1>(ICoder <T> tCoder, ICoder <T1> t1Coder, Func <T, T1> selector) { return(new SequenceCoder <T>(tCoder.Code, meta => t1Coder.Code(selector(meta)))); }
public static async Task CodeAsync(this ICoder self, Stream inStream, Stream outStream, long inSize, long outSize, ICodingProgress progress = null) { await Task.Factory.StartNew(() => self.Code(inStream, outStream, inSize, outSize, progress)) .ConfigureAwait(false); }
public static ICoder <T> Combine_Gen <T, T1>(ICoder <T> tCoder, ICoder <T1> t1Coder, Func <T, T1> selector) { return(new SequenceCoder <T>(new ICoder[] { tCoder, t1Coder }, (meta, arr) => $"{tCoder.Code(meta)}-{t1Coder.Code(selector(meta))}")); }
public static ICoder <T> WithPrefix <T>(this ICoder <T> coder, string prefix) { var coderPrefix = new UnitCoder <T>(prefix); return(new SequenceCoder <T>(new ICoder[] { coderPrefix, coder }, (meta, arr) => string.Join("", coderPrefix.Code(meta), coder.Code(meta)))); }