public IFieldMapper Parse(JobParser parser, ParseState state) { var selector = state.TryGet("Select", DefaultPath, true); if (selector.StartsWith("/")) { selector = DefaultPath + selector; } var getter = parser.CompileGetter(typeof(T), selector); var name = state.TryGet("Name", DefaultName ?? SuggestName(getter.SuggestedName)); var fieldType = (FieldType)Enum.Parse(typeof(FieldType), state.TryGet("Type", "Dimension"), true); IFieldMapper mapper = new SimpleFieldMapper(state.AffixName(name), scope => SelectItem(scope).TryGet(item => getter.Getter(item, scope), getter.DefaultValue), getter.ValueType, fieldType); var labelState = state.Select("Labels"); if (labelState != null) { var labels = labelState.Keys.ToDictionary(labelState.AffixName, key => (ILabelProvider) new SitecoreFieldLabelProvider(labelState.TryGet <string>(key), parser.DefaultLanguage)); if (labels.Count > 0) { return(new LabeledFieldMapper(mapper, labels)); } } return(mapper); }
public IFieldMapper Parse(JobParser parser, ParseState state) { var source = state.TryGet("Select", "Pages", true); var path = source.Split('.'); source = path[0]; var name = state.TryGet("Name", source); Type itemType; var items = Selectors.SelectFromName(source, out itemType); var selector = string.Join(".", path.Skip(1)); if (string.IsNullOrEmpty(selector)) { selector = Selectors.DefaultSelector(source); } var getterInfo = parser.CompileGetter(itemType, selector); return(new SequenceFieldMapper(name, scope => items(scope).Select(item => getterInfo.Getter(item, scope)), (SequenceType) Enum.Parse(typeof(SequenceType), state.TryGet("Type", "Path"), true))); }