public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptorCollection baseProps =
                TypeDescriptor.GetProperties(value, attributes, true);

            FunctionParameters           parameters     = value as FunctionParameters;
            PropertyDescriptorCollection propCollection = null;

            PropertyDescriptor[] resultPropCollection = null;


            if (parameters != null)
            {
                propCollection = TypeDescriptor.GetProperties(parameters.GetType(), new Attribute[] { new BrowsableAttribute(true) });
                int index = 0;
                switch (parameters.SourceType)
                {
                case SourceType.Equation:
                    resultPropCollection = (PropertyDescriptor[])Array.CreateInstance(typeof(PropertyDescriptor), propCollection.Count - 2);

                    foreach (PropertyDescriptor propertyDescriptor in propCollection)
                    {
                        if (propertyDescriptor.DisplayName != "Code" && propertyDescriptor.DisplayName != "CodeLanguage")
                        {
                            resultPropCollection.SetValue(propertyDescriptor, index);
                            index++;
                        }
                    }
                    break;

                case SourceType.CodeExpression:
                    int formulaCount = 0;
                    foreach (PropertyDescriptor propertyDescriptor in propCollection)
                    {
                        if (propertyDescriptor.DisplayName.StartsWith("Formula"))
                        {
                            formulaCount++;
                        }
                    }


                    resultPropCollection = (PropertyDescriptor[])Array.CreateInstance(typeof(PropertyDescriptor), propCollection.Count - formulaCount);

                    foreach (PropertyDescriptor propertyDescriptor in propCollection)
                    {
                        if (!propertyDescriptor.DisplayName.StartsWith("Formula"))
                        {
                            resultPropCollection.SetValue(propertyDescriptor, index);
                            index++;
                        }
                    }
                    break;
                }
            }

            return(new PropertyDescriptorCollection(resultPropCollection));
        }
Пример #2
0
        private string GetFunctionFooter(FunctionParameters function, CodeLanguage codeLanguage)
        {
            Type functionType = function.GetType();;

            FunctionCodeAttribute[] attributes =
                (FunctionCodeAttribute[])functionType.GetCustomAttributes(
                    typeof(FunctionCodeAttribute), false);
            switch (codeLanguage)
            {
            case CodeLanguage.CSharp:
                return((attributes.Length > 0) ? attributes[0].SharpFooter : "");

            case CodeLanguage.VBNET:
                return((attributes.Length > 0) ? attributes[0].VBFooter : "");
            }
            return("");
        }
		private void UseExpression(FunctionParameters expression)
		{
			if (expression != null)
			{
				if (MessageBox.Show(this, "Are you sure that you want use this expression as source for component?", "Equation repository", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
                    _component.FunctionParameters = (FunctionParameters)Activator.CreateInstance(expression.GetType());
                    _component.FunctionParameters.Name = expression.Name;
                    _component.FunctionParameters.CodeLanguage = expression.CodeLanguage;
                    _component.FunctionParameters.Code = expression.Code;
                    _component.FunctionParameters.SourceType = SourceType.CodeExpression;
				}
			}
		}
		private void UseEquation(FunctionParameters equation)
		{
			if (equation != null)
			{
				if (MessageBox.Show(this, "Are you sure that you want use this equation as source for component?", "Equation repository", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
				{
                    //_component.FunctionParameters = equation;
                    _component.FunctionParameters = (FunctionParameters)Activator.CreateInstance(equation.GetType());
                    _component.FunctionParameters.Formula = equation.Formula;
                    if (_component.FunctionParameters.GetType() == typeof(Parametric2DParameters))
                        (_component.FunctionParameters as Parametric2DParameters).FormulaY = (equation as Parametric2DParameters).FormulaY;
                    if (_component.FunctionParameters.GetType() == typeof(Parametric3DParameters))
                    {
                        (_component.FunctionParameters as Parametric3DParameters).FormulaY = (equation as Parametric3DParameters).FormulaY;
                        (_component.FunctionParameters as Parametric3DParameters).FormulaZ = (equation as Parametric3DParameters).FormulaZ;
                    }
                    if (_component.FunctionParameters.GetType() == typeof(ParametricSurfaceParameters))
                    {
                        (_component.FunctionParameters as ParametricSurfaceParameters).FormulaY = (equation as ParametricSurfaceParameters).FormulaY;
                        (_component.FunctionParameters as ParametricSurfaceParameters).FormulaZ = (equation as ParametricSurfaceParameters).FormulaZ;
                    }
                    _component.FunctionParameters.Name = equation.Name;
                    _component.FunctionParameters.SourceType = SourceType.Equation;

				}
			}
		}
 private void UseExpression(FunctionParameters expression)
 {
     if (expression != null)
     {
         if (MessageBox.Show(this, "Are you sure that you want use this expression as source for component?", "Equation repository", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             _component.FunctionParameters              = (FunctionParameters)Activator.CreateInstance(expression.GetType());
             _component.FunctionParameters.Name         = expression.Name;
             _component.FunctionParameters.CodeLanguage = expression.CodeLanguage;
             _component.FunctionParameters.Code         = expression.Code;
             _component.FunctionParameters.SourceType   = SourceType.CodeExpression;
         }
     }
 }
Пример #6
0
 private void UseEquation(FunctionParameters equation)
 {
     if (equation != null)
     {
         if (MessageBox.Show(this, "Are you sure that you want use this equation as source for component?", "Equation repository", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             //_component.FunctionParameters = equation;
             _component.FunctionParameters         = (FunctionParameters)Activator.CreateInstance(equation.GetType());
             _component.FunctionParameters.Formula = equation.Formula;
             if (_component.FunctionParameters.GetType() == typeof(Parametric2DParameters))
             {
                 (_component.FunctionParameters as Parametric2DParameters).FormulaY = (equation as Parametric2DParameters).FormulaY;
             }
             if (_component.FunctionParameters.GetType() == typeof(Parametric3DParameters))
             {
                 (_component.FunctionParameters as Parametric3DParameters).FormulaY = (equation as Parametric3DParameters).FormulaY;
                 (_component.FunctionParameters as Parametric3DParameters).FormulaZ = (equation as Parametric3DParameters).FormulaZ;
             }
             if (_component.FunctionParameters.GetType() == typeof(ParametricSurfaceParameters))
             {
                 (_component.FunctionParameters as ParametricSurfaceParameters).FormulaY = (equation as ParametricSurfaceParameters).FormulaY;
                 (_component.FunctionParameters as ParametricSurfaceParameters).FormulaZ = (equation as ParametricSurfaceParameters).FormulaZ;
             }
             _component.FunctionParameters.Name       = equation.Name;
             _component.FunctionParameters.SourceType = SourceType.Equation;
         }
     }
 }