Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.ToString() should be called automatically #1

Open
deadlydog opened this issue Mar 26, 2015 · 3 comments
Open

.ToString() should be called automatically #1

deadlydog opened this issue Mar 26, 2015 · 3 comments

Comments

@deadlydog
Copy link

First off, this is a great library. Thanks!

One major (and easy to fix, I presume) nuisance is that we can't pass non-string objects into the .Expand() function.

For example, this breaks at run-time:

int age = 5;
"I am {age} years old".Expand(age);

instead we currently have to manually call .ToString():

int age = 5;
"I am {age} years old".Expand(age.ToString());

If you could change .Expand to take params Object[] args, and the just call .ToString() automatically on each parameter passed in, it would avoid us having to do it manually everywhere.

Thanks!

@anderly
Copy link
Owner

anderly commented Mar 27, 2015

Thanks for posting this. I can certainly look at making this change. In the meantime, since Expansive simply gets installed as a single .cs file in your project, you should be able to make this change on your end until I can update the NuGet package.

Thanks again.

@deadlydog
Copy link
Author

I went to go ahead and make this change, but it looks like the signature I would use is already in use:

public static string Expand(this string source, params object[] models)

And I'm not really sure what this "models" function is used for?

Basically I was just going to have public static string Expand(this string source, params object[] args) call .ToString() on each of the args and forward it off to the public static string Expand(this string source, params string[] args) function.

@anderly
Copy link
Owner

anderly commented Apr 8, 2015

See here: https://github.com/anderly/Expansive#advanced-multi-model-string-templating

So, for now, an easier approach (using your example above) might just be calling

int age = 5;
"I am {age} years old".Expand({ age: age });

I'm going to look at simplifying expansions with simple primitive types to handle your use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants