示例#1
0
        /// <summary>
        /// Helper.
        /// </summary>
        void SetObjectPropertyValueByTag(object tag, object value)
        {
            if (tag is string)
            {// This is a dynamic generic property.
                SystemMonitor.CheckThrow(SelectedContainerObject != null);
                SelectedContainerObject.SetGenericDynamicPropertyValue(tag as string, value);
            }
            else if (tag is PropertyInfo)
            {// Direct property of the indicator.
                PropertyInfo info = (PropertyInfo)tag;
                if (info.CanWrite)
                {
                    info.SetValue(_selectedObject, value, null);
                }
                else
                {
                    SystemMonitor.OperationError("Property set method not found [" + info.DeclaringType.Name + ":" + info.Name + "].");
                }
            }
            else
            {
                SystemMonitor.Error("Unrecognized tag type for indicator property.");
            }

            if (SelectedContainerObject != null)
            {
                SelectedContainerObject.PropertyChanged();
            }
        }
示例#2
0
        /// <summary>
        /// Helper.
        /// </summary>
        protected Type GetPropertyTypeByTag(object tag)
        {
            if (tag is string)
            {// Is generic dynamic property.
                SystemMonitor.CheckThrow(SelectedContainerObject != null);
                return(SelectedContainerObject.GetGenericDynamicPropertyType(tag as string));
            }

            // Is normal property.
            PropertyInfo info = (PropertyInfo)tag;

            if (Nullable.GetUnderlyingType(info.PropertyType) != null)
            {// Is nullable, establish underlying.
                return(Nullable.GetUnderlyingType(info.PropertyType));
            }
            else
            {// Direct aquisition.
                return(info.PropertyType);
            }
        }
示例#3
0
        /// <summary>
        /// Main UI logic function.
        /// </summary>
        /// <returns>Y axis value of the dynamic last control.</returns>
        protected void UpdateUI()
        {
            int lastYValue = _startingYLocation; // checkBoxEnabled.Bottom + InterControlMargin;

            //lastYValue = Math.Max(checkBoxEnabled.Bottom + InterControlMargin, _startingYLocation);

            if (this.DesignMode)
            {
                return;
            }
            // Clear existing indicator custom parameters controls.
            foreach (Control control in _propertiesControls)
            {
                control.Parent = null;
                control.Tag    = null;
                control.Dispose();
            }

            _propertiesControls.Clear();

            if (SelectedObject == null)
            {
                OnUpdateUI(lastYValue);
                return;
            }

            // Gather indicator custom parameters.
            Type type = SelectedObject.GetType();

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            SortedDictionary <string, PropertyInfo> actualProperties = new SortedDictionary <string, PropertyInfo>();

            // Filter properties.
            foreach (PropertyInfo info in properties)
            {
                if (_filteringPropertiesNames.Contains(info.Name) == false &&
                    info.GetCustomAttributes(typeof(HiddenAttribute), true).Length == 0)
                {
                    if (actualProperties.ContainsKey(info.Name) == false)
                    {// Also if a parent and child define same property, with "new" only show childs.
                        actualProperties.Add(info.Name, info);
                    }
                }
            }

            // Handle default properties of the SelectedObject class.
            foreach (PropertyInfo info in actualProperties.Values)
            {
                if (info.CanRead == false)
                {// We do not process write only properties.
                    continue;
                }

                Type propertyType = info.PropertyType;
                bool isReadOnly   = info.CanWrite == false || IsReadOnly;

                object value = info.GetValue(SelectedObject, null);

                Type underlyingType = Nullable.GetUnderlyingType(propertyType);
                if (underlyingType != null)
                {// Unwrap nullable properties.
                    propertyType = underlyingType;

                    if (value == null)
                    {// Nullable enums with null values not displayed.
                        continue;
                    }
                }

                AddDynamicPropertyValueControl(info.Name, propertyType, value, info, isReadOnly, ref lastYValue);
            }

            // Handle dynamic generic properties of the indicator as well.
            if (SelectedContainerObject != null)
            {
                foreach (string name in SelectedContainerObject.GetGenericDynamicPropertiesNames())
                {
                    AddDynamicPropertyValueControl(name, SelectedContainerObject.GetGenericDynamicPropertyType(name), SelectedContainerObject.GetGenericDynamicPropertyValue(name), name, IsReadOnly, ref lastYValue);
                }
            }

            OnUpdateUI(lastYValue);
        }