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 void readField(ImportContext ctx, object target)
 {
     object value = ctx.readObject(_type);
     if (_field != null) {
     ctx.setField(_field, target, value);
     }
 }
示例#3
0
 public override object readObject(ImportContext ctx, TypeData[] typeArguments = null)
 {
     return ctx.readString();
 }
示例#4
0
 public abstract object readObject(ImportContext ctx, TypeData[] typeArguments = null);
示例#5
0
 public override object readObject(ImportContext ctx, TypeData[] typeArgs = null)
 {
     return _baseType.readObject(ctx, _args);
 }
示例#6
0
 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;
 }
示例#7
0
 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;
 }
示例#8
0
 public override object readObject(ImportContext ctx, TypeData[] typeArguments = null)
 {
     // TODO: is this correct?
     return ctx.readObject(this);
 }
示例#9
0
        public override object readObject(ImportContext ctx, TypeData[] typeArgs = null)
        {
            string s = ctx.readString();
            if (_type != null) {
            try {
                return Enum.Parse(_type, s);

            } catch (ArgumentException) {
                ctx.warn("could not find enum constant '" + s + "' in type " + _type);
            }
            }
            return null;
        }
示例#10
0
 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;
 }
示例#11
0
 protected void readEntries(
     ImportContext ctx, Action<object> addAction, int size, TypeData expectedElementType)
 {
     for (int ii = 0; ii < size; ii++) {
     addAction(ctx.readObject(expectedElementType));
     }
 }
示例#12
0
 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;
 }
示例#13
0
 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;
 }
 public override object readObject(ImportContext ctx, TypeData[] typeArguments = null)
 {
     throw new Exception("Nothing should call this");
 }
 public override object readObject(ImportContext ctx, TypeData[] typeArgs = null)
 {
     throw new Exception();
 }