コード例 #1
0
ファイル: Linker.cs プロジェクト: TurpIF/verse
        /// <summary>
        /// Describe and create decoder for given schema using reflection on target entity and provided binding flags.
        /// </summary>
        /// <typeparam name="TEntity">Entity type</typeparam>
        /// <param name="schema">Entity schema</param>
        /// <param name="bindings">Binding flags used to filter bound fields and properties</param>
        /// <returns>Entity decoder</returns>
        public static IDecoder <TEntity> CreateDecoder <TEntity>(ISchema <TEntity> schema, BindingFlags bindings)
        {
            if (!Linker.LinkDecoder(schema.DecoderDescriptor, bindings, new Dictionary <Type, object>()))
            {
                throw new ArgumentException($"can't link decoder for type '{typeof(TEntity)}'", nameof(schema));
            }

            return(schema.CreateDecoder(ConstructorGenerator.CreateConstructor <TEntity>()));
        }