[src] Propagate the [CCallback] and [BlockCallback] attributes to generated code. (#20225)
The generator needs these attributes in certain cases when a third-party library implements a protocol that subclasses a platform protocol where members of the platform protocol has members with parameters with these attributes. That's a rather long sentence: in fact there are fewer words in the test verifying this behavior!
This commit is contained in:
Родитель
6fd2189274
Коммит
8cfbe6fac6
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
|
||||
namespace ObjCRuntime {
|
||||
/// <summary>
|
||||
/// This attribute is applied to delegate parameters in a delegate to specify
|
||||
/// that the delegate parameter needs an Objective-C Block-style bridge.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <seealso cref='T:ObjCRuntime.CCallbackAttribute' />
|
||||
/// </remarks>
|
||||
[AttributeUsage (AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class BlockCallbackAttribute : Attribute {
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BlockCallbackAttribute"/> class.
|
||||
/// </summary>
|
||||
public BlockCallbackAttribute ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
|
||||
namespace ObjCRuntime {
|
||||
/// <summary>
|
||||
/// This attribute is applied to delegate parameters in a delegate to specify
|
||||
/// that the delegate parameter needs an C-style bridge.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <seealso cref='T:ObjCRuntime.BlockCallbackAttribute' />
|
||||
/// </remarks>
|
||||
[AttributeUsage (AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class CCallbackAttribute : Attribute {
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CCallbackAttribute"/> class.
|
||||
/// </summary>
|
||||
public CCallbackAttribute ()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -368,18 +368,6 @@ public class AlignAttribute : Attribute {
|
|||
public class ParamsAttribute : Attribute {
|
||||
}
|
||||
|
||||
//
|
||||
// These two attributes can be applied to parameters in a C# delegate
|
||||
// declaration to specify what kind of bridge needs to be provided on
|
||||
// callback. Either a Block style setup, or a C-style setup
|
||||
//
|
||||
[AttributeUsage (AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class BlockCallbackAttribute : Attribute { }
|
||||
|
||||
[AttributeUsage (AttributeTargets.Parameter, AllowMultiple = false)]
|
||||
public class CCallbackAttribute : Attribute { }
|
||||
|
||||
|
||||
//
|
||||
// When applied, flags the [Flags] as a notification and generates the
|
||||
// code to strongly type the notification.
|
||||
|
|
|
@ -6813,12 +6813,17 @@ public partial class Generator : IMemberGatherer {
|
|||
{
|
||||
var pt = p.ParameterType;
|
||||
|
||||
string name;
|
||||
string name = string.Empty;
|
||||
if (AttributeManager.HasAttribute<BlockCallbackAttribute> (p))
|
||||
name = "[BlockCallback] ";
|
||||
else if (AttributeManager.HasAttribute<CCallbackAttribute> (p))
|
||||
name = "[CCallback] ";
|
||||
|
||||
if (pt.IsByRef) {
|
||||
pt = pt.GetElementType ();
|
||||
name = (removeRefTypes ? "" : (p.IsOut ? "out " : "ref ")) + TypeManager.RenderType (pt, p);
|
||||
name += (removeRefTypes ? "" : (p.IsOut ? "out " : "ref ")) + TypeManager.RenderType (pt, p);
|
||||
} else
|
||||
name = TypeManager.RenderType (pt, p);
|
||||
name += TypeManager.RenderType (pt, p);
|
||||
if (!pt.IsValueType && AttributeManager.HasAttribute<NullAllowedAttribute> (p))
|
||||
name += "?";
|
||||
return name;
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\ArgumentSemantic.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\BindAsAttribute.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\BindingImplAttribute.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\BlockCallbackAttribute.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\CCallbackAttribute.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\LinkWithAttribute.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\NativeAttribute.cs" />
|
||||
<Compile Include="$(RepositoryPath)\src\ObjCRuntime\NativeNameAttribute.cs" />
|
||||
|
|
|
@ -1928,6 +1928,8 @@ SHARED_CORE_SOURCES = \
|
|||
ObjCRuntime/ArgumentSemantic.cs \
|
||||
ObjCRuntime/BindAsAttribute.cs \
|
||||
ObjCRuntime/Blocks.cs \
|
||||
ObjCRuntime/BlockCallbackAttribute.cs \
|
||||
ObjCRuntime/CCallbackAttribute.cs \
|
||||
ObjCRuntime/Class.cs \
|
||||
ObjCRuntime/Constants.cs \
|
||||
ObjCRuntime/DisposableObject.cs \
|
||||
|
|
|
@ -133,6 +133,8 @@
|
|||
<Compile Include="..\src\ObjCRuntime\ArgumentSemantic.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\BindAsAttribute.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\BindingImplAttribute.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\BlockCallbackAttribute.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\CCallbackAttribute.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\LinkWithAttribute.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\NativeAttribute.cs" />
|
||||
<Compile Include="..\src\ObjCRuntime\NativeNameAttribute.cs" />
|
||||
|
|
|
@ -1434,6 +1434,12 @@ namespace GeneratorTests {
|
|||
BuildFile (Profile.iOS, "tests/internal-delegate.cs");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DelegateParameterAttributes ()
|
||||
{
|
||||
BuildFile (Profile.iOS, "tests/delegate-parameter-attributes.cs");
|
||||
}
|
||||
|
||||
#if NET
|
||||
[Test]
|
||||
public void Issue19612 ()
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
using Foundation;
|
||||
|
||||
namespace Test {
|
||||
[Protocol]
|
||||
interface DerivedProtocol : INSFilePresenter { }
|
||||
}
|
Загрузка…
Ссылка в новой задаче