xamarin-macios/tests/generator/bug43579.cs

49 строки
1.5 KiB
C#
Исходник Обычный вид История

[generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates (#817) * [generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates https://bugzilla.xamarin.com/show_bug.cgi?id=43579 Bug Description: Generator will emit invalid code when using the same name (overload) in a method inside a @delegate (protocol) that is decorated either with EventArgs or DelegateName ----------------------------------------------------------------- This commit introduces a new attribute named DelegateApiNameAttribute which mimics the EventNameAttribute but for delegate properties in host classes It is used to specify the delegate property name that will be created when the generator creates the delegate property on the host class that holds events and delegates. This is really useful when you have two overload methods that makes sense to keep them named as is but you want to expose them in the host class with a better given name. example: interface SomeDelegate { [Export ("foo"), DelegateApiName ("Confirmation"), DelegateName ("Func<bool>"), DefaultValue (false)] bool Confirm (Some source); } Generates propety in the host class: Func<bool> Confirmation { get; set; } This also introduces two new BIXXXX errors: - BI1043 Repeated overload {mi.Name} and no [DelegateApiNameAttribute] provided to generate property name on host class. - BI1044 Repeated name '{apiName.Name}' provided in [DelegateApiNameAttribute]. Which provides an error instead of generating invalid C# code. Generator test included :D * [docs] Added DelegateApiNameAttribute and IgnoredInDelegateAttribute docs Also added Protocol where Model was used in our docs so we do not misslead customers about it
2016-09-14 15:20:08 +03:00
using System;
[tests][generator] Port XI/Classic tests to XI/Unified. (#1745) * [tests][generator] Port XI/Classic tests to XI/Unified. * [tests][generator] Comment out code triggering previously unknown bugs. These tests makes the generator fail: error BI0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com System.NullReferenceException: Object reference not set to an instance of an object at Generator.GetSetterExportAttribute (System.Reflection.PropertyInfo pinfo) [0x0002e] in /work/maccore/master/xamarin-macios/src/generator.cs:1981 at Generator.Go () [0x007e3] in /work/maccore/master/xamarin-macios/src/generator.cs:2162 at BindingTouch.Main2 (System.String[] args) [0x010b2] in /work/maccore/master/xamarin-macios/src/btouch.cs:435 at BindingTouch.Main (System.String[] args) [0x0001d] in /work/maccore/master/xamarin-macios/src/btouch.cs:77 at System.Environment.get_StackTrace () [0x00000] in /work/maccore/master/xamarin-macios/_ios-build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/corlib/System/Environment.cs:321 at ErrorHelper.ShowInternal (System.Exception e) [0x000dc] in /work/maccore/master/xamarin-macios/src/error.cs:200 at ErrorHelper.Show (System.Exception e) [0x00027] in /work/maccore/master/xamarin-macios/src/error.cs:151 at BindingTouch.Main (System.String[] args) [0x0002b] in /work/maccore/master/xamarin-macios/src/btouch.cs:79 This has been filed as https://bugzilla.xamarin.com/show_bug.cgi?id=52664. * [tests][generator] Comment out code triggering previously unknown bugs. This has been filed as https://bugzilla.xamarin.com/show_bug.cgi?id=52665.
2017-02-22 18:47:11 +03:00
using Foundation;
using ObjCRuntime;
[generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates (#817) * [generator] Fix bug 43579 - Generator emits invalid code when using the same method name (overload) in @delegates using events and C# delegates https://bugzilla.xamarin.com/show_bug.cgi?id=43579 Bug Description: Generator will emit invalid code when using the same name (overload) in a method inside a @delegate (protocol) that is decorated either with EventArgs or DelegateName ----------------------------------------------------------------- This commit introduces a new attribute named DelegateApiNameAttribute which mimics the EventNameAttribute but for delegate properties in host classes It is used to specify the delegate property name that will be created when the generator creates the delegate property on the host class that holds events and delegates. This is really useful when you have two overload methods that makes sense to keep them named as is but you want to expose them in the host class with a better given name. example: interface SomeDelegate { [Export ("foo"), DelegateApiName ("Confirmation"), DelegateName ("Func<bool>"), DefaultValue (false)] bool Confirm (Some source); } Generates propety in the host class: Func<bool> Confirmation { get; set; } This also introduces two new BIXXXX errors: - BI1043 Repeated overload {mi.Name} and no [DelegateApiNameAttribute] provided to generate property name on host class. - BI1044 Repeated name '{apiName.Name}' provided in [DelegateApiNameAttribute]. Which provides an error instead of generating invalid C# code. Generator test included :D * [docs] Added DelegateApiNameAttribute and IgnoredInDelegateAttribute docs Also added Protocol where Model was used in our docs so we do not misslead customers about it
2016-09-14 15:20:08 +03:00
namespace bug43579 {
interface IFooDelegate { }
[BaseType (typeof (NSObject))]
[Model]
[Protocol]
interface FooDelegate {
// Events
[Export ("FooDidEndEditing:"), EventArgs ("FooDelegateEnded"), EventName ("Ended")]
void EditingEnded (Foo foo);
[Export ("FooDidEndEditing:after:"), EventArgs ("FooDelegateEndedTime"), EventName ("EndedAfter")]
void EditingEnded (Foo foo, double time);
[Export ("FooDidEndEditing:after:index:"), IgnoredInDelegate]
void EditingEnded (Foo foo, double time, int index);
// Using Func
[Export ("foo:dobar:"), DelegateName ("Func<Foo,int,bool>"), DefaultValue ("true")]
bool DoBar (Foo foo, int bar);
[Export ("foo:doBar:after:"), DelegateApiName ("DoBarAfter"), DelegateName ("Func<Foo,int,double,bool>"), DefaultValue ("true")]
bool DoBar (Foo foo, int bar, double time);
// Using an actual DelegateName
[Export ("foo:doAnotherBar:"), DelegateName ("FooDelegateAnotherBar"), DefaultValue ("true")]
bool DoAnotherBar (Foo foo, int bar);
[Export ("foo:doAnotherBar:after:"), DelegateApiName ("DoAnotherBarAfter"), DelegateName ("FooDelegateAnotherBarTime"), DefaultValue ("true")]
bool DoAnotherBar (Foo foo, int bar, double time);
}
[BaseType (typeof (NSObject), Delegates = new string [] { "Delegate" }, Events = new Type [] { typeof (FooDelegate) })]
interface Foo {
[Export ("delegate", ArgumentSemantic.Assign), NullAllowed]
IFooDelegate Delegate { get; set; }
}
}