Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 2597563

Browse files
Merge pull request #434 from xamarin/clean-up-on-aisle-seven
Missed a couple types
2 parents 73e015d + 2f77a2d commit 2597563

File tree

2 files changed

+13
-99
lines changed

2 files changed

+13
-99
lines changed

SwiftRuntimeLibrary/SwiftAnyObject.cs

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,66 +6,24 @@
66
using SwiftRuntimeLibrary.SwiftMarshal;
77

88
namespace SwiftRuntimeLibrary {
9-
public sealed class SwiftAnyObject : ISwiftObject {
10-
SwiftAnyObject(IntPtr ptr)
11-
: this (ptr, SwiftObjectRegistry.Registry)
9+
public sealed class SwiftAnyObject : SwiftNativeObject {
10+
SwiftAnyObject (IntPtr ptr)
11+
: base (ptr, GetSwiftMetatype (), SwiftObjectRegistry.Registry)
1212
{
13-
}
14-
15-
SwiftAnyObject (IntPtr ptr, SwiftObjectRegistry registry)
16-
{
17-
SwiftObject = ptr;
1813
SwiftCore.Retain (ptr);
19-
registry.Add (this);
20-
}
21-
22-
#region IDisposable implementation
23-
24-
bool disposed = false;
25-
public void Dispose ()
26-
{
27-
Dispose (true);
28-
GC.SuppressFinalize (this);
2914
}
3015

3116
~SwiftAnyObject ()
3217
{
3318
Dispose (false);
3419
}
3520

36-
void Dispose (bool disposing)
37-
{
38-
if (!disposed) {
39-
if (disposing) {
40-
DisposeManagedResources ();
41-
}
42-
DisposeUnmanagedResources ();
43-
disposed = true;
44-
}
45-
}
46-
47-
void DisposeManagedResources ()
48-
{
49-
}
50-
51-
void DisposeUnmanagedResources ()
52-
{
53-
SwiftCore.Release (SwiftObject);
54-
}
55-
#endregion
56-
57-
#region ISwiftObject implementation
58-
59-
public IntPtr SwiftObject { get; set; }
60-
6121
public static SwiftAnyObject XamarinFactory (IntPtr p)
6222
{
63-
return new SwiftAnyObject (p, SwiftObjectRegistry.Registry);
23+
return new SwiftAnyObject (p);
6424
}
6525

66-
#endregion
67-
68-
public static SwiftAnyObject FromISwiftObject(ISwiftObject obj)
26+
public static SwiftAnyObject FromISwiftObject (ISwiftObject obj)
6927
{
7028
if (obj == null)
7129
throw new ArgumentNullException (nameof (obj));
@@ -80,7 +38,7 @@ public static SwiftMetatype GetSwiftMetatype ()
8038
public T CastAs<T> () where T : class, ISwiftObject
8139
{
8240
var metaType = StructMarshal.Marshaler.Metatypeof (typeof (T));
83-
using (var optional = SwiftOptional<T>.None()) {
41+
using (var optional = SwiftOptional<T>.None ()) {
8442
unsafe {
8543
fixed (byte* dataPtr = StructMarshal.Marshaler.PrepareNominal (optional)) {
8644
NativeMethodsForSwiftAnyObject.CastAs (new IntPtr (dataPtr), SwiftObject, metaType);
@@ -94,8 +52,7 @@ public T CastAs<T> () where T : class, ISwiftObject
9452
}
9553

9654
internal static class NativeMethodsForSwiftAnyObject {
97-
[DllImport(SwiftCore.kXamGlue, EntryPoint = XamGlueConstants.SwiftAnyObject_CastAs)]
55+
[DllImport (SwiftCore.kXamGlue, EntryPoint = XamGlueConstants.SwiftAnyObject_CastAs)]
9856
public static extern void CastAs (IntPtr retval, IntPtr obj, SwiftMetatype meta);
9957
}
100-
}
101-
58+
}

SwiftRuntimeLibrary/SwiftIteratorProtocol.cs

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct SwiftIteratorProtocolVtable {
3030
}
3131

3232

33-
public class SwiftIteratorProtocolProxy<T> : ISwiftObject, IIteratorProtocol<T> {
33+
public class SwiftIteratorProtocolProxy<T> : SwiftNativeObject, IIteratorProtocol<T> {
3434
static SwiftIteratorProtocolProxy ()
3535
{
3636
SetVTable ();
@@ -52,72 +52,29 @@ static void NextFuncReceiver (IntPtr returnVal, IntPtr self)
5252

5353
IIteratorProtocol<T> proxiedType;
5454

55+
5556
public SwiftIteratorProtocolProxy (IIteratorProtocol<T> proxiedType)
57+
: base (IteratorProtocolPinvokes.NewIteratorProtocol (StructMarshal.Marshaler.Metatypeof (typeof (T))),
58+
GetSwiftMetatype (), SwiftObjectRegistry.Registry)
5659
{
5760
this.proxiedType = proxiedType;
58-
SwiftObject = IteratorProtocolPinvokes.NewIteratorProtocol (StructMarshal.Marshaler.Metatypeof (typeof (T)));
59-
SwiftCore.Retain (SwiftObject);
60-
SwiftObjectRegistry.Registry.Add (this);
61-
}
62-
63-
SwiftIteratorProtocolProxy (IntPtr ptr)
64-
: this (ptr, SwiftObjectRegistry.Registry)
65-
{
6661
}
6762

6863
SwiftIteratorProtocolProxy (IntPtr ptr, SwiftObjectRegistry registry)
64+
: base (ptr, GetSwiftMetatype (), registry)
6965
{
70-
SwiftObject = ptr;
71-
SwiftCore.Retain (ptr);
72-
registry.Add (this);
73-
}
74-
75-
#region IDisposable implementation
76-
77-
bool disposed = false;
78-
public void Dispose ()
79-
{
80-
Dispose (true);
81-
GC.SuppressFinalize (this);
8266
}
8367

8468
~SwiftIteratorProtocolProxy ()
8569
{
8670
Dispose (false);
8771
}
8872

89-
void Dispose (bool disposing)
90-
{
91-
if (!disposed) {
92-
if (disposing) {
93-
DisposeManagedResources ();
94-
}
95-
DisposeUnmanagedResources ();
96-
disposed = true;
97-
}
98-
}
99-
100-
void DisposeManagedResources ()
101-
{
102-
}
103-
104-
void DisposeUnmanagedResources ()
105-
{
106-
SwiftCore.Release (SwiftObject);
107-
}
108-
#endregion
109-
110-
#region ISwiftObject implementation
111-
112-
public IntPtr SwiftObject { get; set; }
113-
11473
public static SwiftIteratorProtocolProxy<T> XamarinFactory (IntPtr p)
11574
{
11675
return new SwiftIteratorProtocolProxy<T> (p, SwiftObjectRegistry.Registry);
11776
}
11877

119-
#endregion
120-
12178
public static SwiftMetatype GetSwiftMetatype ()
12279
{
12380
return IteratorProtocolPinvokes.IteratorProtocolMetadataAccessor (SwiftMetadataRequest.Complete, StructMarshal.Marshaler.Metatypeof (typeof (T)));

0 commit comments

Comments
 (0)