public override void writeObject(ExportContext ctx, object value, TypeData[] typeArgs = null) { // make a list of all the fields that have changed, then send only those // TODO: Improve this.. Perhaps it writes them all to a new stream, a byte[], so that // we can insert the length afterwards... ugh... List<FieldData> fields = null; foreach (FieldData field in _fields) { if (field.hasChanged(value)) { (fields ?? (fields = new List<FieldData>())).Add(field); } } if (fields == null) { ctx.writeLength(0); return; } ctx.writeLength(fields.Count); foreach (FieldData field in fields) { field.writeField(ctx, this, value); } }
public override void writeObject(ExportContext ctx, object value, TypeData[] typeArgs = null) { // TODO: we should consider making a non-generic IMuliset interface for easy wildcarding TypeData elementType = typeArgs[0]; Type fullType = value.GetType(); int size = (int)fullType.GetProperty("ElementCount").GetValue(value, null); ctx.writeLength(size); if (size == 0) { return; } IEnumerable en = (IEnumerable)fullType.GetMethod("EntrySet").Invoke(value, null); PropertyInfo getKey = null, getVal = null; foreach (var entry in en) { if (getKey == null) { Type entryType = entry.GetType(); getKey = entryType.GetProperty("Key"); getVal = entryType.GetProperty("Value"); } this.logInfo("Writing value of multiset", "value", getKey.GetValue(entry, null)); ctx.writeObject(getKey.GetValue(entry, null), elementType); ctx.writeLength((int)getVal.GetValue(entry, null)); } }
protected void writeEntries( ExportContext ctx, IEnumerable enumerable, int size, TypeData expectedElementType) { ctx.writeLength(size); foreach (object entry in enumerable) { ctx.writeObject(entry, expectedElementType); } }
public override void writeObject(ExportContext ctx, object value, TypeData[] typeArgs = null) { TypeData keyType = typeArgs[0]; TypeData valType = typeArgs[1]; Type fullType = value.GetType(); int size = (int)fullType.GetProperty("Count").GetValue(value, null); ctx.writeLength(size); if (size == 0) { return; } Type entryType = typeof(KeyValuePair<,>).MakeGenericType( keyType.getType(), valType.getType()); Type ienumerableType = typeof(IEnumerable<>).MakeGenericType(entryType); IEnumerator en = (IEnumerator) ienumerableType.GetMethod("GetEnumerator").Invoke(value, null); PropertyInfo getKey = entryType.GetProperty("Key"); PropertyInfo getVal = entryType.GetProperty("Value"); while (en.MoveNext()) { var entry = en.Current; ctx.writeObject(getKey.GetValue(entry, null), keyType); ctx.writeObject(getVal.GetValue(entry, null), valType); } }