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);
     }
 }
Exemple #3
0
 public override object readObject(ImportContext ctx, TypeData[] typeArguments = null)
 {
     return ctx.readString();
 }
Exemple #4
0
 public abstract object readObject(ImportContext ctx, TypeData[] typeArguments = null);
Exemple #5
0
 public override object readObject(ImportContext ctx, TypeData[] typeArgs = null)
 {
     return _baseType.readObject(ctx, _args);
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #8
0
 public override object readObject(ImportContext ctx, TypeData[] typeArguments = null)
 {
     // TODO: is this correct?
     return ctx.readObject(this);
 }
Exemple #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;
        }
Exemple #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;
 }
Exemple #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));
     }
 }
Exemple #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;
 }
Exemple #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();
 }