public void Read <T>(T target, string input) { var settings = _blocks.SettingsFor(typeof(T)); var block = _parser.Parse(input, settings); var data = new RequestData(new ObjectBlockValues(block, settings, typeof(T))); var context = new BindingContext(data, _services, new NulloBindingLogger()); _resolver.BindProperties(target, context); }
public ObjectBlock BlockFor(object input, BlockWritingContext context, string objectName = null) { Accessor implicitAccessor = null; var type = input.GetType(); if (context.Accessor != null) { var parentSettings = _blocks.SettingsFor(context.Accessor.OwnerType); implicitAccessor = parentSettings.FindImplicitValue(type); } var implicitValue = implicitAccessor != null ? implicitAccessor.GetValue(input).ToString() : null; var properties = _cache.GetPropertiesFor(type).Values; var settings = _blocks.SettingsFor(type); return(new ObjectBlock { Blocks = properties .Where(x => !settings.ShouldIgnore(input, new SingleProperty(x))) .Where(x => x.GetValue(input, null) != null && !isImplicitValue(x, implicitAccessor)) .Select(x => { context.StartProperty(x); var writer = _writerLibrary.WriterFor(context); var block = writer.Write(context); context.FinishProperty(); return block; }).ToList(), Name = _blocks.NameFor(new BlockToken(objectName)), ImplicitValue = implicitValue }); }