Example #1
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Value != null)
            {
                var type = c.Type;
                //var realType = c.Value.GetType();

                if (/*!IsNumeric(type) && type != Types.TimeSpan &&*/ c.Type != typeof(Type) && c.Value.GetType() != typeof(UWay.Skynet.Cloud.Data.Common.DateParts))
                {
                    NamedValueExpression nv;
                    TypeAndValue         tv = new TypeAndValue(type, c.Value);
                    if (!this.map.TryGetValue(tv, out nv))
                    {
                        string name = "p" + (iParam++);
                        nv = new NamedValueExpression(name, SqlType.Get(type), c);
                        this.map.Add(tv, nv);
                    }
                    return(nv);
                }
                //else
                //{

                //}
            }
            return(c);
        }
Example #2
0
 /// <summary>
 /// 将本对象的用户配置值保存到内存中或持久化的配置文件中
 /// </summary>
 public void Save(bool persistent = false)
 {
     if (CurrentContextDict != null)
     {
         foreach (string propertyName in CurrentContextDict.Keys.ToList())
         {
             string[] propertyNames = propertyName.Split('.');
             object   obj           = propertyNames.Length == 1 ? ContextObject : FindObject(propertyNames);
             obj = RefHelper.GetValue(obj, propertyNames[propertyNames.Length - 1]);
             if (obj == null)
             {
                 CurrentContextDict.Remove(propertyName);
             }
             else if (obj.GetType() == typeof(String) || !obj.GetType().IsClass)
             {
                 CurrentContextDict[propertyName] = new TypeAndValue {
                     TypeName = obj.GetType().AssemblyQualifiedName, Value = CommOp.ToFullStr(obj)
                 };
             }
             else
             {
                 CurrentContextDict[propertyName] = new TypeAndValue {
                     TypeName = obj.GetType().AssemblyQualifiedName, Value = JsonHelper.ToJson(obj)
                 };
             }
         }
     }
     if (persistent)
     {
         SaveAllToPersistent();
     }
 }
Example #3
0
 /// <summary>
 /// 从内存中获取指定对象名称的配置值
 /// </summary>
 /// <param name="propertyName"></param>
 /// <returns></returns>
 TypeAndValue GetContextValue(string propertyName)
 {
     if (!CurrentContextDict.ContainsKey(propertyName))
     {
         CurrentContextDict[propertyName] = new TypeAndValue();
     }
     return(CurrentContextDict[propertyName]);
 }
Example #4
0
 protected override Expression VisitConstant(ConstantExpression c)
 {
     if (c.Value != null && !IsNumeric(c.Value.GetType()))
     {
         TypeAndValue tv = new TypeAndValue(c.Type, c.Value);
         if (!this.map.TryGetValue(tv, out NamedValueExpression nv))
         { // re-use same name-value if same type & value
             string name = "p" + (iParam++);
             nv = new NamedValueExpression(name, c);
             this.map.Add(tv, nv);
         }
         return(nv);
     }
     return(c);
 }
Example #5
0
 protected override Expression VisitConstant(ConstantExpression c)
 {
     if (((c.Value == null) || !c.Type.IsArray) && ((c.Value != null) && !this.IsNumeric(c.Value.GetType())))
     {
         NamedValueExpression expression;
         TypeAndValue         key = new TypeAndValue(c.Type, c.Value);
         if (!this.map.TryGetValue(key, out expression))
         {
             expression = new NamedValueExpression("p" + this.iParam++, this.language.TypeSystem.GetColumnType(c.Type), c);
             this.map.Add(key, expression);
         }
         return(expression);
     }
     return(c);
 }
 // ...same for all others, just...
 // ...
 // implement your own for one 'route'
 protected Expression VisitConstant(ConstantExpression c)
 {
     if (c.Value != null && !IsNumeric(c.Value.GetType()))
     {
         NamedValueExpression nv;
         TypeAndValue         tv = new TypeAndValue(c.Type, c.Value);
         if (!this.map.TryGetValue(tv, out nv))       // re-use same name-value if same type & value
         {
             string name = "p" + (iParam++);
             nv = new NamedValueExpression(name, this.language.TypeSystem.GetColumnType(c.Type), c);
             this.map.Add(tv, nv);
         }
         return(nv);
     }
     return(c);
 }
