public object Clone()
        {
            MathExpMethod mem = new MathExpMethod();

            if (_exp != null)
            {
                mem._exp = (IMathExpression)_exp.Clone();
            }
            mem._action = _action;
            return(mem);
        }
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context != null && context.Instance != null && provider != null)
     {
         ParameterValue pv = context.Instance as ParameterValue;
         if (pv == null)
         {
             MapItem item = context.Instance as MapItem;
             if (item != null)
             {
                 pv = item.Item.Value as ParameterValue;
             }
         }
         if (pv == null)
         {
             pv = value as ParameterValue;
         }
         if (pv != null)
         {
             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
             if (edSvc != null)
             {
                 IMathExpression mew = value as IMathExpression;
                 if (mew == null)
                 {
                     mew = pv.MathExpression;
                     if (mew == null)
                     {
                         MathNodeRoot r = new MathNodeRoot();
                         r.Name = pv.Name;
                         mew    = r;
                     }
                 }
                 System.Drawing.Point curPoint = System.Windows.Forms.Cursor.Position;
                 rc.X = curPoint.X;
                 rc.Y = curPoint.Y;
                 IMathEditor dlg = mew.CreateEditor(rc);
                 //
                 MathPropertyGrid pg   = null;
                 Type             t    = edSvc.GetType();
                 PropertyInfo     pif0 = t.GetProperty("OwnerGrid");
                 if (pif0 != null)
                 {
                     object g = pif0.GetValue(edSvc, null);
                     pg = g as MathPropertyGrid;
                 }
                 IMethod imScope = pv.ScopeMethod;
                 if (imScope == null)
                 {
                     imScope = mew.ScopeMethod;
                     if (imScope == null)
                     {
                         if (pg != null)
                         {
                             imScope = pg.ScopeMethod;
                         }
                     }
                 }
                 //
                 dlg.ActionContext = pv.ActionContext;
                 dlg.SetScopeMethod(imScope);
                 dlg.VariableMapTargetType      = typeof(ParameterValue);
                 dlg.MathExpression             = (IMathExpression)mew.Clone();
                 dlg.MathExpression.ScopeMethod = imScope;
                 dlg.MathExpression.EnableUndo  = true;
                 if (edSvc.ShowDialog((Form)dlg) == DialogResult.OK)
                 {
                     mew = dlg.MathExpression;
                     if (value != pv)
                     {
                         value = mew;
                         pv.SetValue(value);
                     }
                     else
                     {
                         pv.SetValue(mew);
                     }
                     if (pg != null)
                     {
                         pg.OnValueChanged(mew, EventArgs.Empty);
                     }
                 }
             }
         }
     }
     return(value);
 }