Proposed OpenXmlReader methods
See original GitHub issueIn order to make more succinct calling code, I’ve extended OpenXmlReader
in my code with these helpers. I propose that something similar can be added to the library.
public T LoadCurrentElement<T>() where T : OpenXmlElement => (T)_reader.LoadCurrentElement();
public bool ElementTypeIs<T>() where T : OpenXmlElement => ElementType == typeof(T);
public bool ElementIs<T>(out T element) where T : OpenXmlElement
{
element = null;
if (ElementTypeIs<T>())
{
element = LoadCurrentElement<T>();
return true;
}
return false;
}
ElementIs<T>
plays nice with the new out
semantics introduced in C# 7.0. Instead of this mess,
if (reader.ElementType == typeof(Paragraph))
{
Paragraph p = (Paragraph)reader.LoadCurrentElement();
// ...
}
the new methods provide a simplification
if (reader.ElementIs(out Paragraph p))
{
// ...
}
Thoughts?
Issue Analytics
- State:
- Created 6 years ago
- Comments:25 (12 by maintainers)
Top Results From Across the Web
Proposed OpenXmlReader methods · Issue #398
I propose that something similar can be added to the library. public T LoadCurrentElement<T>() where T : OpenXmlElement => (T)_reader.
Read more >OpenXmlReader Class (DocumentFormat.OpenXml)
Initializes a new instance of the OpenXmlReader class using the supplied Boolean value. Properties. Attributes. Gets the list of attributes of the current ......
Read more >c# - Using OpenXmlReader
I am trying to read (large) Excel 2007+ spreadsheets, and Google has kindly informed me that using the OpenXml SDK is a pretty...
Read more >Template Based Approach to Export Data to Excel: Part III
In this article you will learn how to work with a template based approach to export data to Excel.
Read more >Write Large Excel Files Using the Open XML SDK.mp4
Comments7 · Reading Large Excel Files using the Open XML SDK · How to create Excel files with C# code · Using the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m just a spectator here, but it’s definitely something we could use in
ClosedXML
. Here’s a snippet of our current code:Looks like it is an ideal candidate for use of the proposed new methods.
Stale issue message