Skip to content

How to implement Optional parameters (with default values) and Nullable parameters #21

Description

@SkyChen91

how to use this function? Give an example?
•Optional parameters (with default values), 'params' parameters and Nullable parameters

Give an example?
Thanks!

Activity

  1. govert commented on Feb 13, 2019

    @govert
    Member
  2. SkyChen91 commented on Feb 14, 2019

    @SkyChen91
    Author

    I use this formula in Excel and can't return the default value ""Hello World!".
    [ExcelFunction] public static string dnaOptionalString(string optOptTest = "Hello World!") { return optOptTest; }
    dnaoptionstring

    Where is the mistake. What do I need to configure?

  3. SkyChen91 commented on Feb 14, 2019

    @SkyChen91
    Author

    Do I need to register these functions separately in a special way?

  4. SkyChen91 commented on Feb 15, 2019

    @SkyChen91
    Author

    I have a another question, how to get the Worksheet where Range is located via ExcelReference?

  5. govert commented on Feb 15, 2019

    @govert
    Member

    To use the Excel-DNA Registration extensions (which support optional parameters) you need to change your project to use 'explicit registration'. See the walkthrough here: https://github.com/Excel-DNA/Registration/blob/master/README.md

  6. SkyChen91 commented on Feb 16, 2019

    @SkyChen91
    Author

    Sorry,I have read this article, but still do not understand。
    And I also read the source code. Find The Function [ public` static IEnumerable ProcessParameterConversions(this IEnumerable registrations, ParameterConversionConfiguration conversionConfig); ]
    Should I use this extension convert the function parameter before registration.
    Like This:
    config
    I do not know How to set the ParameterConversionConfiguration.

  7. lbnewre commented on Feb 10, 2021

    @lbnewre

    Govert, thanks a lot for your work, but this part is not clear enough. Are optional arguments still a work in progress? (you're mentioning here some casting issues: https://github.com/Excel-DNA/Registration/blob/master/Source/Samples/Registration.Sample/ParameterConversionExamples.cs

    Otherwise, could you amend the documentation and give some examples?
    I.e. in the walkthrough you're showing how to update a help page by adjusting that specific argument generally for functions.
    I think what SkyChen91 is looking for (and so am I) is a neat way to set arguments/parameters for individual functions as a default to the value specified in that function.

    E.g. When setting defaults as in the example above
    [ExcelFunction] public static string dnaOptionalString(string optOptTest = "Hello World!") { return optOptTest; }
    Value of
    optOptTest stays empty "" and can't be updated to "Hello World!"?. We could check for emptyness as a workaround and update it that way below inside the function, but am I right to assume that the information "Hello World!" in this case is only overhead yet and can't be retrieved inside the function? Or how would you do that? If it's possible, a simple example would be great!

  8. govert commented on Feb 10, 2021

    @govert
    Member

    @lbnewre When I run the Registration sample, the optional string function works fine, and I get see the default value returned to Excel when calling it as =dnaOptionalString() from a sheet.

    Have you tested the Registration sample?
    Are you using the Registration extension in your add-in, according to the walkthrough here: https://github.com/Excel-DNA/Registration/blob/master/README.md
    (You need a few extra steps in your add-in like ExplicitRegistraiton=true, and dealing with the RegisterFunctions explicitly etc.)

    I think there are some quirks with the conversions in some cases, but optional strings with defaults work in the Registration sample on my computer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions