Exemplo n.º 1
0
        /// <summary>
        /// Gets parameters binding.
        /// </summary>
        public IReadOnlyList <IDbParameterBinding> GetParametersBinding(Type type)
        {
            lock (parametersBinding)
            {
                if (!parametersBinding.TryGetValue(type, out var bindingList))
                {
                    var newBindingList = new List <IDbParameterBinding>();

                    foreach (var propInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                    {
                        var typeArguments = new[] { type, propInfo.PropertyType };

                        if (TypeHelper.GetAttribute <DbParameterAttribute>(propInfo, out var pAttr))
                        {
                            var binding = TypeHelper.AddBinding(newBindingList, typeof(DbParameterBinding <,>), typeArguments, this, propInfo, pAttr);
                            binding.CalcBindingMode();
                        }
                    }

                    bindingList = newBindingList;
                    parametersBinding.Add(type, bindingList);
                }

                return(bindingList);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Add properties defined in the template.
        /// </summary>
        private void AddProperties()
        {
            foreach (var propInfo in TemplateType.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
            {
                var typeArguments = new[] { TemplateType, propInfo.PropertyType };

                if (TypeHelper.GetAttribute <DbRecordsetAttribute>(propInfo, out var rsAttr))
                {
                    Mode = DbExecutionMode.Query;
                    AssertRecordsetIndex(rsAttr.Index);
                    TypeHelper.AddBinding(ref recordsets, typeof(DbRecordsetBinding <,>), typeArguments, Setup, propInfo, rsAttr);
                }
                else if (TypeHelper.GetAttribute <DbRecordAttribute>(propInfo, out var rAttr))
                {
                    Mode = DbExecutionMode.Query;
                    AssertRecordsetIndex(rsAttr.Index);
                    TypeHelper.AddBinding(ref records, typeof(DbRecordBinding <,>), typeArguments, Setup, propInfo, rAttr);
                }
                else if (TypeHelper.GetAttribute <DbFieldAttribute>(propInfo, out var fAttr) ||
                         TypeHelper.GetAttribute <DbColumnAttribute>(propInfo, out var cAttr) && (fAttr = new DbFieldAttribute(cAttr)) != null)
                {
                    Mode = DbExecutionMode.Query;
                    TypeHelper.AddBinding(ref fields, typeof(DbFieldBinding <,>), typeArguments, Setup, propInfo, fAttr);
                }
                else if (TypeHelper.GetAttribute <DbParameterAttribute>(propInfo, out var pAttr))
                {
                    TypeHelper.AddBinding(ref parameters, typeof(DbParameterBinding <,>), typeArguments, Setup, propInfo, pAttr);
                }
            }
        }