コード例 #1
0
ファイル: ItemBuilder.cs プロジェクト: rwredding/jerrycurl
        private void AddValueNode(List <MetadataNode> itemNodes, ColumnIdentity value)
        {
            MetadataIdentity identity = new MetadataIdentity(this.schema, value.Name);
            IBindingMetadata metadata = identity.GetMetadata <IBindingMetadata>() ?? this.FindDynamicMetadata(identity);

            if (metadata != null && !this.IsOutsideResultScope(metadata))
            {
                if (metadata.HasFlag(BindingMetadataFlags.Dynamic))
                {
                    this.AddDynamicNode(itemNodes, identity, metadata, value);
                }
                else
                {
                    this.AddStaticNode(itemNodes, metadata, value);
                }
            }
        }
コード例 #2
0
 public FuncColumnKey(MetadataIdentity metadata, ColumnIdentity column)
 {
     this.Metadata = metadata;
     this.Column   = column;
 }
コード例 #3
0
ファイル: ItemBuilder.cs プロジェクト: rwredding/jerrycurl
        private MetadataNode AddStaticNode(List <MetadataNode> itemNodes, IBindingMetadata metadata, ColumnIdentity value)
        {
            MetadataNode thisNode = this.FindNode(itemNodes, metadata);

            if (thisNode != null)
            {
                thisNode.Column ??= value;
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item))
            {
                MetadataNode itemNode = new MetadataNode(metadata)
                {
                    Metadata = metadata,
                    Column   = value,
                    Flags    = metadata.HasFlag(BindingMetadataFlags.Dynamic) ? NodeFlags.Dynamic : NodeFlags.None,
                };

                if (metadata.Parent.HasFlag(BindingMetadataFlags.Model))
                {
                    itemNode.Flags |= NodeFlags.Result;
                }

                itemNodes.Add(itemNode);

                return(itemNode);
            }
            else
            {
                MetadataNode parentNode = this.FindNode(itemNodes, metadata.Parent) ?? this.AddStaticNode(itemNodes, metadata.Parent, null);

                if (parentNode != null)
                {
                    thisNode = new MetadataNode(metadata)
                    {
                        Metadata = metadata,
                        Column   = value,
                        Flags    = metadata.HasFlag(BindingMetadataFlags.Dynamic) ? NodeFlags.Dynamic : NodeFlags.None,
                    };

                    parentNode.Properties.Add(thisNode);
                }
            }

            return(thisNode);
        }
コード例 #4
0
ファイル: FieldData.cs プロジェクト: mephistoc/jerrycurl
 public void SetCellInfo(ColumnIdentity cellInfo)
 {
     this.columnInfo = cellInfo;
     this.parameter  = null;
 }
コード例 #5
0
ファイル: ItemBuilder.cs プロジェクト: rwredding/jerrycurl
        private MetadataNode AddDynamicNode(List <MetadataNode> itemNodes, MetadataIdentity identity, IBindingMetadata metadata, ColumnIdentity value)
        {
            this.AddStaticNode(itemNodes, metadata, null);

            MetadataNode thisNode = this.FindNode(itemNodes, identity);

            MetadataIdentity parentIdentity = identity.Pop();

            if (thisNode != null)
            {
                thisNode.Column ??= value;
            }
            else if (parentIdentity != null)
            {
                MetadataNode parentNode = this.FindNode(itemNodes, parentIdentity) ?? this.AddDynamicNode(itemNodes, parentIdentity, metadata, null);

                if (parentNode != null)
                {
                    thisNode = new MetadataNode(identity)
                    {
                        Column   = value,
                        Metadata = metadata,
                        Flags    = NodeFlags.Dynamic,
                    };

                    parentNode.Properties.Add(thisNode);
                }
            }

            return(thisNode);
        }
コード例 #6
0
ファイル: FieldData.cs プロジェクト: mephistoc/jerrycurl
 public void SetValue(IDbDataParameter adoParameter)
 {
     this.parameter  = adoParameter;
     this.columnInfo = null;
 }
コード例 #7
0
ファイル: FuncColumnKey.cs プロジェクト: mephistoc/jerrycurl
 public FuncColumnKey(MetadataIdentity metadata, ColumnIdentity column)
 {
     this.Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
     this.Column   = column;
 }
