cancel
Showing results for 
Search instead for 
Did you mean: 
Patrick_Ramser
Star Contributor
Star Contributor

OnBase 16 contains a new feature to help you write correct and well-performing Unity Scripts: Code Analysis. This feature, available through OnBase Studio, uses OnBase's custom rules we’ve written through Microsoft's code analysis engine to examine your Unity scripts and libraries for common mistakes.

What exactly is this?

Code analysis, specifically for managed code, is a feature that allows the definition and use of various rules that can be used to check code for various consistencies, or inconsistencies. Most newer versions of msbuild and Visual Studio ship natively with code analysis tools already built in, only needing a quick toggle or selection of rules to run before build operations.

More information can be found through an MSDN article; Microsoft has a pretty great breakdown of the feature and how it works.

When does it run?

After upgrading to OnBase 16, Code Analysis is run on every Unity script and library when you build it in OnBase Studio. In Studio, you can also run a report to analyze some or all of your existing scripts in bulk. These features are not available in Unity API Project Configuration available through the Configuration module.

Can I turn it off?

Yes, you can (although Code Analysis only generates warnings, not errors, and will not prevent your scripts from building). In the Studio Options dialog, under Script Editors, deselect the "Run code analysis on build" option. You can also suppress individual warnings for a method by tagging the method with the [SuppressRule] attribute.

What kinds of errors will it find?

At the release of OnBase 16, Code Analysis will attempt to find the following patterns that we have determined are likely to cause unwanted results:

  • Documents modified without being locked
  • Scan batches used for import without being locked
  • Locks not being released
  • Creating an Editable object but never passing it into a modifier
  • The use of dynamically generated assemblies
  • Passing an Exception's Message into Diagnostics.Write() (rather than simply passing the Exception itself, which preserves the stack trace)

Can it find other errors?

The Code Analysis feature is new, but it's expandable. We hope to have more rules to find other problems in future versions of OnBase. If you have suggestions for other rules we could add, please let us know! Like all of our enhancements, we love to pull from what customers actually want and what they're actually doing in their current solutions.

In Conclusion

Our Unity API scripting platform [and editor] have continually improved from release to release ever since we unleashed it in version 8. Our hope is that features like code analysis continue to strengthen our customers ability to build great solutions with it, propelling us forward into a future of OnBase that allows your code to be even better than ever. For any questions, comments, or even feedback, hit us up in the comments or our forums. Like we mentioned earlier as well, any suggestions to build upon our analysis rules that you would find useful would be greatly appreciated. Check back on our blog next week to learn about something else in our framework that we recently added: support for LINQ statements in Unity scripts.