private static IBindingMetadata FindDynamicMetadata(MetadataIdentity identity) { IBindingMetadata metadata = identity.Lookup <IBindingMetadata>(); while (metadata == null && (identity = identity.Pop()) != null) { metadata = identity.Lookup <IBindingMetadata>(); } if (metadata != null && metadata.HasFlag(BindingMetadataFlags.Dynamic)) { return(metadata); } return(null); }
private static void AddDataNode(NodeTree tree, DataAttribute attribute) { MetadataIdentity identity = new MetadataIdentity(tree.Schema, attribute.Name); IBindingMetadata metadata = identity.Lookup <IBindingMetadata>() ?? FindDynamicMetadata(identity); if (metadata != null) { Node node; if (metadata.HasFlag(BindingMetadataFlags.Dynamic)) { node = AddDynamicNode(tree, identity, metadata); } else { node = AddStaticNode(tree, metadata); } if (node != null) { node.Data = attribute; tree.Data.Add(node); } } }
public RelationHeader <TTarget> Join <TTarget>(Expression <Func <TSource, IEnumerable <TTarget> > > expression) { MetadataIdentity newIdentity = this.Source.Identity.Push(this.Schema.Notation.Lambda(expression)); IRelationMetadata metadata = newIdentity.Lookup <IRelationMetadata>(); return(new RelationHeader <TTarget>(metadata.Item, this.Attributes)); }
public RelationHeader <TSource> SelectAll <TTarget>(Expression <Func <TSource, TTarget> > expression, Func <IRelationMetadata, bool> selector) { MetadataIdentity sourceIdentity = this.Source.Identity.Push(this.Schema.Notation.Lambda(expression)); IReadOnlyList <IRelationMetadata> metadata = sourceIdentity.Lookup <IRelationMetadata>().Properties; return(new RelationHeader <TSource>(this.Source, this.Add(metadata.Where(selector)))); }
public RelationHeader <TSource> Select <TTarget>(Expression <Func <TSource, TTarget> > expression) { MetadataIdentity newIdentity = this.Source.Identity.Push(this.Schema.Notation.Lambda(expression)); IRelationMetadata metadata = newIdentity.Lookup <IRelationMetadata>(); return(new RelationHeader <TSource>(this.Source, this.Add(metadata))); }
private static IRelationMetadata GetMetadata(MetadataIdentity identity) { IRelationMetadata metadata = identity.Lookup <IRelationMetadata>(); if (metadata == null) { throw new InvalidOperationException(identity.Name + " not found"); } return(metadata); }
public BufferConverter Compile(MetadataIdentity metadata, ColumnMetadata columnInfo) { IBindingMetadata binding = metadata.Lookup <IBindingMetadata>(); ParameterExpression inputParam = Expression.Parameter(typeof(object)); ParameterExpression helperParam = Expression.Parameter(typeof(object)); ParameterExpression helperVariable = this.GetHelperVariable(binding); Expression value = inputParam; if (binding != null) { Type sourceType = null; if (columnInfo != null) { BindingColumnInfo bindingColumnInfo = new BindingColumnInfo() { Column = columnInfo, CanBeNull = true, Metadata = binding, }; sourceType = binding.Value?.Read(bindingColumnInfo)?.ReturnType; } BindingValueInfo valueInfo = new BindingValueInfo() { CanBeNull = true, CanBeDbNull = true, Metadata = binding, Value = value, SourceType = sourceType, TargetType = binding.Type, Helper = helperVariable, }; try { value = binding.Value?.Convert?.Invoke(valueInfo) ?? inputParam; } catch (BindingException) { throw; } catch (Exception ex) { throw BindingException.InvalidCast(binding, ex); } } value = this.GetObjectExpression(value); if (helperVariable != null) { Expression typedParam = Expression.Convert(helperParam, helperVariable.Type); Expression assignHelper = Expression.Assign(helperVariable, typedParam); value = Expression.Block(new[] { helperVariable }, assignHelper, value); } BufferInternalConverter innerFunc = Expression.Lambda <BufferInternalConverter>(value, inputParam, helperParam).Compile(); object helperObject = binding?.Helper?.Object; return(value => innerFunc(value, helperObject)); }