예제 #1
0
        public SearchDescriptorBase <TEntity, TId> AddValue <TValue>(string name, bool isOnKey, Expression <Func <TEntity, TValue> > getValue, Func <string, TValue> convert)
        {
            var valueProperty = new FieldSelector <TEntity, TValue>(name, getValue, convert);

            this.Fields[name] = valueProperty;
            if (isOnKey)
            {
                this.DefaultValueProperty = valueProperty;
            }
            return(this);
        }
예제 #2
0
        public ObjectSerializer(IFieldSelector fieldSelector, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            Type = type;
            //TODO: remove version info
            var typeName = type.GetShortAssemblyQualifiedName();
            // ReSharper disable once PossibleNullReferenceException
            // ReSharper disable once AssignNullToNotNullAttribute
            var typeNameBytes = typeName.ToUtf8Bytes();

            var fields      = fieldSelector.SelectFields(type);
            var fieldNames  = fields.Select(field => field.Name.ToUtf8Bytes()).ToList();
            var versionInfo = TypeEx.GetTypeManifest(fieldNames);

            //precalculate the entire manifest for this serializer
            //this helps us to minimize calls to Stream.Write/WriteByte
            _manifest =
                new[] { ManifestFull }
            .Concat(BitConverter.GetBytes(typeNameBytes.Length))
            .Concat(typeNameBytes)
            .ToArray();         //serializer id 255 + assembly qualified name

            //TODO: this should only work this way for standard poco objects
            //custom object serializers should not emit their inner fields

            //this is the same as the above, but including all field names of the type, in alphabetical order
            _manifestWithVersionInfo =
                new[] { ManifestVersion }
            .Concat(BitConverter.GetBytes(typeNameBytes.Length))
            .Concat(typeNameBytes)
            .Concat(versionInfo)
            .ToArray();         //serializer id 255 + assembly qualified name + versionInfo

            //initialize reader and writer with dummy handlers that wait until the serializer is fully initialized
            _writer = (stream, o, session) =>
            {
                SpinWait.SpinUntil(() => _isInitialized);
                WriteValue(stream, o, session);
            };

            _reader = (stream, session) =>
            {
                SpinWait.SpinUntil(() => _isInitialized);
                return(ReadValue(stream, session));
            };
        }
예제 #3
0
        public SerializerOptions(bool versionTolerance = false, bool preserveObjectReferences = false,
                                 IEnumerable <Surrogate> surrogates = null, IEnumerable <ValueSerializerFactory> serializerFactories = null,
                                 IEnumerable <Type> knownTypes      = null, IFieldSelector fieldSelector = null)
        {
            VersionTolerance = versionTolerance;
            Surrogates       = surrogates?.ToArray() ?? EmptySurrogates;

            //use the default factories + any user defined
            ValueSerializerFactories =
                DefaultValueSerializerFactories.Concat(serializerFactories?.ToArray() ?? EmptyValueSerializerFactories)
                .ToArray();

            KnownTypes = knownTypes?.ToArray() ?? new Type[] {};
            for (var i = 0; i < KnownTypes.Length; i++)
            {
                KnownTypesDict.Add(KnownTypes[i], (ushort)i);
            }

            PreserveObjectReferences = preserveObjectReferences;

            FieldSelector = fieldSelector ?? new DefaultFieldSelector();
        }
예제 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AnnotatedFieldDependencySelector"/> class.
 /// </summary>
 /// <param name="fieldSelector">The <see cref="IFieldSelector"/> that is
 /// responsible for selecting a list of injectable fields.</param>
 public AnnotatedFieldDependencySelector(IFieldSelector fieldSelector)
     : base(fieldSelector)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="AnnotatedFieldDependencySelector"/> class.
 /// </summary>
 /// <param name="fieldSelector">The <see cref="IFieldSelector"/> that is 
 /// responsible for selecting a list of injectable fields.</param>
 public AnnotatedFieldDependencySelector(IFieldSelector fieldSelector)
     : base(fieldSelector)
 { }