Exemplo n.º 1
0
        private void comboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_valueWasAssigned || comboBox.SelectedIndex < 0 || comboBox.SelectedIndex >= _properties.Count)
            {
                return;
            }

            PropertyDef selectedProperty = _properties[comboBox.SelectedIndex];

            selectedProperty       = selectedProperty.Clone();
            selectedProperty.Owner = _valueOwner;

            bool isArrayElement = selectedProperty.IsArrayElement;
            bool bForceFresh    = false;

            if (_property.Property != null)
            {
                object                 propertyMember = _property.Property.GetValue(_object, null);
                VariableDef            var            = propertyMember as VariableDef;
                DesignerRightValueEnum rvPropertyEnum = _property.Attribute as DesignerRightValueEnum;

                if (rvPropertyEnum == null)
                {
                    if (var == null)
                    {
                        var = new VariableDef(selectedProperty, VariableDef.kSelf);
                    }

                    else
                    {
                        var.SetProperty(selectedProperty, var.ValueClass);
                    }

                    if (isArrayElement && var.ArrayIndexElement == null)
                    {
                        var.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                        var.ArrayIndexElement.IsArrayIndex = true;
                        bForceFresh = true;
                    }
                    else if (!isArrayElement && var.ArrayIndexElement != null)
                    {
                        var.ArrayIndexElement = null;
                        bForceFresh           = true;
                    }

                    _property.Property.SetValue(_object, var, null);
                }
                else if (propertyMember != null)
                {
                    RightValueDef varRV = propertyMember as RightValueDef;

                    if (varRV == null)
                    {
                        Debug.Check(false);
                        //varRV = new RightValueDef(selectedProperty, VariableDef.kSelf);
                    }
                    else
                    {
                        if (varRV.IsMethod)
                        {
                            Debug.Check(false);
                        }
                        else
                        {
                            if (varRV.Var != null)
                            {
                                varRV.Var.SetProperty(selectedProperty, varRV.ValueClassReal);
                            }
                            else
                            {
                                var   = new VariableDef(selectedProperty, varRV.ValueClassReal);
                                varRV = new RightValueDef(var);
                            }
                        }
                    }

                    if (varRV != null && varRV.Var != null)
                    {
                        if (isArrayElement && varRV.Var.ArrayIndexElement == null)
                        {
                            varRV.Var.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                            varRV.Var.ArrayIndexElement.IsArrayIndex = true;

                            bForceFresh = true;
                        }
                        else if (!isArrayElement && varRV.Var.ArrayIndexElement != null)
                        {
                            varRV.Var.ArrayIndexElement = null;
                            bForceFresh = true;
                        }
                    }

                    _property.Property.SetValue(_object, varRV, null);
                }
            }
            else if (_param != null)
            {
                string valueType       = _valueOwner;
                bool   bOldArrayElment = false;

                if (_param.Value != null && _param.Value is VariableDef)
                {
                    VariableDef paramV = _param.Value as VariableDef;

                    if (paramV.ArrayIndexElement != null)
                    {
                        bOldArrayElment = true;
                    }
                }

                VariableDef paramValue = new VariableDef(selectedProperty, valueType);
                _param.Value = paramValue;

                if (isArrayElement && paramValue.ArrayIndexElement == null)
                {
                    paramValue.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                    paramValue.ArrayIndexElement.IsArrayIndex = true;

                    bForceFresh = true;
                }
                else if (!isArrayElement && bOldArrayElment)
                {
                    paramValue.ArrayIndexElement = null;
                    bForceFresh = true;
                }
            }

            this.RereshProperty(bForceFresh, _property);

            OnValueChanged(_property);
        }