Exemplo n.º 1
0
        private static IEncoderDescriptor <TElement> BindArray <TElement>(
            IWriterDefinition <TState, TNative, TEntity> parent, Func <TEntity, IEnumerable <TElement> > getter,
            TreeEncoderDescriptor <TState, TNative, TElement> elementDescriptor)
        {
            var elementDefinition = elementDescriptor.definition;

            parent.Callback = (reader, state, entity) =>
                              reader.WriteAsArray(state, getter(entity), elementDefinition.Callback);

            return(elementDescriptor);
        }
Exemplo n.º 2
0
        protected bool TryLookup <TOther>(string name, out int index, out IWriterDefinition <WriterState, ProtobufValue, TOther> writer)
        {
            index = Array.FindIndex(this.fields, binding => binding.Name == name);

            if (index < 0)
            {
                writer = null;

                return(false);
            }

            writer = new ProtobufWriterDefinition <TOther>(this.fields[index].Fields);

            return(true);
        }
Exemplo n.º 3
0
        private static IEncoderDescriptor <TField> BindField <TField>(
            IWriterDefinition <TState, TNative, TEntity> parentDefinition,
            string name, Dictionary <string, WriterCallback <TState, TNative, TEntity> > parentFields,
            Func <TEntity, TField> getter, TreeEncoderDescriptor <TState, TNative, TField> fieldDescriptor)
        {
            if (parentFields.ContainsKey(name))
            {
                throw new InvalidOperationException($"field '{name}' was declared twice on same descriptor");
            }

            parentDefinition.Callback = (reader, state, entity) => reader.WriteAsObject(state, entity, parentFields);

            var fieldDefinition = fieldDescriptor.definition;

            parentFields[name] = (reader, state, entity) => fieldDefinition.Callback(reader, state, getter(entity));

            return(fieldDescriptor);
        }
Exemplo n.º 4
0
 public TreeEncoderDescriptor(IEncoderConverter <TNative> converter, IWriterDefinition <TState, TNative, TEntity> definition)
 {
     this.converter  = converter;
     this.definition = definition;
     this.fields     = new Dictionary <string, WriterCallback <TState, TNative, TEntity> >();
 }
Exemplo n.º 5
0
 private static void BindValue(IWriterDefinition <TState, TNative, TEntity> parent,
                               Converter <TEntity, TNative> converter)
 {
     parent.Callback = (reader, state, entity) => reader.WriteAsValue(state, converter(entity));
 }