public PrimitiveFieldView(VarView myForm, object variableToView, FieldInfo vardata, int left, int top)
     : base(myForm, variableToView, vardata, left, top)
 {
     ValueBox.KeyDown   += tb_KeyDown;
     ValueBox.LostFocus += ValueBox_LostFocus;
     IsValid             = true;
 }
Example #2
0
        public ClassView(VarView myform, object classToView, int lineNumber)
        {
            LineNumber = lineNumber;

            _myform  = myform;
            _myClass = classToView;

            //Create line number object
            Label lineNumBox = new Label();

            lineNumBox.Text      = lineNumber.ToString() + ": [" + _trimTypeName(_myClass.GetType().ToString()) + "]";
            lineNumBox.Left      = 0;
            lineNumBox.Width     = _myform.LineLabelWidth;
            lineNumBox.TextAlign = ContentAlignment.MiddleCenter;
            lineNumBox.Top       = _myform.CurrentTextBoxY + 5;
            lineNumBox.BackColor = Color.White;
            _myform.Controls.Add(lineNumBox);

            FieldInfo[] fields = null;
            try
            {
                fields = classToView.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                fields = fields.Concat(classToView.GetType().BaseType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)).ToArray();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to create ClassView.");
                Console.WriteLine(e.Message);
                MessageBox.Show(e.Message, "Error");
                return;
            }

            foreach (var f in fields)
            {
                _myform.BackColor = Color.Black;
                //Create a new textbox for the name and value
                if (f.FieldType.IsPrimitive || f.FieldType == typeof(string))
                {
                    _createPrimitiveFieldView(f, _myClass);
                }
                else
                {
                    _createClassFieldView(f, _myClass);
                }
            }

            IsValid = true;
        }
Example #3
0
        public FieldView(VarView myForm, object variableToView, FieldInfo vardata, int left, int top)
        {
            _form = myForm;

            string valueText = "";

            try
            {
                valueText = vardata.GetValue(variableToView).ToString();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error");
                IsValid = false;
            }


            VariableData = vardata;
            Variable     = variableToView;
            BaseColor    = Color.White;

            NameBox             = new Label();
            NameBox.Left        = left;
            NameBox.Top         = top;
            NameBox.Text        = _trimFieldName(vardata.Name);
            NameBox.TextAlign   = System.Drawing.ContentAlignment.MiddleCenter;
            NameBox.BackColor   = BaseColor;
            NameBox.Width       = 100;
            NameBox.MouseClick += RightClickHandler;

            ValueBox             = new TextBox();
            ValueBox.Left        = left;
            ValueBox.Top         = top + 20;
            ValueBox.Text        = valueText;
            ValueBox.TextAlign   = HorizontalAlignment.Center;
            ValueBox.MouseClick += RightClickHandler;
        }
Example #4
0
 public ClassFieldView(VarView myForm, object variableToView, FieldInfo vardata, int left, int top) : base(myForm, variableToView, vardata, left, top)
 {
     _init();
     ValueBox.MouseClick += ValueBox_Click;
     IsValid              = true;
 }
Example #5
0
        bool _wasEmpty;//TODO: Use this to repopulate the list when it becomes non empty

        public ListView(VarView myform, dynamic classToView, int lineNumber)
        {
            _myform    = myform;
            _myClass   = classToView;
            LineNumber = lineNumber;



            int count = 0;

            foreach (object obj in classToView)
            {
                object varToView = obj;


                //Create line number object
                Label lineNumBox = new Label();
                lineNumBox.Text      = "Class " + lineNumber.ToString();
                lineNumBox.Left      = 0;
                lineNumBox.Width     = _myform.LineLabelWidth;
                lineNumBox.TextAlign = ContentAlignment.MiddleCenter;
                lineNumBox.Top       = _myform.CurrentTextBoxY + 5;
                lineNumBox.BackColor = Color.White;
                _myform.Controls.Add(lineNumBox);


                //Dirty way to handle a key value pair
                Type valueType = obj.GetType();
                if (valueType.IsGenericType)
                {
                    Type baseType = valueType.GetGenericTypeDefinition();
                    if (baseType == typeof(KeyValuePair <,>))
                    {
                        varToView = obj.GetType().GetProperty("Value", BindingFlags.Instance | BindingFlags.Public).GetValue(obj);
                        FieldInfo f   = obj.GetType().GetField("value", BindingFlags.Instance | BindingFlags.NonPublic);
                        var       key = obj.GetType().GetProperty("Key", BindingFlags.Instance | BindingFlags.Public).GetValue(obj);

                        var cfv = _createClassFieldView(f, obj);
                        cfv.NameBox.Text = varToView.GetType().ToString() + ": " + key.ToString();

                        IsValid = true;
                        continue;
                    }
                }

                FieldInfo[] fields = null;
                try
                {
                    fields = varToView.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                    fields = fields.Concat(varToView.GetType().BaseType.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy)).ToArray();
                }
                catch (Exception e)
                {
                    Console.WriteLine("Failed to create ClassView.");
                    Console.WriteLine(e.Message);
                    return;
                }

                foreach (var f in fields)
                {
                    _myform.BackColor = Color.Black;
                    //Create a new textbox for the name and value
                    if (f.FieldType.IsPrimitive || f.FieldType == typeof(string))
                    {
                        _createPrimitiveFieldView(f, varToView);
                    }
                    else
                    {
                        _createClassFieldView(f, varToView);
                    }
                }

                IsValid = true;

                count++;
                if (count == 10)
                {
                    return;
                }
            }


            if (count == 0)                       //If the list is empty
            {
                HackString tx = new HackString(); //lolhacks
                tx.Text = "Empty Collection.";
                FieldInfo field = tx.GetType().GetField("Text");

                _createPrimitiveFieldView(field, tx);
                IsValid = true;
            }
        }