Beispiel #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 public void LoadString(string data)
 {
     template = DotLiquidCore.Template.Parse(data);
 }
Beispiel #2
0
        private static object Liquidize(object obj)
        {
            if (obj == null)
            {
                return(obj);
            }
            if (obj is ILiquidizable)
            {
                return(((ILiquidizable)obj).ToLiquid());
            }
            if (obj is string)
            {
                return(obj);
            }
            if (obj is IEnumerable)
            {
                return(obj);
            }
            if (obj.GetType().GetTypeInfo().IsPrimitive)
            {
                return(obj);
            }
            if (obj is decimal)
            {
                return(obj);
            }
            if (obj is DateTime)
            {
                return(obj);
            }
            if (obj is DateTimeOffset)
            {
                return(obj);
            }
            if (obj is TimeSpan)
            {
                return(obj);
            }
            if (obj is Guid)
            {
                return(obj);
            }
            if (TypeUtility.IsAnonymousType(obj.GetType()))
            {
                return(obj);
            }
            if (obj is KeyValuePair <string, object> )
            {
                return(obj);
            }
            var safeTypeTransformer = Template.GetSafeTypeTransformer(obj.GetType());

            if (safeTypeTransformer != null)
            {
                return(safeTypeTransformer(obj));
            }
            if (obj.GetType().GetTypeInfo().GetCustomAttributes(typeof(LiquidTypeAttribute), false).Any())
            {
                var attr = (LiquidTypeAttribute)obj.GetType().GetTypeInfo().GetCustomAttributes(typeof(LiquidTypeAttribute), false).First();
                return(new DropProxy(obj, attr.AllowedMembers));
            }

            throw new SyntaxException(Liquid.ResourceManager.GetString("ContextObjectInvalidException"), obj.ToString());
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="data"></param>
 public void LoadString(byte[] data)
 {
     template = DotLiquidCore.Template.Parse(System.Text.Encoding.UTF8.GetString(data));
 }