public BindingDescription SerializableBindingToBinding(string targetName, SerializableBindingDescription description) { return(new BindingDescription { TargetName = targetName, Source = SourceStepDescriptionFrom(description), Mode = description.Mode, }); }
public bool TryParseBindingDescription(string text, out SerializableBindingDescription requestedDescription) { try { Reset(text); requestedDescription = ParseBindingDescription(); return(true); } catch (Exception exception) { Log.Error("Problem parsing binding {0}", exception); requestedDescription = null; return(false); } }
private SourceStepDescription SourceStepDescriptionFrom(SerializableBindingDescription description) { if (description.Path != null) { return(new PathSourceStepDescription() { SourcePropertyPath = description.Path, Converter = FindConverter(description.Converter), ConverterParameter = description.ConverterParameter, FallbackValue = description.FallbackValue }); } if (description.Literal != null) { var literal = description.Literal; if (literal == TibetBindingParser.LiteralNull) { literal = null; } return(new LiteralSourceStepDescription() { Literal = literal, Converter = FindConverter(description.Converter), ConverterParameter = description.ConverterParameter, FallbackValue = description.FallbackValue }); } if (description.Function != null) { // first look for a combiner with the name var combiner = FindCombiner(description.Function); if (combiner != null) { return(new CombinerSourceStepDescription() { Combiner = combiner, InnerSteps = description.Sources == null ? new List <SourceStepDescription>() : description.Sources.Select(s => SourceStepDescriptionFrom(s)).ToList(), Converter = FindConverter(description.Converter), ConverterParameter = description.ConverterParameter, FallbackValue = description.FallbackValue }); } else { // no combiner, then drop back to looking for a converter var converter = FindConverter(description.Function); if (converter == null) { Log.Error("Failed to find combiner or converter for {0}", description.Function); } if (description.Sources == null || description.Sources.Count == 0) { Log.Error("Value Converter {0} supplied with no source", description.Function); return(new LiteralSourceStepDescription() { Literal = null, }); } else if (description.Sources.Count > 2) { Log.Error("Value Converter {0} supplied with too many parameters - {1}", description.Function, description.Sources.Count); return(new LiteralSourceStepDescription() { Literal = null, }); } else { return(new CombinerSourceStepDescription() { Combiner = new ValueConverterValueCombiner(converter), InnerSteps = description.Sources.Select(SourceStepDescriptionFrom).ToList(), Converter = FindConverter(description.Converter), ConverterParameter = description.ConverterParameter, FallbackValue = description.FallbackValue }); } } } // this probably suggests that the path is the entire source object return(new PathSourceStepDescription() { SourcePropertyPath = null, Converter = FindConverter(description.Converter), ConverterParameter = description.ConverterParameter, FallbackValue = description.FallbackValue }); }