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); } } }
public FuncColumnKey(MetadataIdentity metadata, ColumnIdentity column) { this.Metadata = metadata; this.Column = column; }
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); }
public void SetCellInfo(ColumnIdentity cellInfo) { this.columnInfo = cellInfo; this.parameter = null; }
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); }
public void SetValue(IDbDataParameter adoParameter) { this.parameter = adoParameter; this.columnInfo = null; }
public FuncColumnKey(MetadataIdentity metadata, ColumnIdentity column) { this.Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); this.Column = column; }
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()); }
public static Action <IField, object> GetFieldBinder(MetadataIdentity metadata, ColumnIdentity column) { FuncColumnKey key = new FuncColumnKey(metadata, column); return(columnMap.GetOrAdd(key, _ => BuildFieldBinder(metadata, column))); }
/// <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++; } } } }