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

Testing for variables #19

Open
miloush opened this issue Jul 9, 2021 · 4 comments · Fixed by #21
Open

Testing for variables #19

miloush opened this issue Jul 9, 2021 · 4 comments · Fixed by #21

Comments

@miloush
Copy link

miloush commented Jul 9, 2021

There doesn't seem to be an easy way to check if a variable exists in a given file, and unfortunately the IMatFile indexer throws an exception when a variable does not exist. It would be useful to have a more tolerant way to access variables, such as one of the following:

  • have IMatFile[string] return null if variable does not exist
  • add IMatFile.TryGetVariable(string, out IVariable) method
  • expose the underlying dictionary as IReadOnlyDictionary<string, IVariable>
@mahalex
Copy link
Owner

mahalex commented Jul 10, 2021

Thanks for creating the issue!
The current way to check if a variable exists is go through the IMatFile.Variables array and test the Name property of the elements, which is quite ugly.
I will go with the second proposed solution. Another approach would be to inherit IMatFile from IReadOnlyDictionary<string, IVariable> or IDictionary<string, IVariable>, but there are some problems associated with that: I feel like it should be a read-only dictionary, but there is already a setter on the indexer for some reason. I guess we can do it when (if) we think about the next major version with breaking changes to the API.

mahalex added a commit that referenced this issue Jul 10, 2021
mahalex added a commit that referenced this issue Jul 10, 2021
* Fix #19 
* Fix #20 
* Upgrade test dependencies
* Build and test with .NET 5
@mahalex mahalex reopened this Jul 10, 2021
@mahalex
Copy link
Owner

mahalex commented Jul 10, 2021

Version 1.4.0-beta1 published on nuget.org contains this change. Feel free to test it.

@miloush
Copy link
Author

miloush commented Jul 15, 2021

Great, working for me!

@cbergemann
Copy link

It would be very usefull to have the same interface for IStructureArray - currently you need to iterate over the FieldNames property. Exposing the TryGet method of the underlying Dictionary would help.

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

Successfully merging a pull request may close this issue.

3 participants