How to create right click context menu script in C#?

I found The GenericMenu script in javascript to create a custom context and dropdown menus like this:

class MyWindow extends EditorWindow {
    
    @MenuItem("TestContextMenu/Open Window")
	static function Init () {
		var window = GetWindow (MyWindow);
		window.position = Rect (50, 50, 250, 60);
		window.Show ();
	}

	function Callback (obj:Object) {
		Debug.Log ("Selected: " + obj);
	}

    function OnGUI() {
        var evt : Event = Event.current;
        var contextRect : Rect = new Rect (10, 10, 100, 100);
        
        if (evt.type == EventType.ContextClick)
        {
            var mousePos : Vector2 = evt.mousePosition;
            if (contextRect.Contains (mousePos))
            {
				// Now create the menu, add items and show it
				var menu : GenericMenu = new GenericMenu ();
            	
				menu.AddItem (new GUIContent ("MenuItem1"), false, Callback, "item 1");
				menu.AddItem (new GUIContent ("MenuItem2"), false, Callback, "item 2");
            	menu.AddSeparator ("");
				menu.AddItem (new GUIContent ("SubMenu/MenuItem3"), false, Callback, "item 3");
				
				menu.ShowAsContext ();

                evt.Use();
            }
        }
    }
}

I want to create that in C#, but I have no idea about that.
Anyone can help me to change that script in C#? :smiley:

I’m sorry, the page is not found.
[31921-not+found.jpg|31921]

could you give me another reference?

Try this out: Convert unity javascript (unityscript) to C#