Example #7
0
        /// <summary>
        /// 从Profile中获取并设置本窗体的指定控件的属性值,如果为空则设置默认值
        /// </summary>
        /// <param name="propertyName">用'.'号分隔的控件及属性名称 </param>
        /// <param name="defaultValue">默认值</param>
        public void Load(string propertyName, string defaultValue)
        {
            TypeAndValue value = GetContextValue(propertyName);

            if (String.IsNullOrEmpty(value.Value))
            {
                value.Value = defaultValue;
            }
            //  if (String.IsNullOrEmpty(value.Value)) return;
            string[] propertyNames = propertyName.Split('.');
            object   obj           = FindObject(propertyNames);

            if (obj == null)
            {
                return;
            }
            RefHelper.SetValue(obj, propertyNames[propertyNames.Length - 1], value.Value, RefHelper.LoadType(value.TypeName));
        }
Example #8
0
        protected override ColumnAssignment VisitColumnAssignment(ColumnAssignment ca)
        {
            ca = base.VisitColumnAssignment(ca);
            Expression           expression = ca.Expression;
            NamedValueExpression nv         = null;

            if (expression.NodeType == ExpressionType.Constant)
            {
                var value = (expression as ConstantExpression).Value;
                if (value == null)
                {
                    TypeAndValue tv = new TypeAndValue(ca.Column.Type, null);
                    if (!this.map.TryGetValue(tv, out nv))
                    {
                        string name = "p" + (iParam++);
                        nv = new NamedValueExpression(name, SqlType.Get(ca.Column.Type), Expression.Constant(null, ca.Column.Type));
                        this.map.Add(tv, nv);
                    }
                    expression = nv;
                }
                else
                {
                    var columnType = ca.Column.Type;
                    if (columnType.IsNullable())
                    {
                        columnType = Nullable.GetUnderlyingType(columnType);
                    }

                    if (columnType != value.GetType())
                    {
                        value      = Converter.Convert(value, columnType);
                        expression = Expression.Constant(value);
                    }
                }
            }

            nv = expression as NamedValueExpression;
            if (nv != null)
            {
                expression = new NamedValueExpression(nv.Name, ca.Column.SqlType, nv.Value);
            }
            return(this.UpdateColumnAssignment(ca, ca.Column, expression));
        }
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Value != null && !IsNumeric(c.Value.GetType()))
            {
                var tv = new TypeAndValue(c.Type, c.Value);

                if (this.map.TryGetValue(tv, out DbNamedValueExpression nv) == false)
                {
                    var name = "p" + (iParam++);

                    nv = new DbNamedValueExpression(name, this.language.TypeSystem.GetColumnType(c.Type), c);

                    this.map.Add(tv, nv);
                }

                return(nv);
            }

            return(c);
        }
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Value != null && !this.IsNumeric(c.Value.GetType()))
            {
                NamedValueExpression nv;
                TypeAndValue         tv = new TypeAndValue(c.Type, c.Value);
                if (!this.map.TryGetValue(tv, out nv))   // re-use same name-value if same type & value
                {
                    var queryType = this.language.TypeSystem.GetColumnType(c.Type);

                    if (queryType == null)
                    {
                        return(c);
                    }
                    string name = "@__Param__" + (this.parameterCounter++) + "__";
                    nv = new NamedValueExpression(name, queryType, c);
                    this.map.Add(tv, nv);
                }

                return(nv);
            }

            return(c);
        }
Example #11
0
 // Eval returns the type and, if constant, the value for the
 // expression expr, evaluated at position pos of package pkg,
 // which must have been derived from type-checking an AST with
 // complete position information relative to the provided file
 // set.
 //
 // The meaning of the parameters fset, pkg, and pos is the
 // same as in CheckExpr. An error is returned if expr cannot
 // be parsed successfully, or the resulting expr AST cannot be
 // type-checked.
 public static (TypeAndValue, error) Eval(ptr <token.FileSet> _addr_fset, ptr <Package> _addr_pkg, token.Pos pos, @string expr)
 {
     TypeAndValue      _    = default;
     error             err  = default !;