Пример #1
0
        private IReflectClass NormalizeFieldClass(RawFieldSpec fieldInfo, IReflectClass fieldClass
                                                  )
        {
            // TODO: why the following line is necessary?
            IReflectClass theClass = _stream.Reflector().ForName(fieldClass.GetName());

            if (fieldInfo.IsPrimitive())
            {
                theClass = PrimitiveClass(theClass);
            }
            if (fieldInfo.IsArray())
            {
                theClass = ArrayClass(theClass);
            }
            return(theClass);
        }
        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);
        }