Skip to content

Add DefinitionBindingMap.AsEnumerable extension#80

Open
AleksandrFomenko wants to merge 6 commits into
Nice3point:mainfrom
AleksandrFomenko:feature/parameter-extensions
Open

Add DefinitionBindingMap.AsEnumerable extension#80
AleksandrFomenko wants to merge 6 commits into
Nice3point:mainfrom
AleksandrFomenko:feature/parameter-extensions

Conversation

@AleksandrFomenko

@AleksandrFomenko AleksandrFomenko commented Jun 19, 2026

Copy link
Copy Markdown

Summary of the Pull Request

What is this about:

Adds an extension to enumerate project parameter bindings with LINQ.

Description:

DefinitionBindingMap.AsEnumerable() iterates the map and yields (Definition, ElementBinding) pairs, so callers can query bindings with standard LINQ instead of working with ForwardIterator() directly.

Readme and Changelog updated accordingly.

Quality Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

@AleksandrFomenko
AleksandrFomenko marked this pull request as draft June 19, 2026 09:15
@AleksandrFomenko

Copy link
Copy Markdown
Author

😺

@Nice3point

Copy link
Copy Markdown
Owner
  1. ParameterBindingKind enum Revit already models this distinction through InstanceBinding and TypeBinding types. Introducing a custom [Flags] enum duplicates that concept and disconnects users from the Revit type system they already know. The library's rule is wrap Revit, don't reimplement it. I'd prefer we stay closer to what Revit already provides here.
  2. Sorting result.Sort() is an opinionated choice that isn't coming from the API. Some callers want alphabetical order, others want insertion order for predictable diffs, others don't care and just pay the sort cost for nothing. The library adds ergonomics, not behavior. let the caller decide.
  3. Returning string instead of Definition Stripping down to names means any caller who actually needs the definition or binding has to iterate a second time

@Nice3point

Nice3point commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Better to add a custom enumeration and thats it.

    extension(DefinitionBindingMap map)
    {
        [Pure]
        public IEnumerable<(Definition Definition, ElementBinding Binding)> AsEnumerable()
        {
            var iterator = map.ForwardIterator();
            while (iterator.MoveNext())
            {
                if (iterator is { Key: { } definition, Current: ElementBinding binding })
                {
                    yield return (definition, binding);
                }
            }
        }
    }

Usage:

            foreach (var (definition, binding) in document.ParameterBindings.AsEnumerable())
            {
                
            }

@Nice3point
Nice3point marked this pull request as ready for review July 14, 2026 10:57
Copilot AI review requested due to automatic review settings July 14, 2026 10:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new DefinitionBindingMap extension to make iterating Revit project-parameter bindings easier (as (Definition, ElementBinding) pairs), and documents it in the README and CHANGELOG.

Changes:

  • Add DefinitionBindingMapExtensions.AsEnumerable() to iterate bindings as tuple pairs for LINQ-friendly querying.
  • Document the new enumeration pattern in README.md.
  • Add a CHANGELOG entry for the new extension.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
source/Nice3point.Revit.Extensions/DefinitionBindingMapExtensions.cs Adds AsEnumerable() for iterating DefinitionBindingMap bindings as (Definition, ElementBinding) tuples.
README.md Adds a “Project parameters” section showing how to query document.ParameterBindings.AsEnumerable() with LINQ.
CHANGELOG.md Records the new map.AsEnumerable() extension under 2027.0.3.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +2 to +13
namespace Nice3point.Revit.Extensions;

/// <summary>
/// Specifies which parameter bindings to include when querying project parameters.
/// </summary>
/// <summary>
/// Revit DefinitionBindingMap Extensions
/// </summary>
[PublicAPI]
public static class DefinitionBindingMapExtensions
{
extension(DefinitionBindingMap map)
Comment thread CHANGELOG.md Outdated
Comment thread README.md
Comment on lines +699 to +703
### Project parameters

**AsEnumerable** enumerates the project parameter bindings of the document as `(Definition, Binding)` pairs, making them easy to query with LINQ.
```csharp
var bindings = document.ParameterBindings.AsEnumerable();
AleksandrFomenko and others added 3 commits July 14, 2026 14:18
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@AleksandrFomenko
AleksandrFomenko force-pushed the feature/parameter-extensions branch from fc8806b to 891f7ad Compare July 15, 2026 16:55
@AleksandrFomenko AleksandrFomenko changed the title Add project parameter extensions for Document Add DefinitionBindingMap.AsEnumerable extension Jul 15, 2026
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 this pull request may close these issues.

3 participants