[generator] Have WrapAttribute generate virtual members (#1707)
* [generator] Have WrapAttribute generate virtual members WrapAttribute now has a boolean optional parameter named isVirtual, this instructs the generator to add the virtual keyword to generated members. This is useful when fixing breaking changes so we can keep the wrong signature generated instead of having manual code files. * [docs] Add docs about virtual to WrapAttribute
This commit is contained in:
Родитель
61c72afd78
Коммит
a021c0cd3c
|
@ -1894,6 +1894,19 @@ interface XyzPanel {
|
|||
}
|
||||
```
|
||||
|
||||
The members generated by `[Wrap]` are not `virtual` by default, if you need a `virtual` member you can set to `true` the optional `isVirtual` parameter.
|
||||
|
||||
```
|
||||
[BaseType (typeof (NSObject))]
|
||||
interface FooExplorer {
|
||||
[Export ("fooWithContentsOfURL:")]
|
||||
void FromUrl (NSUrl url);
|
||||
|
||||
[Wrap ("FromUrl (NSUrl.FromString (url))", isVirtual: true)]
|
||||
void FromUrl (string url);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
# Parameter Attributes
|
||||
|
||||
|
|
|
@ -210,11 +210,14 @@ public class BindAttribute : Attribute {
|
|||
}
|
||||
|
||||
public class WrapAttribute : Attribute {
|
||||
public WrapAttribute (string methodname)
|
||||
public WrapAttribute (string methodname, bool isVirtual = false)
|
||||
{
|
||||
MethodName = methodname;
|
||||
IsVirtual = isVirtual;
|
||||
}
|
||||
|
||||
public string MethodName { get; set; }
|
||||
public bool IsVirtual { get; set; }
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -510,7 +510,9 @@ public class MemberInformation
|
|||
if (attr.Length != 1)
|
||||
throw new BindingException (1012, true, "No Export or Bind attribute defined on {0}.{1}", type, mi.Name);
|
||||
|
||||
wrap_method = ((WrapAttribute) attr [0]).MethodName;
|
||||
var wrapAtt = (WrapAttribute) attr [0];
|
||||
wrap_method = wrapAtt.MethodName;
|
||||
is_virtual_method = wrapAtt.IsVirtual;
|
||||
} else {
|
||||
BindAttribute ba = (BindAttribute) attr [0];
|
||||
this.selector = ba.Selector;
|
||||
|
@ -546,7 +548,11 @@ public class MemberInformation
|
|||
if (export != null)
|
||||
selector = export.Selector;
|
||||
|
||||
if (wrap_method != null || is_interface_impl || is_type_sealed)
|
||||
if (wrap_method != null) {
|
||||
var wrapAtt = AttributeManager.GetCustomAttribute <WrapAttribute> (pi, true);
|
||||
is_virtual_method = wrapAtt?.IsVirtual ?? false;
|
||||
}
|
||||
else if (is_interface_impl || is_type_sealed)
|
||||
is_virtual_method = false;
|
||||
else
|
||||
is_virtual_method = !is_static;
|
||||
|
|
|
@ -52,5 +52,9 @@
|
|||
<Link>Options.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="generator-attributes.cs" />
|
||||
<Compile Include="generator-attribute-manager.cs" />
|
||||
<Compile Include="generator-enums.cs" />
|
||||
<Compile Include="generator-filters.cs" />
|
||||
<Compile Include="generator-typemanager.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -13,7 +13,7 @@ include $(TOP)/Make.config
|
|||
|
||||
IOS_CURRENT_DIR=$(IOS_DESTDIR)/Library/Frameworks/Xamarin.iOS.framework/Versions/Current
|
||||
IOS_GENERATOR = $(IOS_CURRENT_DIR)/bin/btouch /baselib:$(IOS_CURRENT_DIR)/lib/mono/2.1/monotouch.dll /unsafe /compiler:$(IOS_CURRENT_DIR)/bin/smcs
|
||||
IOS_TESTS = bug15283 bug15307 bug15799 bug16036 sof20696157 bug23041 bug27430 bug27428 bug34042 btouch-with-hyphen-in-name property-redefination-ios arrayfromhandlebug bug36457 bug39614 bug40282 bug17232 bug24078-ignore-methods-events strong-dict-support-templated-dicts bug43579 bindastests
|
||||
IOS_TESTS = bug15283 bug15307 bug15799 bug16036 sof20696157 bug23041 bug27430 bug27428 bug34042 btouch-with-hyphen-in-name property-redefination-ios arrayfromhandlebug bug36457 bug39614 bug40282 bug17232 bug24078-ignore-methods-events strong-dict-support-templated-dicts bug43579 bindastests virtualwrap
|
||||
IOS_CUSTOM_TESTS = forum54078 desk63279 desk79124 multiple-api-definitions1 multiple-api-definitions2 bug29493 classNameCollision bi1036 bug37527 bug27986 bug35176 bi1046 bindas1048error bindas1049error bindas1050modelerror bindas1050protocolerror
|
||||
|
||||
MAC_CURRENT_DIR=$(MAC_DESTDIR)/Library/Frameworks/Xamarin.Mac.framework/Versions/Current
|
||||
|
@ -159,6 +159,17 @@ bi1036:
|
|||
bi1046:
|
||||
$(if $(V),,@echo "$@";) $(IOS_GENERATOR) $@.cs --process-enums | grep BI1046 >/dev/null 2>&1
|
||||
|
||||
virtualwrap:
|
||||
@rm -Rf $@.tmpdir
|
||||
@mkdir -p $@.tmpdir
|
||||
$(if $(V),,@echo "$@";) $(IOS_GENERATOR) --sourceonly:$@.source -tmpdir=$@.tmpdir $@.cs --process-enums
|
||||
@if ! grep -r "public virtual" virtualwrap.tmpdir/WrapTest > /dev/null; then \
|
||||
echo "error: Could not find public virtual keywords in generated code."; exit 1; \
|
||||
fi
|
||||
@if [ `grep -r "public virtual" virtualwrap.tmpdir/WrapTest | wc -l` -ne 4 ]; then \
|
||||
echo "Error: Expected 4 virtual keywords in generated code."; exit 1; \
|
||||
fi
|
||||
|
||||
clean-local::
|
||||
rm -f *.dll *.source
|
||||
rm -Rf *.tmpdir
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
using System;
|
||||
using MonoTouch.UIKit;
|
||||
using MonoTouch.ObjCRuntime;
|
||||
using MonoTouch.Foundation;
|
||||
|
||||
namespace WrapTest {
|
||||
|
||||
[BaseType (typeof (NSObject))]
|
||||
interface MyFooClass {
|
||||
|
||||
[Export ("fooString")]
|
||||
string FooString { get; }
|
||||
|
||||
[Wrap ("(NSString) FooString", isVirtual: true)]
|
||||
NSString FooNSString { get; }
|
||||
|
||||
[Wrap ("(NSString) FooString")]
|
||||
NSString FooNSStringN { get; }
|
||||
|
||||
[Export ("fooWithContentsOfURL:")]
|
||||
void FromUrl (NSUrl url);
|
||||
|
||||
[Wrap ("FromUrl (NSUrl.FromString (url))", isVirtual: true)]
|
||||
void FromUrl (string url);
|
||||
|
||||
[Wrap ("FromUrl (NSUrl.FromString (url))")]
|
||||
void FromUrlN (string url);
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче