JetBrains / JetBrains/resharper-unity
Ignore "Expensive method invocation" if the code is wrapped inside `UNITY_EDITOR` preprocessor directive
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 142
- PR merge metrics
- No merged PRs in 30d
Description
If an expensive method is wrapped inside `UNITY_EDITOR`, `UNITY_EDITOR_WIN`, `UNITY_EDITOR_OSX` or `UNITY_EDITOR_LINUX`, an _Expansive Method Invocation_ warning shouldn't be shown or at least state that it is for editor only.
Here is a reference to the Unity specific preprocessor statements: [Link](https://docs.unity3d.com/Manual/PlatformDependentCompilation.html)
Example:
The following method should not be marked as _Expansive Method Invocation_, as it won't make a difference when the project is built.
```csharp
private static void Method()
{
#if UNITY_EDITOR
Debug.Log("Test Log.");
#endif
var x = 5;
}
```
However, the following code should be marked as _Expansive Method Invocation_, as `GetComponent` method is expansive.
```csharp
private static void Method()
{
#if UNITY_EDITOR
Debug.Log("Test Log.");
#endif
var x = GetComponent();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.