public void Render(Context context, TextWriter result) { object output = RenderInternal(context); if (output is ILiquidizable) { output = null; } if (output != null) { // see if this context has a ValueTypeTranformer for the type var transformer = context.GetValueTypeTransformer(output.GetType()); if (transformer == null) { // if the context doesn't have a ValueTypeTranformer for the type, get the global one (if there is one) transformer = Template.GetValueTypeTransformer(output.GetType()); } if (transformer != null) { output = transformer(output); } string outputString; if (output is IEnumerable) #if NET35 { outputString = string.Join(string.Empty, ((IEnumerable)output).Cast <object>().Select(o => o.ToString()).ToArray()); } #else { outputString = string.Join(string.Empty, ((IEnumerable)output).Cast <object>()); } #endif else if (output is bool) { outputString = output.ToString().ToLower(); } else if (output is DateTimeOffset dto) { // Change the default output for a DateTimeOffset to omit the timezone offset. outputString = dto.ToString("G"); } else { outputString = output.ToString(); } result.Write(outputString); }
public void Render(Context context, TextWriter result) { object output = RenderInternal(context); if (output is ILiquidizable) output = null; if (output != null) { // see if this context has a ValueTypeTranformer for the type var transformer = context.GetValueTypeTransformer(output.GetType()); if (transformer == null) { // if the context doesn't have a ValueTypeTranformer for the type, get the global one (if there is one) transformer = Template.GetValueTypeTransformer(output.GetType()); } if(transformer != null) output = transformer(output); string outputString; if (output is IEnumerable) #if NET35 outputString = string.Join(string.Empty, ((IEnumerable)output).Cast<object>().Select(o => o.ToString()).ToArray()); #else outputString = string.Join(string.Empty, ((IEnumerable)output).Cast<object>()); #endif else if (output is bool) outputString = output.ToString().ToLower(); else outputString = output.ToString(); result.Write(outputString); }