Skip to content

Commit 60011c4

Browse files
committed
[.NET] Migrate to a new C# 14 extensions format.
1 parent 61b8a92 commit 60011c4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+5456
-5675
lines changed

Readme.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
[![Downloads](https://img.shields.io/nuget/dt/Nice3point.Revit.Extensions?style=for-the-badge)](https://www.nuget.org/packages/Nice3point.Revit.Extensions)
1212
[![Last Commit](https://img.shields.io/github/last-commit/Nice3point/RevitExtensions/develop?style=for-the-badge)](https://github.com/Nice3point/RevitExtensions/commits/develop)
1313

14-
Extensions make working with the Revit API much easier and more intuitive. They add helpful methods that make your code cleaner, easier to understand, and simpler to maintain. Generics, nullable, everything here.
14+
Extensions make working with the Revit API much easier and more intuitive.
15+
They add helpful methods that make your code cleaner, easier to understand, and simpler to maintain. Generics, nullable, everything here.
1516

1617
Instead of writing complex utility functions, you can use these extensions to write code in a natural, fluent way that focuses on what you actually want to do:
1718

@@ -40,37 +41,38 @@ Package included by default in [Revit Templates](https://github.com/Nice3point/R
4041
## Table of contents
4142

4243
<!-- TOC -->
43-
* [Element extensions](#element-extensions)
44+
45+
* [Element extensions](#element-extensions)
4446
* [Element transform extensions](#element-transform-extensions)
4547
* [Element association extensions](#element-association-extensions)
4648
* [Element validation extensions](#element-validation-extensions)
4749
* [Element worksharing extensions](#element-worksharing-extensions)
4850
* [Element schema extensions](#element-schema-extensions)
49-
* [ElementId extensions](#elementid-extensions)
51+
* [ElementId extensions](#elementid-extensions)
5052
* [ElementId transform extensions](#elementid-transform-extensions)
51-
* [Application extensions](#application-extensions)
53+
* [Application extensions](#application-extensions)
5254
* [Ribbon Extensions](#ribbon-extensions)
5355
* [ContextMenu Extensions](#contextmenu-extensions)
54-
* [Document extensions](#document-extensions)
56+
* [Document extensions](#document-extensions)
5557
* [Document managers extensions](#document-managers-extensions)
56-
* [Geometry extensions](#geometry-extensions)
58+
* [Geometry extensions](#geometry-extensions)
5759
* [Element geometry extensions](#element-geometry-extensions)
58-
* [Parameters extensions](#parameters-extensions)
60+
* [Parameters extensions](#parameters-extensions)
5961
* [Document global parameters extensions](#document-global-parameters-extensions)
60-
* [FilteredElementCollector extensions](#filteredelementcollector-extensions)
61-
* [ForgeTypeId extensions](#forgetypeid-extensions)
62-
* [Unit Extensions](#unit-extensions)
63-
* [Label Extensions](#label-extensions)
64-
* [Color extensions](#color-extensions)
65-
* [Family extensions](#family-extensions)
66-
* [HostObject extensions](#hostobject-extensions)
67-
* [Plumbing extensions](#plumbing-extensions)
68-
* [Solid extensions](#solid-extensions)
62+
* [FilteredElementCollector extensions](#filteredelementcollector-extensions)
63+
* [ForgeTypeId extensions](#forgetypeid-extensions)
64+
* [Unit Extensions](#unit-extensions)
65+
* [Label Extensions](#label-extensions)
66+
* [Color extensions](#color-extensions)
67+
* [Family extensions](#family-extensions)
68+
* [HostObject extensions](#hostobject-extensions)
69+
* [Plumbing extensions](#plumbing-extensions)
70+
* [Solid extensions](#solid-extensions)
6971
* [Element solid cut extensions](#element-solid-cut-extensions)
70-
* [View extensions](#view-extensions)
72+
* [View extensions](#view-extensions)
7173
* [View managers extensions](#view-managers-extensions)
72-
* [Imperial Extensions](#imperial-extensions)
73-
* [System Extensions](#system-extensions)
74+
* [Imperial Extensions](#imperial-extensions)
75+
* [System Extensions](#system-extensions)
7476

7577
## Element extensions
7678

@@ -119,7 +121,7 @@ var canMirror = element.CanBeMirrored();
119121
```
120122

121123
### Element association extensions
122-
124+
123125
**IsAnalyticalElement** extension returns true if the element is an analytical element.
124126

125127
```csharp
@@ -133,15 +135,15 @@ var isPhysical = element.IsPhysicalElement();
133135
```
134136

135137
### Element validation extensions
136-
138+
137139
**CanDeleteElement** extension indicates whether an element can be deleted.
138140

139141
```csharp
140142
var canDelete = element.CanDeleteElement();
141143
```
142144

143145
### Element worksharing extensions
144-
146+
145147
**GetCheckoutStatus** extension gets the ownership status of an element.
146148

147149
```csharp
@@ -257,6 +259,7 @@ var copy = elementIds.CopyElements(document, new XYZ(1, 1, 1));
257259
```
258260

259261
## Application extensions
262+
260263
### Ribbon Extensions
261264

262265
[Revit API Ribbon controls Guidelines](https://help.autodesk.com/view/RVT/2025/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Introduction_Add_In_Integration_Ribbon_Panels_and_Controls_html)
@@ -335,7 +338,7 @@ button.SetLargeImage("C:/Pictures/RibbonIcon32.png");
335338

336339
Starting with Revit 2024 **SetImage** and **SetLargeImage** extensions support Light and Dark UI themes.
337340

338-
When the provided image name contains "light" or "dark" (case-insensitive), the extensions automatically modify the URI to match the current UI theme.
341+
When the provided image name contains "light" or "dark" (case-insensitive), the extensions automatically modify the URI to match the current UI theme.
339342
For example:
340343

341344
```csharp
@@ -548,7 +551,7 @@ var contains = boundingBox.Contains(point);
548551
```
549552

550553
**Contains** extension determines whether the specified point is contained within this BoundingBox.
551-
Set strict mode if the point needs to be fully on the inside of the source.
554+
Set strict mode if the point needs to be fully on the inside of the source.
552555
A point coinciding with the box border will be considered outside.
553556

554557
```csharp
@@ -752,7 +755,6 @@ var isValid = document.IsValidGlobalParameter(parameterId);
752755
var isAllowed = document.AreGlobalParametersAllowed();
753756
```
754757

755-
756758
## FilteredElementCollector extensions
757759

758760
This set of extensions encapsulates all the work of searching for elements in the Revit database.
@@ -1328,7 +1330,8 @@ var manager = view.GetSpatialFieldManager();
13281330

13291331
## Imperial Extensions
13301332

1331-
**ToFraction** extension converts a double value representing a measurement in feet to its string representation in the Imperial system, expressed as feet, inches, and fractional inches.
1333+
**ToFraction** extension converts a double value representing a measurement in feet to its string representation in the Imperial system, expressed as feet, inches, and fractional
1334+
inches.
13321335

13331336
```csharp
13341337
var imperial = 0.0123.ToFraction(); // 1/8"

build/Build.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<OutputType>Exe</OutputType>
66
<LangVersion>latest</LangVersion>
77
<ImplicitUsings>true</ImplicitUsings>
8-
<TargetFramework>net9.0</TargetFramework>
8+
<TargetFramework>net10.0</TargetFramework>
99
</PropertyGroup>
1010

1111
<ItemGroup>

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "9.0.0",
3+
"version": "10.0.0",
44
"rollForward": "latestMinor",
55
"allowPrerelease": true
66
}

source/Nice3point.Revit.Extensions/BoundingBoxXyzExtensions.cs

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,71 @@
66
[PublicAPI]
77
public static class BoundingBoxXyzExtensions
88
{
9-
/// <summary>
10-
/// Computes the geometric center point of the bounding box.
11-
/// </summary>
129
/// <param name="boundingBox">The bounding box from which the centroid is calculated.</param>
13-
/// <returns>A point representing the centroid of the bounding box.</returns>
14-
/// <remarks>BoundingBoxXYZ <see cref="Autodesk.Revit.DB.Transform"/> is not applied</remarks>
15-
[Pure]
16-
public static XYZ ComputeCentroid(this BoundingBoxXYZ boundingBox)
10+
extension(BoundingBoxXYZ boundingBox)
1711
{
18-
return (boundingBox.Min + boundingBox.Max) / 2;
19-
}
12+
/// <summary>
13+
/// Computes the geometric center point of the bounding box.
14+
/// </summary>
15+
/// <returns>A point representing the centroid of the bounding box.</returns>
16+
/// <remarks>BoundingBoxXYZ <see cref="Autodesk.Revit.DB.Transform"/> is not applied</remarks>
17+
[Pure]
18+
public XYZ ComputeCentroid()
19+
{
20+
return (boundingBox.Min + boundingBox.Max) / 2;
21+
}
2022

21-
/// <summary>
22-
/// Retrieves the coordinates of the eight vertices that define the bounding box.
23-
/// </summary>
24-
/// <param name="boundingBox">The bounding box from which the vertices are computed.</param>
25-
/// <returns>An array of points representing the vertices of the bounding box.</returns>
26-
/// <remarks>BoundingBoxXYZ <see cref="Autodesk.Revit.DB.Transform"/> is not applied</remarks>
27-
[Pure]
28-
public static XYZ[] ComputeVertices(this BoundingBoxXYZ boundingBox)
29-
{
30-
return
31-
[
32-
new XYZ(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Min.Z),
33-
new XYZ(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Max.Z),
34-
new XYZ(boundingBox.Min.X, boundingBox.Max.Y, boundingBox.Min.Z),
35-
new XYZ(boundingBox.Min.X, boundingBox.Max.Y, boundingBox.Max.Z),
36-
new XYZ(boundingBox.Max.X, boundingBox.Min.Y, boundingBox.Min.Z),
37-
new XYZ(boundingBox.Max.X, boundingBox.Min.Y, boundingBox.Max.Z),
38-
new XYZ(boundingBox.Max.X, boundingBox.Max.Y, boundingBox.Min.Z),
39-
new XYZ(boundingBox.Max.X, boundingBox.Max.Y, boundingBox.Max.Z)
40-
];
41-
}
23+
/// <summary>
24+
/// Retrieves the coordinates of the eight vertices that define the bounding box.
25+
/// </summary>
26+
/// <returns>An array of points representing the vertices of the bounding box.</returns>
27+
/// <remarks>BoundingBoxXYZ <see cref="Autodesk.Revit.DB.Transform"/> is not applied</remarks>
28+
[Pure]
29+
public XYZ[] ComputeVertices()
30+
{
31+
return
32+
[
33+
new XYZ(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Min.Z),
34+
new XYZ(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Max.Z),
35+
new XYZ(boundingBox.Min.X, boundingBox.Max.Y, boundingBox.Min.Z),
36+
new XYZ(boundingBox.Min.X, boundingBox.Max.Y, boundingBox.Max.Z),
37+
new XYZ(boundingBox.Max.X, boundingBox.Min.Y, boundingBox.Min.Z),
38+
new XYZ(boundingBox.Max.X, boundingBox.Min.Y, boundingBox.Max.Z),
39+
new XYZ(boundingBox.Max.X, boundingBox.Max.Y, boundingBox.Min.Z),
40+
new XYZ(boundingBox.Max.X, boundingBox.Max.Y, boundingBox.Max.Z)
41+
];
42+
}
4243

43-
/// <summary>
44-
/// Calculates the volume enclosed by the bounding box.
45-
/// </summary>
46-
/// <param name="boundingBox">The bounding box for which the volume is calculated.</param>
47-
/// <returns>The volume of the bounding box.</returns>
48-
[Pure]
49-
public static double ComputeVolume(this BoundingBoxXYZ boundingBox)
50-
{
51-
var length = boundingBox.Max.X - boundingBox.Min.X;
52-
var width = boundingBox.Max.Y - boundingBox.Min.Y;
53-
var height = boundingBox.Max.Z - boundingBox.Min.Z;
44+
/// <summary>
45+
/// Calculates the volume enclosed by the bounding box.
46+
/// </summary>
47+
/// <returns>The volume of the bounding box.</returns>
48+
[Pure]
49+
public double ComputeVolume()
50+
{
51+
var length = boundingBox.Max.X - boundingBox.Min.X;
52+
var width = boundingBox.Max.Y - boundingBox.Min.Y;
53+
var height = boundingBox.Max.Z - boundingBox.Min.Z;
5454

55-
return length * width * height;
56-
}
55+
return length * width * height;
56+
}
5757

58-
/// <summary>
59-
/// Calculates the total surface area of the bounding box.
60-
/// </summary>
61-
/// <param name="boundingBox">The bounding box for which the surface area is calculated.</param>
62-
/// <returns>The total surface area of the bounding box.</returns>
63-
[Pure]
64-
public static double ComputeSurfaceArea(this BoundingBoxXYZ boundingBox)
65-
{
66-
var length = boundingBox.Max.X - boundingBox.Min.X;
67-
var width = boundingBox.Max.Y - boundingBox.Min.Y;
68-
var height = boundingBox.Max.Z - boundingBox.Min.Z;
58+
/// <summary>
59+
/// Calculates the total surface area of the bounding box.
60+
/// </summary>
61+
/// <returns>The total surface area of the bounding box.</returns>
62+
[Pure]
63+
public double ComputeSurfaceArea()
64+
{
65+
var length = boundingBox.Max.X - boundingBox.Min.X;
66+
var width = boundingBox.Max.Y - boundingBox.Min.Y;
67+
var height = boundingBox.Max.Z - boundingBox.Min.Z;
6968

70-
var area1 = length * width;
71-
var area2 = length * height;
72-
var area3 = width * height;
69+
var area1 = length * width;
70+
var area2 = length * height;
71+
var area3 = width * height;
7372

74-
return 2 * (area1 + area2 + area3);
73+
return 2 * (area1 + area2 + area3);
74+
}
7575
}
7676
}

0 commit comments

Comments
 (0)