Skip to content

Commit

Permalink
Use of obsolete members now generates warning (#378)
Browse files Browse the repository at this point in the history
* Use of obsolete members now generates warning

* format

---------

Co-authored-by: Claire Kuang <[email protected]>
  • Loading branch information
JR-Morgan and clairekuang authored Nov 19, 2024
1 parent 774e24d commit 13c2941
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 9 deletions.
2 changes: 0 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ dotnet_diagnostic.ca1509.severity = warning # Invalid entry in code metrics conf
dotnet_diagnostic.ca1861.severity = none # Prefer 'static readonly' fields over constant array arguments if the called method is called repeatedly and is not mutating the passed array (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1861)

dotnet_diagnostic.cs8618.severity = suggestion # nullable problem
dotnet_diagnostic.CS0809.severity = suggestion # obsolete errors
dotnet_diagnostic.CS0618.severity = suggestion # obsolete errors


# Performance rules
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ public static class ElementIdHelper

public static ElementId? GetElementId(string elementId)
{
#if REVIT2024_OR_GREATER
if (long.TryParse(elementId, out long elementIdInt))
{
return new ElementId(elementIdInt);
}
#else
if (int.TryParse(elementId, out int elementIdInt))
{
return new ElementId(elementIdInt);
}
#endif
else
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net48</TargetFramework>
<Configurations>Debug;Release;Local</Configurations>
<RhinoVersion>8</RhinoVersion>
<DefineConstants>$(DefineConstants);RHINO8;RHINO7_OR_GREATER;RHIN08_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);RHINO8;RHINO7_OR_GREATER;RHINO8_OR_GREATER</DefineConstants>
<TargetExt>.rhp</TargetExt>
<StartProgram>$(ProgramFiles)\Rhino $(RhinoVersion)\System\Rhino.exe</StartProgram>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class RhinoLayerBaker : TraversalContextUnpacker
private readonly RhinoColorBaker _colorBaker;
private readonly Dictionary<string, int> _hostLayerCache = new();

private static readonly string s_pathSeparator =
#if RHINO8_OR_GREATER
ModelComponent.NamePathSeparator;
#else
Layer.PathSeparator;
#endif

public RhinoLayerBaker(RhinoMaterialBaker materialBaker, RhinoColorBaker colorBaker)
{
_materialBaker = materialBaker;
Expand Down Expand Up @@ -68,7 +75,7 @@ public int GetLayerIndex(Collection[] collectionPath, string baseLayerName)
.Select(o => string.IsNullOrWhiteSpace(o.name) ? "unnamed" : o.name)
.Prepend(baseLayerName);

var layerFullName = string.Join(Layer.PathSeparator, layerPath);
var layerFullName = string.Join(s_pathSeparator, layerPath);

if (_hostLayerCache.TryGetValue(layerFullName, out int existingLayerIndex))
{
Expand All @@ -91,7 +98,7 @@ private int CreateLayerFromPath(Collection[] collectionPath, string baseLayerNam
Layer? previousLayer = currentDocument.Layers.FindName(currentLayerName);
foreach (Collection collection in collectionPath)
{
currentLayerName += Layer.PathSeparator + collection.name;
currentLayerName += s_pathSeparator + collection.name;
currentLayerName = currentLayerName.Replace("{", "").Replace("}", ""); // Rhino specific cleanup for gh (see RemoveInvalidRhinoChars)
if (_hostLayerCache.TryGetValue(currentLayerName, out int value))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using Speckle.Sdk.Models.Collections;
using Layer = Rhino.DocObjects.Layer;
using SpeckleLayer = Speckle.Sdk.Models.Collections.Layer;
#if RHINO8_OR_GREATER
using Rhino.DocObjects;
#endif

namespace Speckle.Connectors.Rhino.HostApp;

Expand All @@ -12,6 +15,14 @@ public class RhinoLayerUnpacker
{
private readonly Dictionary<int, Collection> _layerCollectionCache = new();

private static readonly string s_pathSeparator =
#if RHINO8_OR_GREATER
ModelComponent.NamePathSeparator;
#else
Layer.PathSeparator;
#endif
private static readonly string[] s_pathSeparatorSplit = [s_pathSeparator];

/// <summary>
/// <para>Use this method to construct the root commit object while converting objects.</para>
/// <para>Returns the host collection corresponding to the provided layer. If it's the first time that it is being asked for, it will be created and stored in the root object collection.</para>
Expand All @@ -26,7 +37,7 @@ public Collection GetHostObjectCollection(Layer layer, Collection rootObjectColl
return value;
}

var names = layer.FullPath.Split(new[] { Layer.PathSeparator }, StringSplitOptions.None);
var names = layer.FullPath.Split(s_pathSeparatorSplit, StringSplitOptions.None);
var path = names[0];
var index = 0;
var previousCollection = rootObjectCollection;
Expand All @@ -53,7 +64,7 @@ public Collection GetHostObjectCollection(Layer layer, Collection rootObjectColl

if (index < names.Length - 1)
{
path += Layer.PathSeparator + names[index + 1];
path += s_pathSeparator + names[index + 1];
}

index++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ public List<Base> GetCorridorChildren(CDB.Corridor corridor)
List<Base> baselines = new(corridor.Baselines.Count);
foreach (CDB.Baseline baseline in corridor.Baselines)
{
#if CIVIL3D2025_OR_GREATER
string baselineGuid = baseline.BaselineGuid.ToString();
#else
string baselineGuid = baseline.baselineGUID.ToString();

#endif

Base convertedBaseline =
new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ PipeNetworkHandler pipeNetworkHandler
["innerHeight"] = pipe.InnerHeight,
["slope"] = pipe.Slope,
["shape"] = pipe.CrossSectionalShape.ToString(),
["length2d"] = pipe.Length2D,
#pragma warning disable CS0618 // Type or member is obsolete
["length2d"] = pipe.Length2D, //Length2D was un-obsoleted in 2023, but is still marked obsolete in 2022
#pragma warning restore CS0618 // Type or member is obsolete
["minimumCover"] = pipe.MinimumCover,
["maximumCover"] = pipe.MaximumCover,
["junctionLoss"] = pipe.JunctionLoss,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public static SOBR.RevitCategory GetSchemaBuilderCategoryFromBuiltIn(this DB.Bui

public static BuiltInCategory GetBuiltInCategory(this Category category)
{
#if REVIT2024_OR_GREATER
return (BuiltInCategory)category.Id.Value;
#else
return (BuiltInCategory)category.Id.IntegerValue;
#endif
}

public static string GetBuiltInFromSchemaBuilderCategory(this SOBR.RevitCategory c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public RevitCategoryInfo(

public bool ContainsRevitCategory(Category category)
{
#if REVIT2024_OR_GREATER
return BuiltInCategories.Select(x => (long)x).Contains(category.Id.Value);
#else
return BuiltInCategories.Select(x => (int)x).Contains(category.Id.IntegerValue);
#endif
}

public List<ElementType> GetElementTypes(Document document)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<Configurations>Debug;Release;Local</Configurations>
<DefineConstants>$(DefineConstants);RHINO8;RHINO7_OR_GREATER;RHIN08_OR_GREATER</DefineConstants>
<DefineConstants>$(DefineConstants);RHINO8;RHINO7_OR_GREATER;RHINO8_OR_GREATER</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 13c2941

Please sign in to comment.