private IReflectClass ReflectClassForFieldSpec(RawFieldSpec fieldInfo, IReflector reflector) { if (fieldInfo.IsVirtualField()) { return(VirtualFieldByName(fieldInfo.Name()).ClassReflector(reflector)); } int fieldTypeID = fieldInfo.FieldTypeID(); switch (fieldTypeID) { case Handlers4.UntypedId: { // need to take care of special handlers here return(ObjectClass()); } case Handlers4.AnyArrayId: { return(ArrayClass(ObjectClass())); } default: { IReflectClass fieldClass = ForID(fieldTypeID); if (null != fieldClass) { return(NormalizeFieldClass(fieldInfo, fieldClass)); } break; break; } } return(null); }
private void EnsureClassRead(int id) { IReflectClass clazz = LookupByID(id); ByteArrayBuffer classreader = _stream.ReadStatefulBufferById(_trans, id); ClassMarshaller classMarshaller = MarshallerFamily()._class; RawClassSpec classInfo = classMarshaller.ReadSpec(_trans, classreader); string className = classInfo.Name(); // Having the class in the _classByName Map for now indicates // that the class is fully read. This is breakable if we start // returning GenericClass'es in other methods like forName // even if a native class has not been found if (LookupByName(className) != null) { return; } // step 2 add the class to _classByName and _classes to denote reading is completed Register(className, clazz); int numFields = classInfo.NumFields(); IReflectField[] fields = _builder.FieldArray(numFields); IFieldMarshaller fieldMarshaller = MarshallerFamily()._field; for (int i = 0; i < numFields; i++) { RawFieldSpec fieldInfo = fieldMarshaller.ReadSpec(_stream, classreader); string fieldName = fieldInfo.Name(); IReflectClass fieldClass = ReflectClassForFieldSpec(fieldInfo, _stream.Reflector( )); if (null == fieldClass && (fieldInfo.IsField() && !fieldInfo.IsVirtual())) { throw new InvalidOperationException("Could not read field type for '" + className + "." + fieldName + "'"); } fields[i] = _builder.CreateField(clazz, fieldName, fieldClass, fieldInfo.IsVirtual (), fieldInfo.IsPrimitive(), fieldInfo.IsArray(), fieldInfo.IsNArray()); } _builder.InitFields(clazz, fields); _listeners.NotifyListeners(clazz); }