public override void writeObject(ExportContext ctx, object value, TypeData[] typeArguments = null) { // TODO: is this correct? ctx.writeObject(value, this); }
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)); } }
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); } }
protected void writeEntries( ExportContext ctx, IEnumerable enumerable, int size, TypeData expectedElementType) { ctx.writeLength(size); foreach (object entry in enumerable) { ctx.writeObject(entry, expectedElementType); } }
public void writeField( ExportContext ctx, ExportingReflectiveTypeData sourceTypeData, object source) { if (_fieldId == -1) { _fieldId = sourceTypeData.getNextFieldId(); // this.logInfo("Writing new field", // "fieldId", _fieldId, // "name", _name, // "type", _type); ctx.writeId(_fieldId); ctx.writeString(_name); ctx.writeType(_type); } else { ctx.writeId(_fieldId); } ctx.writeObject(_field.GetValue(source), _type); }