コード例 #1
0
        private static string ExpressionToString(Type modelType, Expression expression)
        {
            var data = KnockoutExpressionData.CreateConstructorData();

            data.Aliases[modelType.FullName] = "this";
            return(KnockoutExpressionConverter.Convert(expression, data));
        }
コード例 #2
0
        private static string GetGetExpression(Type modelType, object model, MethodInfo method)
        {
            var expression = method.Invoke(model, null) as Expression;
            var data       = KnockoutExpressionData.CreateConstructorData();

            data.Aliases[modelType.FullName] = "this";
            return(KnockoutExpressionConverter.Convert(expression, data));
        }
コード例 #3
0
        public override string GetKnockoutExpression(KnockoutExpressionData data)
        {
            if (string.IsNullOrWhiteSpace(Value))
            {
                Value = "$data";
            }

            return($"{Name}: '{Value}'");
        }
コード例 #4
0
 private string LocalConvert(Expression expression, KnockoutExpressionData convertData = null)
 {
     lambdaFrom.Clear();
     data = convertData ?? new KnockoutExpressionData();
     data = data.Clone();
     if (data.InstanceNames == null || data.InstanceNames.Length == 0)
         data.InstanceNames = new[] { "" };
     return GetterSetterCorrecting(Visit(expression));
 }
コード例 #5
0
 public KnockoutExpressionData Clone()
 {
     var data = new KnockoutExpressionData();
     if (InstanceNames != null)
         data.InstanceNames = InstanceNames.Clone() as string[];
     if (Aliases != null)
         foreach (var pair in Aliases)
             data.Aliases[pair.Key] = pair.Value;
     data.NeedBracketsForAllMembers = NeedBracketsForAllMembers;
     return data;
 }
コード例 #6
0
 private string LocalConvert(Expression expression, KnockoutExpressionData convertData = null)
 {
     lambdaFrom.Clear();
     data = convertData ?? new KnockoutExpressionData();
     data = data.Clone();
     if (data.InstanceNames == null || data.InstanceNames.Length == 0)
     {
         data.InstanceNames = new[] { "" }
     }
     ;
     return(GetterSetterCorrecting(Visit(expression)));
 }
コード例 #7
0
        protected KnockoutExpressionData CreateData()
        {
            var data = new KnockoutExpressionData();

            if (InstanceNames != null)
            {
                data.InstanceNames = InstanceNames;
            }
            if (Aliases != null)
            {
                data.Aliases = Aliases;
            }
            return(data.Clone());
        }
コード例 #8
0
        public override string GetKnockoutExpression(KnockoutExpressionData data)
        {
            string value = KnockoutExpressionConverter.Convert(ExpressionRaw, data);
            if (string.IsNullOrWhiteSpace(value))
                value = "$data";

            var sb = new StringBuilder();

            sb.Append(Name);
            sb.Append(" : ");
            sb.Append(value);

            return sb.ToString();
        }
コード例 #9
0
        public override string GetKnockoutExpression(KnockoutExpressionData data)
        {
            var builder = new StringBuilder();

            builder.Append(Name);
            builder.Append(" : ");
            if (NeedQuotes)
                builder.Append('\'');
            builder.Append(Value);
            if (NeedQuotes)
                builder.Append('\'');

            return builder.ToString();
        }
コード例 #10
0
        public override string GetKnockoutExpression(KnockoutExpressionData data)
        {
            var sb = new StringBuilder();

              sb.Append(Name);
              sb.Append(" : {");
              for (int i = 0; i < subItems.Count; i++)
              {
            if (i != 0)
              sb.Append(",");
            sb.Append(subItems[i].GetKnockoutExpression(data));
              }
              sb.Append('}');

              return sb.ToString();
        }
コード例 #11
0
        public override string GetKnockoutExpression(KnockoutExpressionData data)
        {
            var builder = new StringBuilder();

            builder.Append(Name);
            builder.Append(" : ");
            if (NeedQuotes)
            {
                builder.Append('\'');
            }
            builder.Append(Value);
            if (NeedQuotes)
            {
                builder.Append('\'');
            }

            return(builder.ToString());
        }
コード例 #12
0
        public KnockoutExpressionData Clone()
        {
            var data = new KnockoutExpressionData();

            if (InstanceNames != null)
            {
                data.InstanceNames = InstanceNames.Clone() as string[];
            }
            if (Aliases != null)
            {
                foreach (var pair in Aliases)
                {
                    data.Aliases[pair.Key] = pair.Value;
                }
            }
            data.NeedBracketsForAllMembers = NeedBracketsForAllMembers;
            return(data);
        }
コード例 #13
0
        public override string GetKnockoutExpression(KnockoutExpressionData data)
        {
            var builder = new StringBuilder();

            builder.Append(Name);
            builder.Append(": {");
            for (int i = 0; i < subItems.Count; i++)
            {
                if (i != 0)
                {
                    builder.Append(", ");
                }
                builder.Append(subItems[i].GetKnockoutExpression(data));
            }
            builder.Append('}');

            return(builder.ToString());
        }
コード例 #14
0
        public KnockoutTagBuilder <TModel> DropDownList <TItem>(Expression <Func <TModel, IList <TItem> > > options, object htmlAttributes = null, Expression <Func <TItem, object> > optionsText = null)
        {
            var tagBuilder = new KnockoutTagBuilder <TModel>(Context, "select", InstanceNames, Aliases);

            tagBuilder.ApplyAttributes(htmlAttributes);
            if (options != null)
            {
                tagBuilder.Options(Expression.Lambda <Func <TModel, IEnumerable> >(options.Body, options.Parameters));
            }
            if (optionsText != null)
            {
                var data = new KnockoutExpressionData {
                    InstanceNames = new[] { "item" }
                };
                tagBuilder.OptionsText("function(item) { return " + KnockoutExpressionConverter.Convert(optionsText, data) + "; }");
            }
            return(tagBuilder);
        }
コード例 #15
0
 public void InstanceNamesTest01()
 {
     var data = new KnockoutExpressionData { InstanceNames = new[] { "$parent" } };
       RunTest((Expression<Func<TestModel, string>>)(model => model.A), "$parent.A", data);
 }
コード例 #16
0
        public static string Convert(Expression expression, KnockoutExpressionData convertData = null)
        {
            var converter = new KnockoutExpressionConverter();

            return(converter.LocalConvert(expression, convertData));
        }
コード例 #17
0
 public void InstanceNamesTest02()
 {
     var data = new KnockoutExpressionData { InstanceNames = new[] { "X", "Y", "Z" } };
       RunTest((Expression<Func<TestModel, TestModel, TestModel, string>>)((x, y, z) => x.A + y.B + z.C), "((X.A()+Y.B())+Z.C())", data);
 }
コード例 #18
0
 private void RunTest(Expression expression, string expected, KnockoutExpressionData data = null)
 {
     string actual = KnockoutExpressionConverter.Convert(expression, data);
       AssertStringEquivalent(expected, actual);
 }
コード例 #19
0
 public abstract string GetKnockoutExpression(KnockoutExpressionData data);
コード例 #20
0
 public abstract string GetKnockoutExpression(KnockoutExpressionData data);
コード例 #21
0
 public static string Convert(Expression expression, KnockoutExpressionData convertData = null)
 {
     var converter = new KnockoutExpressionConverter();
     return converter.LocalConvert(expression, convertData);
 }