예제 #1
0
 public override bool CanRead(byte initialOctet)
 {
     return(ClassDefinitionConverter.CanRead(initialOctet) ||
            (0x60 <= initialOctet && initialOctet <= 0x6f) ||
            Constants.BC_OBJECT == initialOctet ||
            base.CanRead(initialOctet));
 }
예제 #2
0
        public override object ReadValueNotExisted(HessianReader reader, HessianContext context, Type objectType, byte initialOctet)
        {
            if (ClassDefinitionConverter.CanRead(initialOctet))
            {
                ClassDefinitionConverter.ReadValue(reader, context, typeof(ClassDefinition), initialOctet);
                initialOctet = reader.ReadByte();
            }

            int definitionIndex = 0;

            if (0x60 <= initialOctet && initialOctet <= 0x6f)
            {
                definitionIndex = initialOctet - Constants.BC_OBJECT_DIRECT;
            }
            else if (Constants.BC_OBJECT == initialOctet)
            {
                definitionIndex = (int)IntConverter.ReadValue(reader, context, typeof(int));
            }
            var definition = context.ClassRefs.GetItem(definitionIndex);

            object value = null;

            if (definition.Type.IsEnum)
            {
                definition.VisitFields(field =>
                {
                    var fieldValue = AutoConverter.ReadValue(reader, context, field.Type);
                    if (field.Name == "name")
                    {
                        value = Enum.Parse(definition.Type, (string)fieldValue);
                        context.ValueRefs.AddItem(value);
                    }
                });
            }
            else
            {
                value = Activator.CreateInstance(definition.Type);
                context.ValueRefs.AddItem(value);
                definition.VisitFields(field =>
                {
                    var fieldValue = AutoConverter.ReadValue(reader, context, field.Type);
                    field.Setter(value, fieldValue);
                });
            }
            return(value);
        }