public override object readObject(ImportContext ctx, TypeData[] typeArgs = null) { object value = (_type == null) ? null : Activator.CreateInstance(_type); int fieldCount = ctx.readLength(); this.logInfo("Reading " + fieldCount + " fields..."); for (int ii = 0; ii < fieldCount; ii++) { int fieldId = ctx.readId(); FieldData field; if (fieldId < _fields.Count) { field = _fields[fieldId]; } else { // ASSERT the fieldId // TODO if (fieldId != _fields.Count) { this.logWarning("Unexpected field id!", "expected", _fields.Count, "got", fieldId); throw new Exception("Unexpected field id!"); } // new field string name = ctx.readString(); TypeData type = ctx.readType(); FieldInfo fieldInfo; if (_fieldInfo != null) { _fieldInfo.TryGetValue(name, out fieldInfo); if (_fieldInfo == null) { ctx.warn("Importing class no longer has field: " + name); } } else { fieldInfo = null; } // fieldInfo can now be null field = new FieldData(type, fieldInfo); _fields.Add(field); } field.readField(ctx, value); } return value; }
public override object readObject(ImportContext ctx, TypeData[] typeArgs = null) { int size = ctx.readLength(); TypeData elementType = typeArgs[0]; Type setType = getType().MakeGenericType(elementType.getType()); object theSet = Activator.CreateInstance(setType); MethodInfo method = setType.GetMethod("Add"); object[] argArray = new object[1]; Action<object> addAction = obj => { argArray[0] = obj; method.Invoke(theSet, argArray); }; readEntries(ctx, addAction, size, elementType); return theSet; }
public override object readObject(ImportContext ctx, TypeData[] typeArgs = null) { int size = ctx.readLength(); TypeData elementType = typeArgs[0]; Type fullType = typeof(HashMultiset<>).MakeGenericType(elementType.getType()); object value = Activator.CreateInstance(fullType); if (size > 0) { MethodInfo method = fullType.GetMethod("Add", new Type[] { elementType.getType(), typeof(int) }); object[] argArray = new object[2]; for (int ii = 0; ii < size; ii++) { argArray[0] = ctx.readObject(elementType); argArray[1] = ctx.readLength(); method.Invoke(value, argArray); } } return value; }
public override object readObject(ImportContext ctx, TypeData[] typeArgs = null) { int size = ctx.readLength(); TypeData elementType = typeArgs[0]; Type listType = getType().MakeGenericType(elementType.getType()); IList list = (IList)Activator.CreateInstance(listType); readEntries(ctx, o => list.Add(o), size, elementType); return list; }
public override object readObject(ImportContext ctx, TypeData[] typeArgs = null) { int size = ctx.readLength(); TypeData keyType = typeArgs[0]; TypeData valType = typeArgs[1]; Type dicType = getType().MakeGenericType(keyType.getType(), valType.getType()); IDictionary dic = (IDictionary)Activator.CreateInstance(dicType); this.logInfo("Going to be reading in...", "dic", dic, "keyType", keyType.getType()); for (int ii = 0; ii < size; ii++) { dic.Add(ctx.readObject(keyType), ctx.readObject(valType)); } return dic; }
public override object readObject(ImportContext ctx, TypeData[] typeArgs = null) { int size = ctx.readLength(); TypeData elementType = typeArgs[0]; Array array = Array.CreateInstance(elementType.getType(), size); int idx = 0; readEntries(ctx, o => array.SetValue(o, idx++), size, elementType); return array; }