Exemple #1
0
    /// <summary>
    /// Registers a single function that is exposed by a manually and automatically written method.
    /// see http://www.quantsa.org/home_expose_to_excel.html
    /// </summary>
    /// <param name="method">The generated method.</param>
    /// <param name="manualMethod">The manual method.</param>
    /// <param name="isHidden">Is this function hidden.</param>
    private void AddSingleAutoFunction(MethodInfo method, MethodInfo manualMethod, bool?isHidden)
    {
        //Create the function attribute
        QuantSAExcelFunctionAttribute quantsaAttribute = manualMethod.GetCustomAttribute <QuantSAExcelFunctionAttribute>();

        if (isHidden != null)
        {
            quantsaAttribute.IsHidden = isHidden.Value;
        }
        functionAttributes.Add(quantsaAttribute.CreateExcelFunctionAttribute());

        // Create the function argument attributes
        List <object> thisArgumentAttributes = new List <object>();

        if (manualMethod.GetParameters().Length < method.GetParameters().Length)
        {
            ExcelArgumentAttribute argAttrib = new ExcelArgumentAttribute();
            argAttrib.Name        = "objectName";
            argAttrib.Description = "The name of the object to be created.";
            //Note that the above 2 strings are the same as those added in GenerateDocs, if they are changed here they should be changed there too.
            thisArgumentAttributes.Add(argAttrib);
        }
        foreach (ParameterInfo param in manualMethod.GetParameters())
        {
            var argAttrib = param.GetCustomAttribute <ExcelArgumentAttribute>();
            if (argAttrib != null)
            {
                argAttrib.Name = param.Name;
            }
            if (ExcelUtilities.InputTypeShouldHaveHelpLink(param.ParameterType))
            {
                string typeName = param.ParameterType.IsArray ? param.ParameterType.GetElementType().Name : param.ParameterType.Name;
                argAttrib.Description += "(" + typeName + ")";
            }
            thisArgumentAttributes.Add(argAttrib);
        }
        functionArgumentAttributes.Add(thisArgumentAttributes);
    }