(Yes/No question) Extension methods for a sealed class

Hello folks!

Short question: can I write an extension method for a sealed class?

Long question and explanation: after watching this tutorial on Unity website, I was trying to extend EditorGUILayout class to create a simple custom box. I wrote this small piece of code that compiles without any problem:

using UnityEngine;
using UnityEditor;
using System.Collections;

public static class ExtensionMethods {
   public static void InfoButton(this EditorGUILayout obj, string description){
     Debug.Log("works");
   }
}

but when I try to use it by writing

EditorGUILayout.InfoButton("asd");

I get this erroy:

`UnityEditor.EditorGUILayout' does not contain a definition for `InfoButton'

I am not sure what really happens behind the scene when I extend a method, and I am not sure why this code doesn’t work. However, while watching this unofficial repo I saw that EditodGUILayout is a sealed class. Can these two things be related? I know I can write a local function and put the same exact code, but I am trying to learn something new :slight_smile:

Extension methods work on objects. You don’t have an EditorGUILayout object! What you’re trying to do here is to add a static extension method. That’s not possible in C#. The problem is not that the class is sealed.

Just put your methods in a static helper class of some sort.

It makes sense, I should have thought of that! Thank you so much for answering! :slight_smile: