Difference between revisions of "Inserting Delegate Stubs in VS2012 (CS)"
From Ribbon Commander Documentation
(→Example) |
(→Example) |
||
Line 30: | Line 30: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
* Note1: At this point we haven't yet provided the delegate stub, so intellisense marks ''myOnAction'' with red squiggles: | * Note1: At this point we haven't yet provided the delegate stub, so intellisense marks ''myOnAction'' with red squiggles: | ||
− | *: [[image: MyOnActionRedSquiggles.png|link=]] | + | *: [[image: MyOnActionRedSquiggles.png|border|link=]] |
* Note2: When clicking inside ''MyOnAction'', intellisense provides us with the option to insert the delegate stub automatically: | * Note2: When clicking inside ''MyOnAction'', intellisense provides us with the option to insert the delegate stub automatically: | ||
− | *: [[image: InsertDelegateStubCS.png|link=]] | + | *: [[image: InsertDelegateStubCS.png|border|link=]] |
The class now becomes: | The class now becomes: |
Latest revision as of 17:07, 15 March 2013
Introduction
In Visual Studio 2012, you can automatically insert delegate stubs based on their signature in C#.
Example
Consider the simple example below:
class SubscribeToDelegates
{
rxCustomUI _customUI;
public SubscribeToDelegates()
{
// Create a new customUI obj
_customUI = rxCustomUI.create("my_test_ctx");
// Create a new button
rxButton myButton = new rxButton();
// Create a new delegate of the correct signature
// NOTE1: We use class rxButtonDelegates to conveniently get the desired delegate type
// NOTE2: The delegate stub hasn't been provided at this point
var myDel = new rxButtonDelegates.onAction(MyOnAction);
// Subscribe to the button's onAction delegate
myButton.onAction = _customUI.make_delegate(myDel);
}
}
- Note1: At this point we haven't yet provided the delegate stub, so intellisense marks myOnAction with red squiggles:
- Note2: When clicking inside MyOnAction, intellisense provides us with the option to insert the delegate stub automatically:
The class now becomes:
class SubscribeToDelegates
{
rxCustomUI _customUI;
public SubscribeToDelegates()
{
// Create a new customUI obj
_customUI = rxCustomUI.create("my_test_ctx");
// Create a new button
rxButton myButton = new rxButton();
// Create a new delegate of the correct signature
// NOTE1: We use class rxButtonDelegates to conveniently get the desired delegate type
// NOTE2: The delegate stub hasn't been provided at this point
var myDel = new rxButtonDelegates.onAction(MyOnAction);
// Subscribe to the button's onAction delegate
myButton.onAction = _customUI.make_delegate(myDel);
}
private void MyOnAction(IRibbonControl control)
{
throw new NotImplementedException();
}
}