コード例 #8
0
ファイル: FuncCache.cs プロジェクト: mephistoc/jerrycurl
        private static Action <IField, object> BuildFieldBinder(MetadataIdentity metadata, ColumnIdentity column)
        {
            ParameterExpression fieldParam = Expression.Parameter(typeof(IField));
            ParameterExpression valueParam = Expression.Parameter(typeof(object));

            IBindingMetadata binding = metadata.GetMetadata <IBindingMetadata>();

            Expression bindValue = valueParam;

            if (metadata != null)
            {
                Type sourceType = null;

                if (column != null)
                {
                    BindingColumnInfo columnInfo = new BindingColumnInfo()
                    {
                        Column    = column,
                        CanBeNull = true,
                        Metadata  = binding,
                    };

                    sourceType = binding.Value?.Read(columnInfo)?.ReturnType;
                }

                BindingValueInfo valueInfo = new BindingValueInfo()
                {
                    CanBeNull   = true,
                    CanBeDbNull = true,
                    Metadata    = binding,
                    Value       = bindValue,
                    SourceType  = sourceType,
                    TargetType  = binding.Type,
                };

                bindValue = binding.Value?.Convert?.Invoke(valueInfo) ?? valueParam;
            }

            MethodInfo bindMethod = typeof(IField).GetMethod(nameof(IField.Bind), new[] { typeof(object) });

            Expression bindCall = Expression.Call(fieldParam, bindMethod, Expression.Convert(bindValue, typeof(object)));

            return(Expression.Lambda <Action <IField, object> >(bindCall, fieldParam, valueParam).Compile());
        }
コード例 #9
0
ファイル: FuncCache.cs プロジェクト: mephistoc/jerrycurl
        public static Action <IField, object> GetFieldBinder(MetadataIdentity metadata, ColumnIdentity column)
        {
            FuncColumnKey key = new FuncColumnKey(metadata, column);

            return(columnMap.GetOrAdd(key, _ => BuildFieldBinder(metadata, column)));
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the SchemaIdentity class.
        /// </summary>
        /// <param name="reader">The reader to construct from.</param>
        public SchemaIdentity(IDataReader reader)
        {
            int fieldCount = (reader.IsClosed) ? 0 : reader.FieldCount;

            _columns = new ColumnIdentity[fieldCount];

            // if there are no fields, then this is a simple identity
            if (fieldCount == 0)
            {
                return;
            }

            // we have to compare nullable, readonly and identity because it affects bulk copy
            var schemaTable      = reader.GetSchemaTable();
            var isNullableColumn = schemaTable.Columns.IndexOf("AllowDbNull");
            var isReadOnlyColumn = schemaTable.Columns.IndexOf("IsReadOnly");
            var isIdentityColumn = schemaTable.Columns.IndexOf("IsIdentity");

            // we know that we are going to store this in a hashtable, so pre-calculate the hashcode
            unchecked
            {
                // base the hashcode on the column names and types
                _hashCode = 17;

                for (int i = 0; i < fieldCount; i++)
                {
                    var row = schemaTable.Rows[i];

                    var column = new ColumnIdentity()
                    {
                        Name       = reader.GetName(i),
                        Type       = reader.GetFieldType(i),
                        IsNullable = (isNullableColumn == -1) ? false : row.IsNull(isNullableColumn) ? false : Convert.ToBoolean(row[isNullableColumn], CultureInfo.InvariantCulture),
                        IsReadOnly = (isReadOnlyColumn == -1) ? false : row.IsNull(isReadOnlyColumn) ? false : Convert.ToBoolean(row[isReadOnlyColumn], CultureInfo.InvariantCulture),
                        IsIdentity = (isIdentityColumn == -1) ? false : row.IsNull(isIdentityColumn) ? false : Convert.ToBoolean(row[isIdentityColumn], CultureInfo.InvariantCulture),
                    };
                    _columns[i] = column;

                    // update the hash code for the name and type
                    _hashCode *= 23;
                    _hashCode += column.Name.GetHashCode();
                    _hashCode *= 23;
                    _hashCode += column.Type.GetHashCode();
                    _hashCode *= 23;
                    if (column.IsNullable)
                    {
                        _hashCode++;
                    }
                    _hashCode *= 23;
                    if (column.IsReadOnly)
                    {
                        _hashCode++;
                    }
                    _hashCode *= 23;
                    if (column.IsIdentity)
                    {
                        _hashCode++;
                    }
                }
            }
        }