summaryrefslogtreecommitdiff
path: root/src/bindings/mono
diff options
context:
space:
mode:
Diffstat (limited to 'src/bindings/mono')
-rw-r--r--src/bindings/mono/ca.ruleset.in334
-rw-r--r--src/bindings/mono/efl_mono.dll.config.in17
-rw-r--r--src/bindings/mono/efl_mono/AssemblyInfo.cs.in3
-rw-r--r--src/bindings/mono/efl_mono/GenericModel.cs10
-rw-r--r--src/bindings/mono/efl_mono/ItemFactory.cs7
-rw-r--r--src/bindings/mono/efl_mono/UserModel.cs19
-rw-r--r--src/bindings/mono/efl_mono/efl_all.cs78
-rw-r--r--src/bindings/mono/efl_mono/efl_csharp_application.cs122
-rw-r--r--src/bindings/mono/efl_mono/efl_libs.cs.in15
-rw-r--r--src/bindings/mono/efl_mono/efl_libs.csv.in15
-rw-r--r--src/bindings/mono/efl_mono/meson.build24
-rw-r--r--src/bindings/mono/efl_sharp.csproj.in48
-rw-r--r--src/bindings/mono/eina_mono/eina_accessor.cs50
-rw-r--r--src/bindings/mono/eina_mono/eina_array.cs332
-rw-r--r--src/bindings/mono/eina_mono/eina_binbuf.cs19
-rw-r--r--src/bindings/mono/eina_mono/eina_common.cs21
-rw-r--r--src/bindings/mono/eina_mono/eina_config.cs15
-rw-r--r--src/bindings/mono/eina_mono/eina_container_common.cs172
-rw-r--r--src/bindings/mono/eina_mono/eina_environment.cs53
-rw-r--r--src/bindings/mono/eina_mono/eina_error.cs150
-rw-r--r--src/bindings/mono/eina_mono/eina_hash.cs70
-rw-r--r--src/bindings/mono/eina_mono/eina_inarray.cs22
-rw-r--r--src/bindings/mono/eina_mono/eina_inlist.cs22
-rw-r--r--src/bindings/mono/eina_mono/eina_iterator.cs22
-rw-r--r--src/bindings/mono/eina_mono/eina_list.cs386
-rw-r--r--src/bindings/mono/eina_mono/eina_log.cs19
-rw-r--r--src/bindings/mono/eina_mono/eina_promises.cs23
-rw-r--r--src/bindings/mono/eina_mono/eina_slice.cs116
-rw-r--r--src/bindings/mono/eina_mono/eina_strbuf.cs20
-rw-r--r--src/bindings/mono/eina_mono/eina_stringshare.cs30
-rw-r--r--src/bindings/mono/eina_mono/eina_value.cs627
-rw-r--r--src/bindings/mono/eina_mono/meson.build3
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_common.cs433
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_config.cs15
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_connection.cs29
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_message.cs19
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_object.cs30
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_pending.cs17
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_proxy.cs42
-rw-r--r--src/bindings/mono/eldbus_mono/eldbus_service.cs17
-rw-r--r--src/bindings/mono/eo_mono/EoWrapper.cs224
-rw-r--r--src/bindings/mono/eo_mono/FunctionWrapper.cs139
-rw-r--r--src/bindings/mono/eo_mono/FunctionWrapper_Unix.cs36
-rw-r--r--src/bindings/mono/eo_mono/FunctionWrapper_Windows.cs26
-rw-r--r--src/bindings/mono/eo_mono/NativeModule.cs60
-rw-r--r--src/bindings/mono/eo_mono/NativeModule_Unix.cs28
-rw-r--r--src/bindings/mono/eo_mono/NativeModule_Windows.cs26
-rw-r--r--src/bindings/mono/eo_mono/WrapperSupervisor.cs34
-rw-r--r--src/bindings/mono/eo_mono/iwrapper.cs716
-rw-r--r--src/bindings/mono/eo_mono/workaround.cs201
-rw-r--r--src/bindings/mono/meson.build185
51 files changed, 4053 insertions, 1088 deletions
diff --git a/src/bindings/mono/ca.ruleset.in b/src/bindings/mono/ca.ruleset.in
new file mode 100644
index 0000000..0f5be88
--- /dev/null
+++ b/src/bindings/mono/ca.ruleset.in
@@ -0,0 +1,334 @@
1<?xml version="1.0" encoding="utf-8"?>
2<RuleSet Name="CustomRulset" Description="Custom Rulset" ToolsVersion="14.0">
3 <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
4 <!-- Do not declare static members on Generic Types -->
5 @CA1000@
6 <!-- Consider making Raise an event -->
7 @CA1030@
8 <!-- Catch generic exception -->
9 @CA1031@
10 <!-- Add extra exception constructors -->
11 @CA1032@
12 <!-- Do not nest NativeTypes -->
13 @CA1034@
14 <!-- IComparable must implement other comparison operators -->
15 @CA1036@
16 <!-- Avoid empty interface -->
17 @CA1040@
18 <!-- Use Integral Or String Argument For Indexers -->
19 @CA1043@
20 <!-- Consider making property with getter -->
21 @CA1044@
22 <!-- Visible instance fields -->
23 @CA1051@
24 <!-- Static holder can be static -->
25 @CA1052@
26 <!-- Using parameters before checking for null -->
27 @CA1062@
28 <!-- Remove IDisposable as Object already has it -->
29 @CA1063@
30 <!-- Exceptions must be public -->
31 @CA1064@
32 <!-- Do not raise exception in unexpected locations -->
33 @CA1065@
34 <!-- String localization -->
35 @CA1303@
36 <!-- Specify IFormatProvider -->
37 @CA1305@
38 <!-- Specify Stringcomparison -->
39 @CA1307@
40 <!-- PInvoke should not be visible -->
41 @CA1401@
42 <!-- Use nameof -->
43 @CA1507@
44 <!-- Parameter underscore -->
45 @CA1707@
46 <!-- Attribute classes must have the Attribute Suffix -->
47 @CA1710@
48 <!-- Replace generic parameter with T -->
49 @CA1715@
50 <!-- Parameter End conflicts with VB -->
51 @CA1716@
52 <!-- Enum field must be plural -->
53 @CA1717@
54 <!-- Variable has type name -->
55 @CA1720@
56 <!-- Property with same name as getter -->
57 @CA1721@
58 <!-- Type name must not match namespace -->
59 @CA1724@
60 <!-- Unused parameter. Lots of warnings regarding Dispose(disposing) -->
61 @CA1801@
62 <!-- Do not ignore function result -->
63 @CA1806@
64 <!-- Remove static constructors -->
65 @CA1810@
66 <!-- Realized classes are never instantiated -->
67 @CA1812@
68 <!-- Override equal and operator equal on Value Types-->
69 @CA1815@
70 <!-- Dispose must call SuppressFinalizers -->
71 @CA1816@
72 <!-- Member can be static -->
73 @CA1822@
74 <!-- Consider zero length array allocation -->
75 @CA1825@
76 <!-- Count() is used where Any() could be used instead to improve performance -->
77 @CA1827@
78 <!-- Use Count instead of Count() -->
79 @CA1829@
80 <!-- Call dispose before going out of scope -->
81 @CA2000@
82 <!-- Call ConfigureWait-->
83 @CA2007@
84 <!-- PInvoke should specify string marshalling -->
85 @CA2101@
86 <!-- Rethrow loses stack info -->
87 @CA2200@
88 <!-- Declare static fields when they are declared and remove static constructor -->
89 @CA2207@
90 <!-- Instantiate exception params correctly -->
91 @CA2208@
92 <!-- Dot not call overrideable methods in constructors -->
93 @CA2214@
94 <!-- Replace implicit operator -->
95 @CA2225@
96 <!-- Change 'XXXXX' to be read-only by removing the property setter -->
97 @CA2227@
98
99
100
101 </Rules>
102 <Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
103 <!-- Ignore docs -->
104 @SA0001@
105
106 <!-- 10** Spacing rules -->
107 @SA1000@
108 @SA1001@
109 @SA1002@
110 @SA1003@
111 <!-- Documentation must start with single space -->
112 @SA1004@
113 @SA1005@
114 @SA1006@
115 @SA1007@
116 @SA1008@
117 @SA1009@
118 @SA1010@
119 @SA1011@
120 @SA1012@
121 @SA1013@
122 @SA1014@
123 @SA1015@
124 @SA1016@
125 @SA1017@
126 @SA1018@
127 @SA1019@
128 @SA1020@
129 @SA1021@
130 @SA1022@
131 @SA1023@
132 @SA1024@
133 @SA1025@
134 @SA1026@
135 @SA1027@
136 @SA1028@
137
138 <!-- Readability -->
139 @SA1100@
140 @SA1101@
141 @SA1102@
142 @SA1103@
143 @SA1104@
144 @SA1105@
145 @SA1106@
146 @SA1107@
147 @SA1108@
148 @SA1109@
149 @SA1110@
150 @SA1111@
151 @SA1112@
152 @SA1113@
153 @SA1114@
154 @SA1115@
155 @SA1116@
156 @SA1117@
157 @SA1118@
158 @SA1119@
159 @SA1120@
160 @SA1121@
161 @SA1122@
162 @SA1123@
163 @SA1124@
164 @SA1125@
165 @SA1126@
166 @SA1127@
167 @SA1128@
168 @SA1129@
169 @SA1130@
170 @SA1131@
171 @SA1132@
172 @SA1133@
173 @SA1134@
174 @SA1135@
175 @SA1136@
176 @SA1137@
177 @SA1138@
178 @SA1139@
179
180 <!-- 12** Ordering -->
181 <!-- FIXME Check if this somehow affects docfx output -->
182 @SA1200@
183 @SA1201@
184 @SA1202@
185 @SA1203@
186 @SA1204@
187 @SA1205@
188 @SA1206@
189 @SA1207@
190 @SA1208@
191 @SA1209@
192 @SA1210@
193 @SA1211@
194 @SA1212@
195 @SA1213@
196 @SA1214@
197 @SA1215@
198 @SA1216@
199 @SA1217@
200
201 <!-- 13** Naming Rules -->
202 <!-- Element start with upper case -->
203 @SA1300@
204 @SA1301@
205 <!-- Interface start with I -->
206 @SA1302@
207 <!-- Upper/lower score rules -->
208 @SA1303@
209 @SA1304@
210 @SA1305@
211 @SA1306@
212 @SA1307@
213 <!-- Variable field prefixes -->
214 @SA1308@
215 @SA1309@
216 @SA1310@
217 @SA1311@
218 @SA1312@
219 @SA1313@
220 @SA1314@
221
222 <!-- 14** Maintainability -->
223 <!-- Access modifier -->
224 @SA1400@
225 <!-- Field must be private -->
226 @SA1401@
227 <!-- File Must contain single class or namespace -->
228 @SA1402@
229 @SA1403@
230 <!-- CodeAnalysis suppress does not have justification -->
231 @SA1404@
232 <!-- Debug.Assert/Fail must provide a message -->
233 @SA1405@
234 @SA1406@
235 <!-- Arithmetic/Conditional expression must declare precedence -->
236 @SA1407@
237 @SA1408@
238 <!-- Remove unecessary code -->
239 @SA1409@
240 <!-- Delegate/Attribute parentheses -->
241 @SA1410@
242 @SA1411@
243 <!-- Utf8 file -->
244 @SA1412@
245 <!-- Trailing commas multiline initializer -->
246 @SA1413@
247
248 <!-- 15** Layout Rules -->
249 @SA1500@
250 @SA1501@
251 @SA1502@
252 @SA1503@
253 @SA1504@
254 @SA1505@
255 @SA1506@
256 @SA1507@
257 @SA1508@
258 @SA1509@
259 @SA1510@
260 @SA1511@
261 @SA1512@
262 @SA1513@
263 @SA1514@
264 @SA1515@
265 @SA1516@
266 @SA1517@
267 @SA1518@
268 @SA1519@
269 @SA1520@
270
271 <!-- 16** Documentation rules -->
272 <!-- Things must be documented -->
273 @SA1600@
274 @SA1601@
275 @SA1602@
276 <!-- Valid xml in docs -->
277 @SA1603@
278 @SA1604@
279 @SA1605@
280 @SA1606@
281 @SA1607@
282 @SA1608@
283 @SA1609@
284 @SA1610@
285 @SA1611@
286 @SA1612@
287 @SA1613@
288 @SA1614@
289 @SA1615@
290 @SA1616@
291 @SA1617@
292 @SA1618@
293 @SA1619@
294 @SA1620@
295 @SA1621@
296 @SA1622@
297 @SA1623@
298 @SA1624@
299 @SA1625@
300 @SA1626@
301 @SA1627@
302 @SA1628@
303 @SA1629@
304 @SA1630@
305 @SA1631@
306 @SA1632@
307 <!-- File headers -->
308 @SA1633@
309 @SA1634@
310 @SA1635@
311 @SA1636@
312 @SA1637@
313 @SA1638@
314 @SA1639@
315 @SA1640@
316 @SA1641@
317 <!-- Constructor/Destructor -->
318 @SA1642@
319 @SA1643@
320 <!-- File header -->
321 @SA1644@
322 <!-- Miscellaneous doc -->
323 @SA1645@
324 @SA1646@
325 @SA1647@
326 @SA1648@
327 <!-- Filename must match file type -->
328 @SA1649@
329 <!-- Spelling -->
330 @SA1650@
331 <!-- Placeholder -->
332 @SA1651@
333 </Rules>
334</RuleSet>
diff --git a/src/bindings/mono/efl_mono.dll.config.in b/src/bindings/mono/efl_mono.dll.config.in
index b84883f..25d216b 100644
--- a/src/bindings/mono/efl_mono.dll.config.in
+++ b/src/bindings/mono/efl_mono.dll.config.in
@@ -1,3 +1,20 @@
1<!--
2/*
3 * Copyright 2019 by its authors. See AUTHORS.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17-->
1<configuration> 18<configuration>
2 <dllmap dll="eina" target="@EINA@"/> 19 <dllmap dll="eina" target="@EINA@"/>
3 <dllmap dll="efl" target="@EFL@"/> 20 <dllmap dll="efl" target="@EFL@"/>
diff --git a/src/bindings/mono/efl_mono/AssemblyInfo.cs.in b/src/bindings/mono/efl_mono/AssemblyInfo.cs.in
new file mode 100644
index 0000000..e22d0a4
--- /dev/null
+++ b/src/bindings/mono/efl_mono/AssemblyInfo.cs.in
@@ -0,0 +1,3 @@
1using System.Runtime.CompilerServices;
2
3@MONO_FRIEND_ASSEMBLIES@
diff --git a/src/bindings/mono/efl_mono/GenericModel.cs b/src/bindings/mono/efl_mono/GenericModel.cs
index 1f92b8c..8d7cc81 100644
--- a/src/bindings/mono/efl_mono/GenericModel.cs
+++ b/src/bindings/mono/efl_mono/GenericModel.cs
@@ -18,7 +18,7 @@ namespace Efl {
18/// </summary> 18/// </summary>
19/// <typeparam name="T">The type of the child model. It is the type used when adding/removing/getting items to this 19/// <typeparam name="T">The type of the child model. It is the type used when adding/removing/getting items to this
20/// model.</typeparam> 20/// model.</typeparam>
21public class GenericModel<T> : Efl.Object, Efl.IModel, IDisposable 21public class GenericModel<T> : Efl.Object, Efl.IModel
22{ 22{
23 private Efl.IModel model; 23 private Efl.IModel model;
24 24
@@ -31,7 +31,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel, IDisposable
31 } 31 }
32 32
33 /// <summary>The list of properties available in the wrapped model.</summary> 33 /// <summary>The list of properties available in the wrapped model.</summary>
34 public Eina.Iterator< System.String> Properties 34 public IEnumerable<System.String> Properties
35 { 35 {
36 get { return GetProperties(); } 36 get { return GetProperties(); }
37 } 37 }
@@ -44,7 +44,7 @@ public class GenericModel<T> : Efl.Object, Efl.IModel, IDisposable
44 44
45 /// <summary>The list of properties available in the wrapped model.</summary> 45 /// <summary>The list of properties available in the wrapped model.</summary>
46 /// <returns>The list of properties in the model.</returns> 46 /// <returns>The list of properties in the model.</returns>
47 public Eina.Iterator<System.String> GetProperties() 47 public IEnumerable<System.String> GetProperties()
48 { 48 {
49 return model.GetProperties(); 49 return model.GetProperties();
50 } 50 }
@@ -119,12 +119,12 @@ public class GenericModel<T> : Efl.Object, Efl.IModel, IDisposable
119 /// <returns>Token to notify the async operation of external request to cancel.</returns> 119 /// <returns>Token to notify the async operation of external request to cancel.</returns>
120 async public System.Threading.Tasks.Task<T> GetAtAsync(uint index) 120 async public System.Threading.Tasks.Task<T> GetAtAsync(uint index)
121 { 121 {
122 using (Eina.Value v = await GetChildrenSliceAsync(index, 1)) 122 using (Eina.Value v = await GetChildrenSliceAsync(index, 1).ConfigureAwait(false))
123 { 123 {
124 if (v.GetValueType().IsContainer()) 124 if (v.GetValueType().IsContainer())
125 { 125 {
126 var child = (Efl.IModel)v[0]; 126 var child = (Efl.IModel)v[0];
127 T obj = (T)Activator.CreateInstance(typeof(T), new System.Object[] {}); 127 T obj = (T)Activator.CreateInstance(typeof(T), Array.Empty<object>());
128 ModelHelper.GetProperties(obj, child); 128 ModelHelper.GetProperties(obj, child);
129 return obj; 129 return obj;
130 } 130 }
diff --git a/src/bindings/mono/efl_mono/ItemFactory.cs b/src/bindings/mono/efl_mono/ItemFactory.cs
index be429fd..a97401c 100644
--- a/src/bindings/mono/efl_mono/ItemFactory.cs
+++ b/src/bindings/mono/efl_mono/ItemFactory.cs
@@ -6,7 +6,8 @@ using System.Collections.Generic;
6using System.Linq; 6using System.Linq;
7using System.ComponentModel; 7using System.ComponentModel;
8 8
9namespace Efl { namespace Ui { 9namespace Efl.Ui
10{
10 11
11/// <summary>Helper factory class. Makes use of C# extension methods for easier property binding. 12/// <summary>Helper factory class. Makes use of C# extension methods for easier property binding.
12/// 13///
@@ -15,7 +16,7 @@ namespace Efl { namespace Ui {
15/// factory.Style().Bind("Name"); // The factory Style property is bound to the Name property for the given model. 16/// factory.Style().Bind("Name"); // The factory Style property is bound to the Name property for the given model.
16/// </code> 17/// </code>
17/// </summary> 18/// </summary>
18public class ItemFactory<T> : Efl.Ui.LayoutFactory, IDisposable 19public class ItemFactory<T> : Efl.Ui.LayoutFactory
19{ 20{
20 /// <summary>Creates a new factory. 21 /// <summary>Creates a new factory.
21 /// </summary> 22 /// </summary>
@@ -26,6 +27,6 @@ public class ItemFactory<T> : Efl.Ui.LayoutFactory, IDisposable
26 } 27 }
27} 28}
28 29
29} } 30}
30 31
31#endif 32#endif
diff --git a/src/bindings/mono/efl_mono/UserModel.cs b/src/bindings/mono/efl_mono/UserModel.cs
index 1116dfc..99350b1 100644
--- a/src/bindings/mono/efl_mono/UserModel.cs
+++ b/src/bindings/mono/efl_mono/UserModel.cs
@@ -27,9 +27,12 @@ internal class ModelHelper
27 static internal void SetProperties<T>(T o, Efl.IModel child) 27 static internal void SetProperties<T>(T o, Efl.IModel child)
28 { 28 {
29 var properties = typeof(T).GetProperties(); 29 var properties = typeof(T).GetProperties();
30 foreach(var prop in properties) 30 foreach (var prop in properties)
31 { 31 {
32 child.SetProperty(prop.Name, ValueFromProperty(o, prop)); 32 using (var tmp = ValueFromProperty(o, prop))
33 {
34 child.SetProperty(prop.Name, tmp);
35 }
33 } 36 }
34 } 37 }
35 38
@@ -37,7 +40,7 @@ internal class ModelHelper
37 static internal void GetProperties<T>(T o, Efl.IModel child) 40 static internal void GetProperties<T>(T o, Efl.IModel child)
38 { 41 {
39 var properties = typeof(T).GetProperties(); 42 var properties = typeof(T).GetProperties();
40 foreach(var prop in properties) 43 foreach (var prop in properties)
41 { 44 {
42 using (var v = child.GetProperty(prop.Name)) 45 using (var v = child.GetProperty(prop.Name))
43 { 46 {
@@ -67,7 +70,7 @@ internal class ModelHelper
67/// </summary> 70/// </summary>
68/// <typeparam name="T">The enclosed C# model class with the properties to be added to the native model.</typeparam> 71/// <typeparam name="T">The enclosed C# model class with the properties to be added to the native model.</typeparam>
69[Efl.Eo.BindingEntity] 72[Efl.Eo.BindingEntity]
70public class UserModel<T> : Efl.MonoModelInternal, IDisposable 73public class UserModel<T> : Efl.MonoModelInternal
71{ 74{
72 /// <summary> 75 /// <summary>
73 /// Creates a new root model. 76 /// Creates a new root model.
@@ -79,18 +82,12 @@ public class UserModel<T> : Efl.MonoModelInternal, IDisposable
79 public UserModel (Efl.Object parent = null) : base(Efl.MonoModelInternal.efl_mono_model_internal_class_get(), parent) 82 public UserModel (Efl.Object parent = null) : base(Efl.MonoModelInternal.efl_mono_model_internal_class_get(), parent)
80 { 83 {
81 var properties = typeof(T).GetProperties(); 84 var properties = typeof(T).GetProperties();
82 foreach(var prop in properties) 85 foreach (var prop in properties)
83 { 86 {
84 AddProperty(prop.Name, Eina.ValueTypeBridge.GetManaged(prop.PropertyType)); 87 AddProperty(prop.Name, Eina.ValueTypeBridge.GetManaged(prop.PropertyType));
85 } 88 }
86 } 89 }
87 90
88 /// <summary>Disposes of this instance.</summary>
89 ~UserModel()
90 {
91 Dispose(false);
92 }
93
94 /// <summary>Adds a new child to the model wrapping the properties of <c>o</c> 91 /// <summary>Adds a new child to the model wrapping the properties of <c>o</c>
95 /// 92 ///
96 /// <para>Reflection is used to instantiate a new <see cref="Efl.IModel" />-based class for this child and 93 /// <para>Reflection is used to instantiate a new <see cref="Efl.IModel" />-based class for this child and
diff --git a/src/bindings/mono/efl_mono/efl_all.cs b/src/bindings/mono/efl_mono/efl_all.cs
index de917a3..c49ec4d 100644
--- a/src/bindings/mono/efl_mono/efl_all.cs
+++ b/src/bindings/mono/efl_mono/efl_all.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -44,7 +59,7 @@ static class UnsafeNativeMethods
44/// </summary> 59/// </summary>
45public static class All 60public static class All
46{ 61{
47 private static bool InitializedUi = false; 62 private static Efl.Csharp.Components initComponents = Efl.Csharp.Components.Basic;
48 63
49 /// <summary> 64 /// <summary>
50 /// If the main loop was initialized. 65 /// If the main loop was initialized.
@@ -64,17 +79,28 @@ public static class All
64 /// <param name="components">The <see cref="Efl.Csharp.Components" /> that initialize the Efl.</param> 79 /// <param name="components">The <see cref="Efl.Csharp.Components" /> that initialize the Efl.</param>
65 public static void Init(Efl.Csharp.Components components = Efl.Csharp.Components.Basic) 80 public static void Init(Efl.Csharp.Components components = Efl.Csharp.Components.Basic)
66 { 81 {
67 Eina.Config.Init(); 82 if (components == Efl.Csharp.Components.None)
68 Efl.Eo.Config.Init(); 83 {
69 ecore_init(); 84 return;
70 ecore_init_ex(0, IntPtr.Zero); 85 }
71 evas_init(); 86
72 eldbus.Config.Init(); 87 initComponents = components;
73 88
74 if (components == Efl.Csharp.Components.Ui) 89 if ((initComponents & Efl.Csharp.Components.Basic)
90 == Efl.Csharp.Components.Basic)
91 {
92 Eina.Config.Init();
93 Efl.Eo.Config.Init();
94 ecore_init();
95 ecore_init_ex(0, IntPtr.Zero);
96 evas_init();
97 eldbus.Config.Init();
98 }
99
100 if ((initComponents & Efl.Csharp.Components.Ui)
101 == Efl.Csharp.Components.Ui)
75 { 102 {
76 Efl.Ui.Config.Init(); 103 Efl.Ui.Config.Init();
77 InitializedUi = true;
78 } 104 }
79 Monitor.Enter(InitLock); 105 Monitor.Enter(InitLock);
80 MainLoopInitialized = true; 106 MainLoopInitialized = true;
@@ -99,22 +125,32 @@ public static class All
99 MainLoopInitialized = false; 125 MainLoopInitialized = false;
100 Monitor.Exit(InitLock); 126 Monitor.Exit(InitLock);
101 127
102 if (InitializedUi) 128 if (initComponents == Efl.Csharp.Components.None)
129 {
130 return;
131 }
132
133 if ((initComponents & Efl.Csharp.Components.Ui)
134 == Efl.Csharp.Components.Ui)
103 { 135 {
104 Eina.Log.Debug("Shutting down Elementary"); 136 Eina.Log.Debug("Shutting down Elementary");
105 Efl.Ui.Config.Shutdown(); 137 Efl.Ui.Config.Shutdown();
106 } 138 }
107 139
108 Eina.Log.Debug("Shutting down Eldbus"); 140 if ((initComponents & Efl.Csharp.Components.Basic)
109 eldbus.Config.Shutdown(); 141 == Efl.Csharp.Components.Basic)
110 Eina.Log.Debug("Shutting down Evas"); 142 {
111 evas_shutdown(); 143 Eina.Log.Debug("Shutting down Eldbus");
112 Eina.Log.Debug("Shutting down Ecore"); 144 eldbus.Config.Shutdown();
113 ecore_shutdown(); 145 Eina.Log.Debug("Shutting down Evas");
114 Eina.Log.Debug("Shutting down Eo"); 146 evas_shutdown();
115 Efl.Eo.Config.Shutdown(); 147 Eina.Log.Debug("Shutting down Ecore");
116 Eina.Log.Debug("Shutting down Eina"); 148 ecore_shutdown();
117 Eina.Config.Shutdown(); 149 Eina.Log.Debug("Shutting down Eo");
150 Efl.Eo.Config.Shutdown();
151 Eina.Log.Debug("Shutting down Eina");
152 Eina.Config.Shutdown();
153 }
118 } 154 }
119} 155}
120 156
diff --git a/src/bindings/mono/efl_mono/efl_csharp_application.cs b/src/bindings/mono/efl_mono/efl_csharp_application.cs
index b4ce5d2..c4abdfe 100644
--- a/src/bindings/mono/efl_mono/efl_csharp_application.cs
+++ b/src/bindings/mono/efl_mono/efl_csharp_application.cs
@@ -1,28 +1,58 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2using System.Runtime.InteropServices; 17using System.Runtime.InteropServices;
3using System.Threading; 18using System.Threading;
4using static Efl.UnsafeNativeMethods; 19using System.Diagnostics.CodeAnalysis;
20using System.Collections.Generic;
5 21
6namespace Efl 22using static Efl.UnsafeNativeMethods;
7{
8 23
9namespace Csharp 24namespace Efl.Csharp
10{ 25{
11 26
12/// <summary>The components to be initialized. 27/// <summary>The components to be initialized.
13/// <para>Since EFL 1.23.</para> 28/// <para>Since EFL 1.23.</para>
14/// </summary> 29/// </summary>
15public enum Components 30[Flags]
31public enum Components : Int32
16{ 32{
33 // Base flags.
34 /// <summary>
35 /// Initialize nothing.
36 /// <para>Since EFL 1.24.</para>
37 /// </summary>
38 None = 0x0,
17 ///<summary>Basic components: Eina, Eo, Ecore, Evas and DBus. 39 ///<summary>Basic components: Eina, Eo, Ecore, Evas and DBus.
18 /// <para>Since EFL 1.23.</para> 40 /// <para>Since EFL 1.24.</para>
19 /// </summary> 41 /// </summary>
20 Basic, 42 Basic = 0x1,
21 ///<summary>The same components of <see cref="Efl.Csharp.Components.Basic"/> 43 /// <summary>
22 /// and the Elementary widget toolkit. 44 /// Elementary Widget toolkit: Elm.
23 /// <para>Since EFL 1.23.</para> 45 /// <para>it's depend of <see cref="Efl.Csharp.Components.Basic" />.</para>
46 /// <para>Since EFL 1.24.</para>
47 /// </summary>
48 Ui = Basic | 0x2,
49
50 // Combined flags.
51 /// <summary>
52 /// Enable all components, equals to <see cref="Efl.Csharp.Components.Ui" />.
53 /// <para>Since EFL 1.24.</para>
24 /// </summary> 54 /// </summary>
25 Ui, 55 All = int.MaxValue,
26} 56}
27 57
28/// <summary> 58/// <summary>
@@ -48,23 +78,36 @@ public enum Components
48public abstract class Application 78public abstract class Application
49{ 79{
50 //the initializied components 80 //the initializied components
51 private static Components initComponent; 81 private static Components initComponents = Components.All;
82
52 //what follows are 3 private functions to boot up the internals of efl 83 //what follows are 3 private functions to boot up the internals of efl
53 private static void Init(Efl.Csharp.Components component) 84 private static void Init(Efl.Csharp.Components components = Components.All)
54 { 85 {
55 Eina.Config.Init(); 86 if (components == Components.None)
56 Efl.Eo.Config.Init();
57 ecore_init();
58 ecore_init_ex(0, IntPtr.Zero);
59 evas_init();
60 eldbus.Config.Init();
61
62 if (component == Components.Ui)
63 { 87 {
88 return;
89 }
90
91 initComponents = components;
92
93 if ((initComponents & Components.Basic) == Components.Basic)
94 {
95 Eina.Config.Init();
96 Efl.Eo.Config.Init();
97 ecore_init();
98 ecore_init_ex(0, IntPtr.Zero);
99 evas_init();
100 eldbus.Config.Init();
101 }
102
103 if ((initComponents & Components.Ui) == Components.Ui)
104 {
105#if WIN32
64 // TODO Support elm command line arguments 106 // TODO Support elm command line arguments
65#if WIN32 // Not a native define, we define it in our build system 107 // Not a native define, we define it in our build system
66 // Ecore_Win32 uses OleInitialize, which requires single thread apartments 108 // Ecore_Win32 uses OleInitialize, which requires single thread apartments
67 if (System.Threading.Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) 109 if (System.Threading.Thread.CurrentThread.GetApartmentState()
110 != ApartmentState.STA)
68 { 111 {
69 throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()"); 112 throw new InvalidOperationException("UI Applications require STAThreadAttribute in Main()");
70 } 113 }
@@ -73,8 +116,6 @@ public abstract class Application
73 116
74 Efl.Ui.Win.ExitOnAllWindowsClosed = new Eina.Value(0); 117 Efl.Ui.Win.ExitOnAllWindowsClosed = new Eina.Value(0);
75 } 118 }
76
77 initComponent = component;
78 } 119 }
79 120
80 private static void Shutdown() 121 private static void Shutdown()
@@ -83,16 +124,24 @@ public abstract class Application
83 System.GC.Collect(); 124 System.GC.Collect();
84 System.GC.WaitForPendingFinalizers(); 125 System.GC.WaitForPendingFinalizers();
85 126
86 if (initComponent == Components.Ui) 127 if (initComponents == Components.None)
128 {
129 return;
130 }
131
132 if ((initComponents & Components.Ui) == Components.Ui)
87 { 133 {
88 elm_shutdown(); 134 elm_shutdown();
89 } 135 }
90 136
91 eldbus.Config.Shutdown(); 137 if ((initComponents & Components.Basic) == Components.Basic)
92 evas_shutdown(); 138 {
93 ecore_shutdown(); 139 eldbus.Config.Shutdown();
94 Efl.Eo.Config.Shutdown(); 140 evas_shutdown();
95 Eina.Config.Shutdown(); 141 ecore_shutdown();
142 Efl.Eo.Config.Shutdown();
143 Eina.Config.Shutdown();
144 }
96 } 145 }
97 146
98 /// <summary> 147 /// <summary>
@@ -145,13 +194,14 @@ public abstract class Application
145 /// <para>Since EFL 1.23.</para> 194 /// <para>Since EFL 1.23.</para>
146 /// </summary> 195 /// </summary>
147 /// <param name="components">The <see cref="Efl.Csharp.Components" /> to run the application.</param> 196 /// <param name="components">The <see cref="Efl.Csharp.Components" /> to run the application.</param>
148 public void Launch(Efl.Csharp.Components components = Components.Ui) 197 public void Launch(Efl.Csharp.Components components = Components.All)
149 { 198 {
150 Init(components); 199 Init(components);
151 Efl.App app = Efl.App.AppMain; 200 Efl.App app = Efl.App.AppMain;
152 var command_line = new Eina.Array<Eina.Stringshare>();
153 command_line.Append(Array.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s));
154#if EFL_BETA 201#if EFL_BETA
202 var command_line = new List<Eina.Stringshare>();
203 //command_line.Add(List.ConvertAll(Environment.GetCommandLineArgs(), s => (Eina.Stringshare)s));
204 //command_line.AddRange(Environment.GetCommandLineArgs());
155 app.SetCommandArray(command_line); 205 app.SetCommandArray(command_line);
156#endif 206#endif
157 app.ArgumentsEvent += (object sender, LoopArgumentsEventArgs evt) => 207 app.ArgumentsEvent += (object sender, LoopArgumentsEventArgs evt) =>
@@ -159,7 +209,7 @@ public abstract class Application
159 if (evt.arg.Initialization) 209 if (evt.arg.Initialization)
160 { 210 {
161 var evtArgv = evt.arg.Argv; 211 var evtArgv = evt.arg.Argv;
162 int n = evtArgv.Length; 212 int n = evtArgv.Count;
163 var argv = new string[n]; 213 var argv = new string[n];
164 for (int i = 0; i < n; ++i) 214 for (int i = 0; i < n; ++i)
165 { 215 {
@@ -189,5 +239,3 @@ public abstract class Application
189} 239}
190 240
191} 241}
192
193}
diff --git a/src/bindings/mono/efl_mono/efl_libs.cs.in b/src/bindings/mono/efl_mono/efl_libs.cs.in
index 31e0455..fcf5b18 100644
--- a/src/bindings/mono/efl_mono/efl_libs.cs.in
+++ b/src/bindings/mono/efl_mono/efl_libs.cs.in
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3namespace efl { 18namespace efl {
diff --git a/src/bindings/mono/efl_mono/efl_libs.csv.in b/src/bindings/mono/efl_mono/efl_libs.csv.in
index 3e356fe..c4b3a72 100644
--- a/src/bindings/mono/efl_mono/efl_libs.csv.in
+++ b/src/bindings/mono/efl_mono/efl_libs.csv.in
@@ -1 +1,16 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1@EFL_MONO_LIBRARY_MAP@ 16@EFL_MONO_LIBRARY_MAP@
diff --git a/src/bindings/mono/efl_mono/meson.build b/src/bindings/mono/efl_mono/meson.build
index cfe53ee..165b6d5 100644
--- a/src/bindings/mono/efl_mono/meson.build
+++ b/src/bindings/mono/efl_mono/meson.build
@@ -34,6 +34,29 @@ efl_src = configure_file(
34 configuration: efl_libs 34 configuration: efl_libs
35) 35)
36 36
37friend_assemblies = ''
38mono_friend_assemblies = get_option('mono-friend-assemblies')
39if get_option('build-tests')
40 if get_option('dotnet')
41 mono_friend_assemblies += 'efl_sharp_test_suite'
42 else
43 mono_friend_assemblies += 'efl_mono_test'
44 mono_friend_assemblies += 'efl-mono-suite'
45 endif
46endif
47
48foreach f : mono_friend_assemblies
49 friend_assemblies += '[assembly: InternalsVisibleTo("@0@")]\n'.format(f)
50endforeach
51friend_assembly_data = configuration_data()
52friend_assembly_data.set('MONO_FRIEND_ASSEMBLIES', friend_assemblies)
53
54mono_files += configure_file(
55 input: 'AssemblyInfo.cs.in',
56 output: 'AssemblyInfo.cs',
57 configuration: friend_assembly_data
58)
59
37mono_eo_files = [ 60mono_eo_files = [
38 'efl_mono_model_internal.eo', 61 'efl_mono_model_internal.eo',
39 'efl_mono_model_internal_child.eo' 62 'efl_mono_model_internal_child.eo'
@@ -60,6 +83,7 @@ endforeach
60efl_mono_lib = library('eflcustomexportsmono', 83efl_mono_lib = library('eflcustomexportsmono',
61 [ 84 [
62 join_paths('..', '..', '..', 'lib', 'efl_mono', 'efl_custom_exports_mono.c'), 85 join_paths('..', '..', '..', 'lib', 'efl_mono', 'efl_custom_exports_mono.c'),
86 join_paths('..', '..', '..', 'lib', 'efl_mono', 'efl_mono_accessors.c'),
63 join_paths('..', '..', '..', 'lib', 'efl_mono', 'efl_mono_model_internal.c'), 87 join_paths('..', '..', '..', 'lib', 'efl_mono', 'efl_mono_model_internal.c'),
64 ], 88 ],
65 pub_eo_file_target, 89 pub_eo_file_target,
diff --git a/src/bindings/mono/efl_sharp.csproj.in b/src/bindings/mono/efl_sharp.csproj.in
new file mode 100644
index 0000000..e03be33
--- /dev/null
+++ b/src/bindings/mono/efl_sharp.csproj.in
@@ -0,0 +1,48 @@
1<Project Sdk="Microsoft.NET.Sdk">
2
3 <PropertyGroup>
4 <OutputType>Library</OutputType>
5 <TargetFramework>netstandard@NETSTANDARD_VERSION@</TargetFramework>
6 </PropertyGroup>
7
8 <PropertyGroup>
9 <PackageId>Efl.Csharp</PackageId>
10 <Version>@EFL_VERSION@</Version>
11 <Authors>EFL Team</Authors>
12 <PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
13 </PropertyGroup>
14
15 <!-- <PropertyGroup Condition="'$(BuildType)'=='Beta'"> -->
16 <!-- <DefineConstants>EFL_BETA</DefineConstants> -->
17 <!-- </PropertyGroup> -->
18 <PropertyGroup>
19 <DefineConstants>@EFL_BETA@</DefineConstants>
20 </PropertyGroup>
21
22 <ItemGroup>
23 <Compile Include="@BINDING_SRC@/efl_mono/*.cs" />
24 <!-- FIXME Windows support -->
25 <Compile Include="@BINDING_SRC@/eo_mono/*.cs" Exclude="@BINDING_SRC@/eo_mono/*Windows.cs" />
26 <Compile Include="@BINDING_SRC@/eina_mono/*.cs" />
27 <Compile Include="@BINDING_SRC@/eolian_mono/*.cs" />
28 <Compile Include="@BINDING_SRC@/eldbus_mono/*.cs" />
29 </ItemGroup>
30
31 <!-- Calling `dotnet build` from a different folder seems to mess up the automatic source file discovery.
32 But we want them to be included only when building the lib itself.
33 -->
34 <ItemGroup Condition="'$(BuildingLib)'=='Yes'">
35 <Compile Include="./efl_mono/*.cs" />
36 <Compile Include="./*.cs" />
37 </ItemGroup>
38
39 <!-- Code style configuration -->
40 <ItemGroup>
41 <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.6" />
42 <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
43 </ItemGroup>
44 <PropertyGroup>
45 <CodeAnalysisRuleSet>@CA_RULESET@</CodeAnalysisRuleSet>
46 </PropertyGroup>
47
48</Project>
diff --git a/src/bindings/mono/eina_mono/eina_accessor.cs b/src/bindings/mono/eina_mono/eina_accessor.cs
index c848a2c..77c9817 100644
--- a/src/bindings/mono/eina_mono/eina_accessor.cs
+++ b/src/bindings/mono/eina_mono/eina_accessor.cs
@@ -1,8 +1,24 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1using System; 16using System;
2using System.Collections; 17using System.Collections;
3using System.Collections.Generic; 18using System.Collections.Generic;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.ComponentModel; 20using System.ComponentModel;
21using System.Diagnostics.CodeAnalysis;
6 22
7using static Eina.TraitFunctions; 23using static Eina.TraitFunctions;
8 24
@@ -13,16 +29,26 @@ namespace Eina
13 29
14internal class AccessorNativeFunctions 30internal class AccessorNativeFunctions
15{ 31{
32 [DllImport(efl.Libs.Eina)] public static extern IntPtr
33 eina_carray_length_accessor_new(IntPtr array, uint step, uint length);
16 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool 34 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] public static extern bool
17 eina_accessor_data_get(IntPtr accessor, uint position, IntPtr data); 35 eina_accessor_data_get(IntPtr accessor, uint position, out IntPtr data);
18 [DllImport(efl.Libs.Eina)] public static extern void 36 [DllImport(efl.Libs.Eina)] public static extern void
19 eina_accessor_free(IntPtr accessor); 37 eina_accessor_free(IntPtr accessor);
38 [DllImport(efl.Libs.CustomExports)] public static extern IntPtr
39 eina_mono_owned_carray_length_accessor_new(IntPtr array,
40 uint step,
41 uint length,
42 Eina.Callbacks.EinaFreeCb freeCb,
43 IntPtr handle);
20} 44}
21 45
22/// <summary>Accessors provide an uniform way of accessing Eina containers, 46/// <summary>Accessors provide an uniform way of accessing Eina containers,
23/// similar to C++ STL's and C# IEnumerable. 47/// similar to C++ STL's and C# IEnumerable.
24/// <para>Since EFL 1.23.</para> 48/// <para>Since EFL 1.23.</para>
25/// </summary> 49/// </summary>
50[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
51 Justification="This is a generalized container mapping the native one.")]
26public class Accessor<T> : IEnumerable<T>, IDisposable 52public class Accessor<T> : IEnumerable<T>, IDisposable
27{ 53{
28 /// <summary>Pointer to the native accessor.</summary> 54 /// <summary>Pointer to the native accessor.</summary>
@@ -80,6 +106,7 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
80 public void Dispose() 106 public void Dispose()
81 { 107 {
82 Dispose(true); 108 Dispose(true);
109 GC.SuppressFinalize(this);
83 } 110 }
84 111
85 /// <summary>Disposes of this wrapper, releasing the native accessor if 112 /// <summary>Disposes of this wrapper, releasing the native accessor if
@@ -134,21 +161,12 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
134 throw new ObjectDisposedException(base.GetType().Name); 161 throw new ObjectDisposedException(base.GetType().Name);
135 } 162 }
136 163
137 IntPtr tmp = MemoryNative.Alloc(Marshal.SizeOf(typeof(IntPtr))); 164 IntPtr tmp;
138 uint position = 0; 165 uint position = 0;
139 166 while (eina_accessor_data_get(Handle, position, out tmp))
140 try
141 {
142 while (eina_accessor_data_get(Handle, position, tmp))
143 {
144 IntPtr data = (IntPtr)Marshal.PtrToStructure(tmp, typeof(IntPtr));
145 yield return Convert(data);
146 position += 1;
147 }
148 }
149 finally
150 { 167 {
151 MemoryNative.Free(tmp); 168 yield return Convert(tmp); // No need to free as it is still owned by the container.
169 position += 1;
152 } 170 }
153 } 171 }
154 172
@@ -161,6 +179,8 @@ public class Accessor<T> : IEnumerable<T>, IDisposable
161/// <summary>Accessor for Inlists. 179/// <summary>Accessor for Inlists.
162/// <para>Since EFL 1.23.</para> 180/// <para>Since EFL 1.23.</para>
163/// </summary> 181/// </summary>
182[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
183 Justification="This is a generalized container mapping the native one.")]
164public class AccessorInList<T> : Accessor<T> 184public class AccessorInList<T> : Accessor<T>
165{ 185{
166 /// <summary>Create a new accessor wrapping the given pointer. 186 /// <summary>Create a new accessor wrapping the given pointer.
@@ -186,6 +206,8 @@ public class AccessorInList<T> : Accessor<T>
186/// <summary>Accessor for Inarrays. 206/// <summary>Accessor for Inarrays.
187/// <para>Since EFL 1.23.</para> 207/// <para>Since EFL 1.23.</para>
188/// </summary> 208/// </summary>
209[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
210 Justification="This is a generalized container mapping the native one.")]
189public class AccessorInArray<T> : Accessor<T> 211public class AccessorInArray<T> : Accessor<T>
190{ 212{
191 /// <summary>Create a new accessor wrapping the given pointer. 213 /// <summary>Create a new accessor wrapping the given pointer.
diff --git a/src/bindings/mono/eina_mono/eina_array.cs b/src/bindings/mono/eina_mono/eina_array.cs
index 78388a5..ba3809b 100644
--- a/src/bindings/mono/eina_mono/eina_array.cs
+++ b/src/bindings/mono/eina_mono/eina_array.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.ArrayNativeFunctions; 26using static Eina.ArrayNativeFunctions;
@@ -12,7 +29,7 @@ namespace Eina
12{ 29{
13 30
14[EditorBrowsable(EditorBrowsableState.Never)] 31[EditorBrowsable(EditorBrowsableState.Never)]
15public static class ArrayNativeFunctions 32internal static class ArrayNativeFunctions
16{ 33{
17 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 34 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
18 eina_array_new(uint step); 35 eina_array_new(uint step);
@@ -20,8 +37,9 @@ public static class ArrayNativeFunctions
20 eina_array_free(IntPtr array); 37 eina_array_free(IntPtr array);
21 [DllImport(efl.Libs.Eina)] internal static extern void 38 [DllImport(efl.Libs.Eina)] internal static extern void
22 eina_array_flush(IntPtr array); 39 eina_array_flush(IntPtr array);
40 public delegate bool KeepCb(IntPtr data, IntPtr gdata);
23 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool 41 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
24 eina_array_remove(IntPtr array, IntPtr keep, IntPtr gdata); 42 eina_array_remove(IntPtr array, KeepCb keep, IntPtr gdata);
25 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool 43 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
26 eina_array_push(IntPtr array, IntPtr data); 44 eina_array_push(IntPtr array, IntPtr data);
27 45
@@ -29,6 +47,10 @@ public static class ArrayNativeFunctions
29 eina_array_iterator_new(IntPtr array); 47 eina_array_iterator_new(IntPtr array);
30 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 48 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
31 eina_array_accessor_new(IntPtr array); 49 eina_array_accessor_new(IntPtr array);
50 [DllImport(efl.Libs.Eina)] [return: MarshalAs(UnmanagedType.U1)]
51 internal static extern bool
52 eina_array_find(IntPtr array, IntPtr data,
53 uint out_idx);
32 54
33 [DllImport(efl.Libs.CustomExports)] internal static extern void 55 [DllImport(efl.Libs.CustomExports)] internal static extern void
34 eina_array_clean_custom_export_mono(IntPtr array); 56 eina_array_clean_custom_export_mono(IntPtr array);
@@ -45,35 +67,51 @@ public static class ArrayNativeFunctions
45 67
46 [DllImport(efl.Libs.CustomExports)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool 68 [DllImport(efl.Libs.CustomExports)] [return: MarshalAs(UnmanagedType.U1)] internal static extern bool
47 eina_array_foreach_custom_export_mono(IntPtr array, IntPtr cb, IntPtr fdata); 69 eina_array_foreach_custom_export_mono(IntPtr array, IntPtr cb, IntPtr fdata);
70 [DllImport(efl.Libs.CustomExports)] internal static extern void
71 eina_array_insert_at_custom_export_mono(IntPtr array, uint index, IntPtr data);
48} 72}
49 73
50/// <summary>A container of contiguous allocated elements. 74/// <summary>A container of contiguous allocated elements.
51/// <para>Since EFL 1.23.</para> 75/// <para>Since EFL 1.23.</para>
52/// </summary> 76/// </summary>
53public class Array<T> : IEnumerable<T>, IDisposable 77[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
78 Justification="This is a generalized container mapping the native one.")]
79public class Array<T> : IList<T>, IEnumerable<T>, IDisposable
54{ 80{
55 public const uint DefaultStep = 32; 81 public const uint DefaultStep = 32;
56 82
57 /// <summary>Pointer to the native buffer.</summary> 83 /// <summary>Pointer to the native buffer.</summary>
58 [EditorBrowsable(EditorBrowsableState.Never)] 84 [EditorBrowsable(EditorBrowsableState.Never)]
59 public IntPtr Handle {get;set;} = IntPtr.Zero; 85 public IntPtr Handle { get; set; } = IntPtr.Zero;
86
60 /// <summary>Whether this wrapper owns the native buffer. 87 /// <summary>Whether this wrapper owns the native buffer.
61 /// <para>Since EFL 1.23.</para> 88 /// <para>Since EFL 1.23.</para>
62 /// </summary> 89 /// </summary>
63 public bool Own {get;set;} 90 internal bool Own { get; set; }
91
64 /// <summary>Who is in charge of releasing the resources wrapped by 92 /// <summary>Who is in charge of releasing the resources wrapped by
65 /// this instance. 93 /// this instance.
66 /// <para>Since EFL 1.23.</para> 94 /// <para>Since EFL 1.23.</para>
67 /// </summary> 95 /// </summary>
68 public bool OwnContent {get;set;} 96 internal bool OwnContent { get; set; }
69 /// <summary> Length of the array. 97
70 /// <para>Since EFL 1.23.</para> 98 /// <summary> Gets the number of elements contained in the <see cref="Array{T}" />.
99 /// <para>Since EFL 1.24.</para>
71 /// </summary> 100 /// </summary>
72 public int Length 101 public int Count
73 { 102 {
74 get { return Count(); } 103 get => (int)eina_array_count_custom_export_mono(Handle);
75 } 104 }
76 105
106 /// <summary>
107 /// Gets a value indicating whether the <see cref="Array" /> is read-only.
108 /// <para>Since EFL 1.24.</para>
109 ///<para>
110 /// It's the negative of <see cref="OwnContent" />.
111 ///</para>
112 /// </summary>
113 public bool IsReadOnly { get => !OwnContent; }
114
77 private void InitNew(uint step) 115 private void InitNew(uint step)
78 { 116 {
79 Handle = eina_array_new(step); 117 Handle = eina_array_new(step);
@@ -86,23 +124,62 @@ public class Array<T> : IEnumerable<T>, IDisposable
86 } 124 }
87 125
88 internal bool InternalPush(IntPtr ele) 126 internal bool InternalPush(IntPtr ele)
127 => eina_array_push_custom_export_mono(Handle, ele);
128
129 internal IntPtr InternalPop()
130 => eina_array_pop_custom_export_mono(Handle);
131
132 internal IntPtr InternalDataGet(int idx)
133 => eina_array_data_get_custom_export_mono(Handle, CheckBounds(idx));
134
135 internal void InternalDataSet(int idx, IntPtr ele)
136 => eina_array_data_set_custom_export_mono(Handle, CheckBounds(idx), ele);
137
138 private uint CheckBounds(int idx)
89 { 139 {
90 return eina_array_push_custom_export_mono(Handle, ele); 140 if (!(0 <= idx && idx < Count))
141 {
142 throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} is out of bounds.");
143 }
144
145 return (uint)idx;
91 } 146 }
92 147
93 internal IntPtr InternalPop() 148 private U LoopingThrough<U>(T val, Func<int, U> f1, Func<U> f2)
94 { 149 {
95 return eina_array_pop_custom_export_mono(Handle); 150 for (int i = 0, count = Count; i < count; ++i)
151 {
152 if (NativeToManaged<T>(InternalDataGet(i)).Equals(val))
153 {
154 return f1(i);
155 }
156 }
157
158 return f2();
96 } 159 }
97 160
98 internal IntPtr InternalDataGet(int idx) 161 private void CheckOwnerships()
99 { 162 {
100 return eina_array_data_get_custom_export_mono(Handle, (uint)idx); // TODO: Check bounds ??? 163 if ((Own == false) && (OwnContent == true))
164 {
165 throw new InvalidOperationException(nameof(Own) + "/" + nameof(OwnContent));
166 }
101 } 167 }
102 168
103 internal void InternalDataSet(int idx, IntPtr ele) 169 private void RequireWritable()
170 {
171 if (IsReadOnly)
172 {
173 throw new NotSupportedException("This object's instance is read only.");
174 }
175 }
176
177 private void DeleteData(IntPtr ele)
104 { 178 {
105 eina_array_data_set_custom_export_mono(Handle, (uint)idx, ele); // TODO: Check bounds ??? 179 if (OwnContent)
180 {
181 NativeFree<T>(ele);
182 }
106 } 183 }
107 184
108 /// <summary> 185 /// <summary>
@@ -132,14 +209,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
132 [EditorBrowsable(EditorBrowsableState.Never)] 209 [EditorBrowsable(EditorBrowsableState.Never)]
133 public Array(IntPtr handle, bool own) 210 public Array(IntPtr handle, bool own)
134 { 211 {
135 if (handle == IntPtr.Zero) 212 Handle = (handle != IntPtr.Zero)
136 { 213 ? handle
137 throw new ArgumentNullException("Handle can't be null"); 214 : throw new ArgumentNullException(nameof(handle),
138 } 215 $"{nameof(Handle)} can't be null");
139
140 Handle = handle;
141 Own = own; 216 Own = own;
142 OwnContent = own; 217 OwnContent = own;
218 CheckOwnerships();
143 } 219 }
144 220
145 /// <summary> 221 /// <summary>
@@ -151,14 +227,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
151 [EditorBrowsable(EditorBrowsableState.Never)] 227 [EditorBrowsable(EditorBrowsableState.Never)]
152 public Array(IntPtr handle, bool own, bool ownContent) 228 public Array(IntPtr handle, bool own, bool ownContent)
153 { 229 {
154 if (handle == IntPtr.Zero) 230 Handle = (handle != IntPtr.Zero)
155 { 231 ? handle
156 throw new ArgumentNullException("Handle can't be null"); 232 : throw new ArgumentNullException(nameof(handle),
157 } 233 $"{nameof(Handle)} can't be null");
158
159 Handle = handle;
160 Own = own; 234 Own = own;
161 OwnContent = ownContent; 235 OwnContent = ownContent;
236 CheckOwnerships();
162 } 237 }
163 238
164 /// <summary> 239 /// <summary>
@@ -183,15 +258,17 @@ public class Array<T> : IEnumerable<T>, IDisposable
183 return; 258 return;
184 } 259 }
185 260
186 if (Own && OwnContent) 261 for (int len = (int)eina_array_count_custom_export_mono(h),
262 i = 0; i < len; ++i)
187 { 263 {
188 int len = (int)eina_array_count_custom_export_mono(h); 264 if (!OwnContent)
189 for (int i = 0; i < len; ++i)
190 { 265 {
191 NativeFree<T>(eina_array_data_get_custom_export_mono(h, (uint)i)); 266 break;
192 } 267 }
193 }
194 268
269 DeleteData(eina_array_data_get_custom_export_mono(h, (uint)i));
270 }
271
195 if (Own) 272 if (Own)
196 { 273 {
197 if (disposing) 274 if (disposing)
@@ -222,27 +299,16 @@ public class Array<T> : IEnumerable<T>, IDisposable
222 Dispose(); 299 Dispose();
223 } 300 }
224 301
225 /// <summary>
226 /// Releases the native array.
227 /// <para>Since EFL 1.23.</para>
228 /// </summary>
229 /// <returns>The native array.</returns>
230 public IntPtr Release()
231 {
232 IntPtr h = Handle;
233 Handle = IntPtr.Zero;
234 return h;
235 }
236
237 private void FreeElementsIfOwned() 302 private void FreeElementsIfOwned()
238 { 303 {
239 if (OwnContent) 304 if (IsReadOnly)
240 { 305 {
241 int len = Length; 306 throw new NotSupportedException("This object's instance is read only.");
242 for (int i = 0; i < len; ++i) 307 }
243 { 308
244 NativeFree<T>(InternalDataGet(i)); 309 for (int i = 0, count = Count; i < count; ++i)
245 } 310 {
311 DeleteData(InternalDataGet(i));
246 } 312 }
247 } 313 }
248 314
@@ -265,26 +331,18 @@ public class Array<T> : IEnumerable<T>, IDisposable
265 eina_array_flush(Handle); 331 eina_array_flush(Handle);
266 } 332 }
267 333
268 /// <summary> 334 internal void SetOwnership(bool ownAll)
269 /// Returns the number of elements in an array.
270 /// <para>Since EFL 1.23.</para>
271 /// </summary>
272 /// <returns>The number of elements.</returns>
273 public int Count()
274 {
275 return (int)eina_array_count_custom_export_mono(Handle);
276 }
277
278 public void SetOwnership(bool ownAll)
279 { 335 {
280 Own = ownAll; 336 Own = ownAll;
281 OwnContent = ownAll; 337 OwnContent = ownAll;
338 CheckOwnerships();
282 } 339 }
283 340
284 public void SetOwnership(bool own, bool ownContent) 341 internal void SetOwnership(bool own, bool ownContent)
285 { 342 {
286 Own = own; 343 Own = own;
287 OwnContent = ownContent; 344 OwnContent = ownContent;
345 CheckOwnerships();
288 } 346 }
289 347
290 /// <summary> 348 /// <summary>
@@ -294,6 +352,8 @@ public class Array<T> : IEnumerable<T>, IDisposable
294 /// <param name="val">The value of the element to be inserted.</param> 352 /// <param name="val">The value of the element to be inserted.</param>
295 public bool Push(T val) 353 public bool Push(T val)
296 { 354 {
355 RequireWritable();
356
297 IntPtr ele = ManagedToNativeAlloc(val); 357 IntPtr ele = ManagedToNativeAlloc(val);
298 var r = InternalPush(ele); 358 var r = InternalPush(ele);
299 if (!r) 359 if (!r)
@@ -320,11 +380,13 @@ public class Array<T> : IEnumerable<T>, IDisposable
320 /// <returns>The element at the end position.</returns> 380 /// <returns>The element at the end position.</returns>
321 public T Pop() 381 public T Pop()
322 { 382 {
383 RequireWritable();
384
323 IntPtr ele = InternalPop(); 385 IntPtr ele = InternalPop();
324 var r = NativeToManaged<T>(ele); 386 var r = NativeToManaged<T>(ele);
325 if (OwnContent && ele != IntPtr.Zero) 387 if (ele != IntPtr.Zero)
326 { 388 {
327 NativeFree<T>(ele); 389 DeleteData(ele);
328 } 390 }
329 391
330 return r; 392 return r;
@@ -337,10 +399,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
337 /// <param name="idx">The position of the desired element.</param> 399 /// <param name="idx">The position of the desired element.</param>
338 /// <returns>The element at the specified position</returns> 400 /// <returns>The element at the specified position</returns>
339 public T DataGet(int idx) 401 public T DataGet(int idx)
340 { 402 => NativeToManaged<T>(InternalDataGet(idx));
341 IntPtr ele = InternalDataGet(idx);
342 return NativeToManaged<T>(ele);
343 }
344 403
345 /// <summary> 404 /// <summary>
346 /// Returns the element of the array at the specified position. 405 /// Returns the element of the array at the specified position.
@@ -349,9 +408,8 @@ public class Array<T> : IEnumerable<T>, IDisposable
349 /// <param name="idx">The position of the desired element.</param> 408 /// <param name="idx">The position of the desired element.</param>
350 /// <returns>The element at the specified position</returns> 409 /// <returns>The element at the specified position</returns>
351 public T At(int idx) 410 public T At(int idx)
352 { 411 => DataGet(idx);
353 return DataGet(idx); 412
354 }
355 413
356 /// <summary> 414 /// <summary>
357 /// Replaces the element at the specified position. 415 /// Replaces the element at the specified position.
@@ -359,16 +417,17 @@ public class Array<T> : IEnumerable<T>, IDisposable
359 /// </summary> 417 /// </summary>
360 /// <param name="idx">The position of the desired element.</param> 418 /// <param name="idx">The position of the desired element.</param>
361 /// <param name="val">The value of the element to be inserted.</param> 419 /// <param name="val">The value of the element to be inserted.</param>
362 public void DataSet(int idx, T val) 420 internal void DataSet(int idx, T val)
363 { 421 {
364 IntPtr ele = InternalDataGet(idx); // TODO: check bondaries ?? 422 RequireWritable();
365 if (OwnContent && ele != IntPtr.Zero) 423
424 IntPtr ele = InternalDataGet(idx);
425 if (ele != IntPtr.Zero)
366 { 426 {
367 NativeFree<T>(ele); 427 DeleteData(ele);
368 } 428 }
369 429
370 ele = ManagedToNativeAlloc(val); 430 InternalDataSet(idx, ManagedToNativeAlloc(val));
371 InternalDataSet(idx, ele);
372 } 431 }
373 432
374 /// <summary> 433 /// <summary>
@@ -394,7 +453,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
394 /// <returns>A array</returns> 453 /// <returns>A array</returns>
395 public T[] ToArray() 454 public T[] ToArray()
396 { 455 {
397 int len = Length; 456 int len = Count;
398 var managed = new T[len]; 457 var managed = new T[len];
399 for (int i = 0; i < len; ++i) 458 for (int i = 0; i < len; ++i)
400 { 459 {
@@ -410,6 +469,7 @@ public class Array<T> : IEnumerable<T>, IDisposable
410 /// </summary> 469 /// </summary>
411 public bool Append(T[] values) 470 public bool Append(T[] values)
412 { 471 {
472 Contract.Requires(values != null, nameof(values));
413 foreach (T v in values) 473 foreach (T v in values)
414 { 474 {
415 if (!Push(v)) 475 if (!Push(v))
@@ -426,17 +486,14 @@ public class Array<T> : IEnumerable<T>, IDisposable
426 /// <para>Since EFL 1.23.</para> 486 /// <para>Since EFL 1.23.</para>
427 /// </summary> 487 /// </summary>
428 public Eina.Iterator<T> GetIterator() 488 public Eina.Iterator<T> GetIterator()
429 { 489 => new Eina.Iterator<T>(eina_array_iterator_new(Handle), true);
430 return new Eina.Iterator<T>(eina_array_iterator_new(Handle), true);
431 }
432 490
433 /// <summary> Gets an Enumerator for this Array. 491 /// <summary> Gets an Enumerator for this Array.
434 /// <para>Since EFL 1.23.</para> 492 /// <para>Since EFL 1.23.</para>
435 /// </summary> 493 /// </summary>
436 public IEnumerator<T> GetEnumerator() 494 public IEnumerator<T> GetEnumerator()
437 { 495 {
438 int len = Length; 496 for (int i = 0, count = Count; i < count; ++i)
439 for (int i = 0; i < len; ++i)
440 { 497 {
441 yield return DataGet(i); 498 yield return DataGet(i);
442 } 499 }
@@ -446,16 +503,113 @@ public class Array<T> : IEnumerable<T>, IDisposable
446 /// <para>Since EFL 1.23.</para> 503 /// <para>Since EFL 1.23.</para>
447 /// </summary> 504 /// </summary>
448 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 505 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
449 { 506 => this.GetEnumerator();
450 return this.GetEnumerator();
451 }
452 507
453 /// <summary> Gets an Accessor for this Array. 508 /// <summary> Gets an Accessor for this Array.
454 /// <para>Since EFL 1.23.</para> 509 /// <para>Since EFL 1.23.</para>
455 /// </summary> 510 /// </summary>
456 public Eina.Accessor<T> GetAccessor() 511 public Eina.Accessor<T> GetAccessor()
512 => new Eina.Accessor<T>(eina_array_accessor_new(Handle), Ownership.Managed);
513
514 /// <summary>
515 /// Removes the first occurrence of a specific object.
516 /// <para>Since EFL 1.24.</para>
517 /// </summary>
518 /// <param name="val">The object to remove.</param>
519 public bool Remove(T val)
520 => LoopingThrough(val,
521 (i) =>
522 {
523 RemoveAt(i);
524 return true;
525 }, () => false);
526
527 /// <summary>
528 /// Adds an item.
529 /// <para>Since EFL 1.24.</para>
530 /// </summary>
531 /// <param name="val">The object to add.</param>
532 public void Add(T val) => Push(val);
533
534 /// <summary>
535 /// Removes all items.
536 /// <para>Since EFL 1.24.</para>
537 /// </summary>
538 public void Clear() => Clean();
539
540 /// <summary>
541 /// Determines whether the <see cref="Array{T}" /> contains a specific value.
542 /// <para>Since EFL 1.24.</para>
543 /// </summary>
544 /// <param name="val">The object to locate.</param>
545 public bool Contains(T val)
546 => LoopingThrough(val, (i) => true, () => false);
547
548 /// <summary>
549 /// Copies the elements of the <see cref="Array{T}" /> to an
550 /// <see cref="Array" />, starting at a particular <see cref="Array" /> index.
551 /// <para>Since EFL 1.24.</para>
552 /// </summary>
553 /// <param name="array">The one-dimensional <see cref="Array" /> that is the
554 /// destination of the elements copied from <see cref="Array{T}" />.
555 /// The <see cref="Array" /> must have zero-based indexing.</param>
556 /// <param name="arrayIndex">The zero-based index in array at which copying
557 /// begins.</param>
558 public void CopyTo(T[] array, int arrayIndex)
559 => ToArray().CopyTo(array, arrayIndex);
560
561 /// <summary>
562 /// Determines the index of a specific item.
563 /// <para>Since EFL 1.24.</para>
564 /// </summary>
565 /// <param name="val">The object to locate.</param>
566 public int IndexOf(T val)
567 => LoopingThrough(val, (i) => i, () => -1);
568
569 /// <summary>
570 /// Inserts an item to the <see cref="Array{T}" /> at the specified index.
571 /// <para>Since EFL 1.24.</para>
572 /// </summary>
573 /// <param name="index">The zero-based index at which item should be inserted.</param>
574 /// <param name="val">The object to insert.</param>
575 public void Insert(int index, T val)
576 {
577 RequireWritable();
578
579 if (index < 0)
580 {
581 throw new ArgumentOutOfRangeException(nameof(index), $"{nameof(index)} cannot be negative.");
582 }
583
584 if (Count < index)
585 {
586 throw new ArgumentOutOfRangeException(nameof(index), $"{nameof(index)} is greater than {nameof(Count)} + 1.");
587 }
588
589 if (index == Count)
590 {
591 Push(val);
592 return;
593 }
594
595 eina_array_insert_at_custom_export_mono(Handle, (uint)index,
596 ManagedToNativeAlloc(val));
597 }
598
599 /// <summary>
600 /// Removes the <see cref="Array{T}" /> item at the specified index.
601 /// <para>Since EFL 1.24.</para>
602 /// </summary>
603 /// <param name="index">The zero-based index of the item to remove.</param>
604 public void RemoveAt(int index)
457 { 605 {
458 return new Eina.Accessor<T>(eina_array_accessor_new(Handle), Ownership.Managed); 606 RequireWritable();
607
608 var ele = InternalDataGet(index);
609 DeleteData(ele);
610 eina_array_remove(Handle, (data,gdata)
611 => ele != data,
612 IntPtr.Zero);
459 } 613 }
460} 614}
461 615
diff --git a/src/bindings/mono/eina_mono/eina_binbuf.cs b/src/bindings/mono/eina_mono/eina_binbuf.cs
index 0e9824c..6cc79f9 100644
--- a/src/bindings/mono/eina_mono/eina_binbuf.cs
+++ b/src/bindings/mono/eina_mono/eina_binbuf.cs
@@ -1,8 +1,24 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.ComponentModel; 20using System.ComponentModel;
21using System.Diagnostics.Contracts;
6 22
7namespace Eina 23namespace Eina
8{ 24{
@@ -199,6 +215,7 @@ public class Binbuf : IDisposable
199 /// <returns>true on success, false if data could not be appended.</returns> 215 /// <returns>true on success, false if data could not be appended.</returns>
200 public bool Append(byte[] str) 216 public bool Append(byte[] str)
201 { 217 {
218 Contract.Requires(str != null, nameof(str));
202 return 0 != eina_binbuf_append_length(Handle, str, (UIntPtr)(str.Length)); 219 return 0 != eina_binbuf_append_length(Handle, str, (UIntPtr)(str.Length));
203 } 220 }
204 221
@@ -223,6 +240,7 @@ public class Binbuf : IDisposable
223 /// <returns>true on success, false if data could not be appended.</returns> 240 /// <returns>true on success, false if data could not be appended.</returns>
224 public bool Append(Binbuf bb) 241 public bool Append(Binbuf bb)
225 { 242 {
243 Contract.Requires(bb != null, nameof(bb));
226 return 0 != eina_binbuf_append_buffer(Handle, bb.Handle); 244 return 0 != eina_binbuf_append_buffer(Handle, bb.Handle);
227 } 245 }
228 246
@@ -258,6 +276,7 @@ public class Binbuf : IDisposable
258 /// <returns>true on success, false if data could not be appended.</returns> 276 /// <returns>true on success, false if data could not be appended.</returns>
259 public bool Insert(byte[] str, uint pos) 277 public bool Insert(byte[] str, uint pos)
260 { 278 {
279 Contract.Requires(str != null, nameof(str));
261 return 0 != eina_binbuf_insert_length(Handle, str, (UIntPtr)(str.Length), (UIntPtr)pos); 280 return 0 != eina_binbuf_insert_length(Handle, str, (UIntPtr)(str.Length), (UIntPtr)pos);
262 } 281 }
263 282
diff --git a/src/bindings/mono/eina_mono/eina_common.cs b/src/bindings/mono/eina_mono/eina_common.cs
index badd62e..a4f2ff4 100644
--- a/src/bindings/mono/eina_mono/eina_common.cs
+++ b/src/bindings/mono/eina_mono/eina_common.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -16,7 +31,7 @@ internal delegate void EinaFreeCb(IntPtr data);
16 31
17} 32}
18 33
19internal static class NativeCustomExportFunctions 34internal static partial class NativeCustomExportFunctions
20{ 35{
21 [DllImport(efl.Libs.CustomExports)] public static extern void 36 [DllImport(efl.Libs.CustomExports)] public static extern void
22 efl_mono_native_free(IntPtr ptr); 37 efl_mono_native_free(IntPtr ptr);
@@ -190,10 +205,10 @@ public static class StringConversion
190 Marshal.WriteByte(native + strbuf.Length, 0); // write the terminating null 205 Marshal.WriteByte(native + strbuf.Length, 0); // write the terminating null
191 return native; 206 return native;
192 } 207 }
193 catch(Exception e) 208 catch (Exception)
194 { 209 {
195 MemoryNative.Free(native); 210 MemoryNative.Free(native);
196 throw e; 211 throw;
197 } 212 }
198 } 213 }
199 214
diff --git a/src/bindings/mono/eina_mono/eina_config.cs b/src/bindings/mono/eina_mono/eina_config.cs
index e9efea3..d1f536e 100644
--- a/src/bindings/mono/eina_mono/eina_config.cs
+++ b/src/bindings/mono/eina_mono/eina_config.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
diff --git a/src/bindings/mono/eina_mono/eina_container_common.cs b/src/bindings/mono/eina_mono/eina_container_common.cs
index 03a6875..a07153e 100644
--- a/src/bindings/mono/eina_mono/eina_container_common.cs
+++ b/src/bindings/mono/eina_mono/eina_container_common.cs
@@ -1,3 +1,18 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
@@ -6,6 +21,7 @@ using System.Runtime.InteropServices;
6using System.Collections.Generic; 21using System.Collections.Generic;
7using System.Reflection; 22using System.Reflection;
8using System.ComponentModel; 23using System.ComponentModel;
24using System.Globalization;
9 25
10using Eina.Callbacks; 26using Eina.Callbacks;
11using static Eina.HashNativeFunctions; 27using static Eina.HashNativeFunctions;
@@ -17,7 +33,7 @@ namespace Eina
17{ 33{
18 34
19[EditorBrowsable(EditorBrowsableState.Never)] 35[EditorBrowsable(EditorBrowsableState.Never)]
20public enum ElementType 36internal enum ElementType
21{ 37{
22 NumericType, 38 NumericType,
23 StringType, 39 StringType,
@@ -27,23 +43,115 @@ public enum ElementType
27 43
28[EditorBrowsable(EditorBrowsableState.Never)] 44[EditorBrowsable(EditorBrowsableState.Never)]
29[StructLayout(LayoutKind.Sequential)] 45[StructLayout(LayoutKind.Sequential)]
30public struct InlistMem 46internal struct InlistMem : IEquatable<InlistMem>
31{ 47{
32 public IntPtr next {get;set;} 48 public IntPtr next {get;set;}
33 public IntPtr prev {get;set;} 49 public IntPtr prev {get;set;}
34 public IntPtr last {get;set;} 50 public IntPtr last {get;set;}
51
52 /// <summary>
53 /// Gets a hash for <see cref="InlistMem" />.
54 /// <para>Since EFL 1.24.</para>
55 /// </summary>
56 /// <returns>A hash code.</returns>
57 public override int GetHashCode()
58 => next.GetHashCode() ^ prev.GetHashCode() ^ last.GetHashCode();
59
60 /// <summary>Returns whether this <see cref="InlistMem" />
61 /// is equal to the given <see cref="object" />.
62 /// <para>Since EFL 1.24.</para>
63 /// </summary>
64 /// <param name="other">The <see cref="object" /> to be compared to.</param>
65 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
66 public override bool Equals(object other)
67 => (!(other is InlistMem)) ? false : Equals((InlistMem)other);
68
69 /// <summary>Returns whether this <see cref="InlistMem" /> is equal
70 /// to the given <see cref="InlistMem" />.
71 /// <para>Since EFL 1.24.</para>
72 /// </summary>
73 /// <param name="other">The <see cref="InlistMem" /> to be compared to.</param>
74 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
75 public bool Equals(InlistMem other)
76 => (next == other.next) && (prev == other.prev)
77 && (last == other.last);
78
79 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
80 /// <para>Since EFL 1.24.</para>
81 /// </summary>
82 /// <param name="lhs">The left hand side of the operator.</param>
83 /// <param name="rhs">The right hand side of the operator.</param>
84 /// <returns><c>true</c> if <c>lhs</c> is equal
85 /// to <c>rhs</c>.</returns>
86 public static bool operator==(InlistMem lhs, InlistMem rhs)
87 => lhs.Equals(rhs);
88
89 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
90 /// <para>Since EFL 1.24.</para>
91 /// </summary>
92 /// <param name="lhs">The left hand side of the operator.</param>
93 /// <param name="rhs">The right hand side of the operator.</param>
94 /// <returns><c>true</c> if <c>lhs</c> is not equal
95 /// to <c>rhs</c>.</returns>
96 public static bool operator!=(InlistMem lhs, InlistMem rhs) => !(lhs == rhs);
35} 97}
36 98
37[EditorBrowsable(EditorBrowsableState.Never)] 99[EditorBrowsable(EditorBrowsableState.Never)]
38[StructLayout(LayoutKind.Sequential)] 100[StructLayout(LayoutKind.Sequential)]
39public struct InlistNode<T> 101internal struct InlistNode<T> : IEquatable<InlistNode<T>>
40{ 102{
41 public InlistMem __in_list {get;set;} 103 public InlistMem __in_list {get;set;}
42 public T Val {get;set;} 104 public T Val {get;set;}
105
106 /// <summary>
107 /// Gets a hash for <see cref="InlistNode{T}" />.
108 /// <para>Since EFL 1.24.</para>
109 /// </summary>
110 /// <returns>A hash code.</returns>
111 public override int GetHashCode()
112 => __in_list.GetHashCode() ^ Val.GetHashCode();
113
114 /// <summary>Returns whether this <see cref="InlistNode{T}" />
115 /// is equal to the given <see cref="object" />.
116 /// <para>Since EFL 1.24.</para>
117 /// </summary>
118 /// <param name="other">The <see cref="object" /> to be compared to.</param>
119 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
120 public override bool Equals(object other)
121 => (!(other is InlistNode<T>)) ? false : Equals((InlistNode<T>)other);
122
123 /// <summary>Returns whether this <see cref="InlistNode{T}" /> is equal
124 /// to the given <see cref="InlistNode{T}" />.
125 /// <para>Since EFL 1.24.</para>
126 /// </summary>
127 /// <param name="other">The <see cref="InlistNode{T}" /> to be compared to.</param>
128 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
129 public bool Equals(InlistNode<T> other)
130 => (__in_list == other.__in_list) && (Val.Equals(other.Val));
131
132 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
133 /// <para>Since EFL 1.24.</para>
134 /// </summary>
135 /// <param name="lhs">The left hand side of the operator.</param>
136 /// <param name="rhs">The right hand side of the operator.</param>
137 /// <returns><c>true</c> if <c>lhs</c> is equal
138 /// to <c>rhs</c>.</returns>
139 public static bool operator==(InlistNode<T> lhs, InlistNode<T> rhs)
140 => lhs.Equals(rhs);
141
142 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
143 /// <para>Since EFL 1.24.</para>
144 /// </summary>
145 /// <param name="lhs">The left hand side of the operator.</param>
146 /// <param name="rhs">The right hand side of the operator.</param>
147 /// <returns><c>true</c> if <c>lhs</c> is not equal
148 /// to <c>rhs</c>.</returns>
149 public static bool operator!=(InlistNode<T> lhs, InlistNode<T> rhs)
150 => !(lhs == rhs);
43} 151}
44 152
45[EditorBrowsable(EditorBrowsableState.Never)] 153[EditorBrowsable(EditorBrowsableState.Never)]
46public interface IBaseElementTraits<T> 154internal interface IBaseElementTraits<T>
47{ 155{
48 IntPtr ManagedToNativeAlloc(T man); 156 IntPtr ManagedToNativeAlloc(T man);
49 IntPtr ManagedToNativeAllocInlistNode(T man); 157 IntPtr ManagedToNativeAllocInlistNode(T man);
@@ -64,7 +172,7 @@ public interface IBaseElementTraits<T>
64} 172}
65 173
66[EditorBrowsable(EditorBrowsableState.Never)] 174[EditorBrowsable(EditorBrowsableState.Never)]
67public class StringElementTraits : IBaseElementTraits<string> 175internal class StringElementTraits : IBaseElementTraits<string>
68{ 176{
69 public StringElementTraits() 177 public StringElementTraits()
70 { 178 {
@@ -203,7 +311,7 @@ public class StringElementTraits : IBaseElementTraits<string>
203} 311}
204 312
205[EditorBrowsable(EditorBrowsableState.Never)] 313[EditorBrowsable(EditorBrowsableState.Never)]
206public class StringshareElementTraits : IBaseElementTraits<Eina.Stringshare> 314internal class StringshareElementTraits : IBaseElementTraits<Eina.Stringshare>
207{ 315{
208 public StringshareElementTraits() 316 public StringshareElementTraits()
209 { 317 {
@@ -343,7 +451,7 @@ public class StringshareElementTraits : IBaseElementTraits<Eina.Stringshare>
343} 451}
344 452
345[EditorBrowsable(EditorBrowsableState.Never)] 453[EditorBrowsable(EditorBrowsableState.Never)]
346public class EflObjectElementTraits<T> : IBaseElementTraits<T> 454internal class EflObjectElementTraits<T> : IBaseElementTraits<T>
347{ 455{
348 public IntPtr ManagedToNativeAlloc(T man) 456 public IntPtr ManagedToNativeAlloc(T man)
349 { 457 {
@@ -501,7 +609,7 @@ public class EflObjectElementTraits<T> : IBaseElementTraits<T>
501} 609}
502 610
503[EditorBrowsable(EditorBrowsableState.Never)] 611[EditorBrowsable(EditorBrowsableState.Never)]
504public abstract class PrimitiveElementTraits<T> 612internal abstract class PrimitiveElementTraits<T>
505{ 613{
506 private Eina.Callbacks.EinaCompareCb dlgt = null; 614 private Eina.Callbacks.EinaCompareCb dlgt = null;
507 615
@@ -603,7 +711,7 @@ public abstract class PrimitiveElementTraits<T>
603} 711}
604 712
605[EditorBrowsable(EditorBrowsableState.Never)] 713[EditorBrowsable(EditorBrowsableState.Never)]
606abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T> 714internal abstract class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T>
607{ 715{
608 private static IBaseElementTraits<Int32> int32Traits = null; 716 private static IBaseElementTraits<Int32> int32Traits = null;
609 717
@@ -627,7 +735,7 @@ abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, I
627 735
628 public IntPtr ManagedToNativeAllocRef(T man, bool refs) 736 public IntPtr ManagedToNativeAllocRef(T man, bool refs)
629 { 737 {
630 return int32Traits.ManagedToNativeAlloc(Convert.ToInt32((object)man)); 738 return int32Traits.ManagedToNativeAlloc(Convert.ToInt32((object)man, CultureInfo.CurrentCulture));
631 } 739 }
632 740
633 public void NativeFreeRef(IntPtr nat, bool unrefs) 741 public void NativeFreeRef(IntPtr nat, bool unrefs)
@@ -642,7 +750,7 @@ abstract public class Primitive32ElementTraits<T> : PrimitiveElementTraits<T>, I
642} 750}
643 751
644[EditorBrowsable(EditorBrowsableState.Never)] 752[EditorBrowsable(EditorBrowsableState.Never)]
645abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T> 753internal abstract class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, IBaseElementTraits<T>
646{ 754{
647 private static IBaseElementTraits<Int64> int64Traits = null; 755 private static IBaseElementTraits<Int64> int64Traits = null;
648 756
@@ -666,7 +774,7 @@ abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, I
666 774
667 public IntPtr ManagedToNativeAllocRef(T man, bool refs) 775 public IntPtr ManagedToNativeAllocRef(T man, bool refs)
668 { 776 {
669 return int64Traits.ManagedToNativeAlloc(Convert.ToInt64((object)man)); 777 return int64Traits.ManagedToNativeAlloc(Convert.ToInt64((object)man, CultureInfo.CurrentCulture));
670 } 778 }
671 779
672 public void NativeFreeRef(IntPtr nat, bool unrefs) 780 public void NativeFreeRef(IntPtr nat, bool unrefs)
@@ -681,7 +789,7 @@ abstract public class Primitive64ElementTraits<T> : PrimitiveElementTraits<T>, I
681} 789}
682 790
683[EditorBrowsable(EditorBrowsableState.Never)] 791[EditorBrowsable(EditorBrowsableState.Never)]
684public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTraits<int> 792internal class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTraits<int>
685{ 793{
686 override public void ManagedToNativeCopyTo(int man, IntPtr mem) 794 override public void ManagedToNativeCopyTo(int man, IntPtr mem)
687 { 795 {
@@ -706,7 +814,7 @@ public class IntElementTraits : Primitive32ElementTraits<int>, IBaseElementTrait
706} 814}
707 815
708[EditorBrowsable(EditorBrowsableState.Never)] 816[EditorBrowsable(EditorBrowsableState.Never)]
709public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTraits<char> 817internal class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTraits<char>
710{ 818{
711 override public void ManagedToNativeCopyTo(char man, IntPtr mem) 819 override public void ManagedToNativeCopyTo(char man, IntPtr mem)
712 { 820 {
@@ -731,7 +839,7 @@ public class CharElementTraits : Primitive32ElementTraits<char>, IBaseElementTra
731} 839}
732 840
733[EditorBrowsable(EditorBrowsableState.Never)] 841[EditorBrowsable(EditorBrowsableState.Never)]
734public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long> 842internal class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTraits<long>
735{ 843{
736 override public void ManagedToNativeCopyTo(long man, IntPtr mem) 844 override public void ManagedToNativeCopyTo(long man, IntPtr mem)
737 { 845 {
@@ -756,7 +864,7 @@ public class LongElementTraits : Primitive64ElementTraits<long>, IBaseElementTra
756} 864}
757 865
758[EditorBrowsable(EditorBrowsableState.Never)] 866[EditorBrowsable(EditorBrowsableState.Never)]
759public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementTraits<short> 867internal class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementTraits<short>
760{ 868{
761 override public void ManagedToNativeCopyTo(short man, IntPtr mem) 869 override public void ManagedToNativeCopyTo(short man, IntPtr mem)
762 { 870 {
@@ -781,7 +889,7 @@ public class ShortElementTraits : Primitive32ElementTraits<short>, IBaseElementT
781} 889}
782 890
783[EditorBrowsable(EditorBrowsableState.Never)] 891[EditorBrowsable(EditorBrowsableState.Never)]
784public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementTraits<float> 892internal class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementTraits<float>
785{ 893{
786 override public void ManagedToNativeCopyTo(float man, IntPtr mem) 894 override public void ManagedToNativeCopyTo(float man, IntPtr mem)
787 { 895 {
@@ -806,7 +914,7 @@ public class FloatElementTraits : Primitive32ElementTraits<float>, IBaseElementT
806} 914}
807 915
808[EditorBrowsable(EditorBrowsableState.Never)] 916[EditorBrowsable(EditorBrowsableState.Never)]
809public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElementTraits<double> 917internal class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElementTraits<double>
810{ 918{
811 override public void ManagedToNativeCopyTo(double man, IntPtr mem) 919 override public void ManagedToNativeCopyTo(double man, IntPtr mem)
812 { 920 {
@@ -831,7 +939,7 @@ public class DoubleElementTraits : Primitive64ElementTraits<double>, IBaseElemen
831} 939}
832 940
833[EditorBrowsable(EditorBrowsableState.Never)] 941[EditorBrowsable(EditorBrowsableState.Never)]
834public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTraits<byte> 942internal class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTraits<byte>
835{ 943{
836 override public void ManagedToNativeCopyTo(byte man, IntPtr mem) 944 override public void ManagedToNativeCopyTo(byte man, IntPtr mem)
837 { 945 {
@@ -856,7 +964,7 @@ public class ByteElementTraits : Primitive32ElementTraits<byte>, IBaseElementTra
856} 964}
857 965
858[EditorBrowsable(EditorBrowsableState.Never)] 966[EditorBrowsable(EditorBrowsableState.Never)]
859public static class TraitFunctions 967internal static class TraitFunctions
860{ 968{
861 public static bool IsEflObject(System.Type type) 969 public static bool IsEflObject(System.Type type)
862 { 970 {
@@ -895,22 +1003,6 @@ public static class TraitFunctions
895 1003
896 private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>(); 1004 private static IDictionary<System.Type, object> register = new Dictionary<System.Type, object>();
897 1005
898 private static System.Type AsEflInstantiableType(System.Type type)
899 {
900 if (!IsEflObject(type))
901 {
902 return null;
903 }
904
905 if (type.IsInterface)
906 {
907 string fullName = type.FullName + "Concrete";
908 return type.Assembly.GetType(fullName); // That was our best guess...
909 }
910
911 return type; // Not interface, so it should be a concrete.
912 }
913
914 public static object RegisterTypeTraits<T>() 1006 public static object RegisterTypeTraits<T>()
915 { 1007 {
916 Eina.Log.Debug($"Finding TypeTraits for {typeof(T).Name}"); 1008 Eina.Log.Debug($"Finding TypeTraits for {typeof(T).Name}");
@@ -918,14 +1010,6 @@ public static class TraitFunctions
918 var type = typeof(T); 1010 var type = typeof(T);
919 if (IsEflObject(type)) 1011 if (IsEflObject(type))
920 { 1012 {
921 System.Type concrete = AsEflInstantiableType(type);
922 if (concrete == null || !type.IsAssignableFrom(concrete))
923 {
924 throw new Exception("Failed to get a suitable concrete class for this type.");
925 }
926
927 // No need to pass concrete as the traits class will use reflection to get the actually most
928 // derived type returned.
929 traits = new EflObjectElementTraits<T>(); 1013 traits = new EflObjectElementTraits<T>();
930 } 1014 }
931 else if (IsString(type)) 1015 else if (IsString(type))
diff --git a/src/bindings/mono/eina_mono/eina_environment.cs b/src/bindings/mono/eina_mono/eina_environment.cs
new file mode 100644
index 0000000..e7f847b
--- /dev/null
+++ b/src/bindings/mono/eina_mono/eina_environment.cs
@@ -0,0 +1,53 @@
1using System;
2using System.Runtime.InteropServices;
3
4namespace Eina
5{
6
7/// <summary>
8/// Class to deal with native Environment variables.
9///
10/// <para>To be used in place of <see cref="System.Environment" /> methods when
11/// accessing the native environment directly.</para>
12/// <para>Since EFL 1.24.</para>
13/// </summary>
14internal static class Environment
15{
16 /// <summary>
17 /// Returns the value of the environment variable named <c>name</c>.
18 ///
19 /// <para>Since EFL 1.24.</para>
20 /// </summary>
21 /// <param name="name">The name of the variable to be retrieved</param>
22 /// <returns>The value of the variable. <c>null</c> if not set.</returns>
23 public static string GetEnv(string name)
24 {
25 return Eina.NativeCustomExportFunctions.efl_mono_native_getenv(name);
26 }
27
28 /// <summary>
29 /// Sets a native environment variable.
30 ///
31 /// <para>Since EFL 1.24.</para>
32 /// </summary>
33 /// <param name="name">The name of the variable</param>
34 /// <param name="value">The value to be set.</param>
35 /// <param name="overwrite"><c>true</c> if an existing variable must be overwritten.</param>
36 public static void SetEnv(string name, string value, bool overwrite=true)
37 {
38 Eina.Error error = Eina.NativeCustomExportFunctions.efl_mono_native_setenv(name, value, overwrite ? 1 : 0);
39 Eina.Error.Raise(error);
40 }
41}
42
43internal static partial class NativeCustomExportFunctions
44{
45 [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
46 [return: MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof(Efl.Eo.StringKeepOwnershipMarshaler))]
47 public static extern string efl_mono_native_getenv(string name);
48
49 [DllImport(efl.Libs.CustomExports, CharSet=CharSet.Ansi)]
50 public static extern Eina.Error efl_mono_native_setenv(string name, string value, int overwrite);
51}
52
53}
diff --git a/src/bindings/mono/eina_mono/eina_error.cs b/src/bindings/mono/eina_mono/eina_error.cs
index 7b5733d..1300e79 100644
--- a/src/bindings/mono/eina_mono/eina_error.cs
+++ b/src/bindings/mono/eina_mono/eina_error.cs
@@ -1,7 +1,23 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
20using System.Diagnostics.CodeAnalysis;
5 21
6namespace Eina 22namespace Eina
7{ 23{
@@ -9,7 +25,7 @@ namespace Eina
9/// <summary>Error codes from native Eina methods. 25/// <summary>Error codes from native Eina methods.
10/// <para>Since EFL 1.23.</para> 26/// <para>Since EFL 1.23.</para>
11/// </summary> 27/// </summary>
12public struct Error : IComparable<Error> 28public struct Error : IComparable<Error>, IEquatable<Error>
13{ 29{
14 int code; 30 int code;
15 31
@@ -26,7 +42,7 @@ public struct Error : IComparable<Error>
26 /// Unhandled Exception error identifier. 42 /// Unhandled Exception error identifier.
27 /// <para>Since EFL 1.23.</para> 43 /// <para>Since EFL 1.23.</para>
28 /// </summary> 44 /// </summary>
29 public static readonly Error UNHANDLED_EXCEPTION; 45 public static readonly Error UNHANDLED_EXCEPTION = eina_error_msg_register("Unhandled C# exception occurred.");
30 46
31 /// <summary> 47 /// <summary>
32 /// No error identifier. 48 /// No error identifier.
@@ -64,31 +80,28 @@ public struct Error : IComparable<Error>
64 /// <para>Since EFL 1.23.</para> 80 /// <para>Since EFL 1.23.</para>
65 /// </summary> 81 /// </summary>
66 /// <param name="val">Value to be converted to Error</param> 82 /// <param name="val">Value to be converted to Error</param>
67 static public implicit operator Error(int val) 83 public static implicit operator Error(int val) => FromInt32(val);
68 { 84
69 return new Error(val); 85 /// <summary>
70 } 86 /// Converts a <see cref="int" /> to a <see cref="Error" />.
87 /// <para>Since EFL 1.23.</para>
88 /// </summary>
89 /// <param name="val">The <see cref="int" /> to be converted.</param>
90 public static Error FromInt32(int val) => new Error(val);
71 91
72 /// <summary> 92 /// <summary>
73 /// Int conversion from Error. 93 /// Int conversion from Error.
74 /// <para>Since EFL 1.23.</para> 94 /// <para>Since EFL 1.23.</para>
75 /// </summary> 95 /// </summary>
76 /// <param name="error">Error identifier to be converted to int</param> 96 /// <param name="error">Error identifier to be converted to int</param>
77 static public implicit operator int(Error error) 97 public static implicit operator int(Error error) => ToInt32(error);
78 {
79 return error.code;
80 }
81 98
82 /// <summary> 99 /// <summary>
83 /// Compare two Errors. 100 /// Converts a <see cref="Error" /> to a <see cref="int" />.
84 /// <para>Since EFL 1.23.</para> 101 /// <para>Since EFL 1.23.</para>
85 /// </summary> 102 /// </summary>
86 /// <param name="err">Error to be compared with</param> 103 /// <param name="error">The <see cref="Error" /> to be converted.</param>
87 /// <returns>True with the Errors is equal, False otherwise.</returns> 104 public static int ToInt32(Error error) => error.code;
88 public int CompareTo(Error err)
89 {
90 return code.CompareTo(err.code);
91 }
92 105
93 /// <summary> 106 /// <summary>
94 /// Transform the object to a string representing the object. 107 /// Transform the object to a string representing the object.
@@ -100,11 +113,6 @@ public struct Error : IComparable<Error>
100 return "Eina.Error(" + code + ")"; 113 return "Eina.Error(" + code + ")";
101 } 114 }
102 115
103 static Error()
104 {
105 UNHANDLED_EXCEPTION = eina_error_msg_register("Unhandled C# exception occurred.");
106 }
107
108 [DllImport(efl.Libs.Eina)] static extern Error eina_error_msg_register(string msg); 116 [DllImport(efl.Libs.Eina)] static extern Error eina_error_msg_register(string msg);
109 [DllImport(efl.Libs.Eina)] static extern Error eina_error_get(); 117 [DllImport(efl.Libs.Eina)] static extern Error eina_error_get();
110 [DllImport(efl.Libs.Eina)] static extern void eina_error_set(Error error); 118 [DllImport(efl.Libs.Eina)] static extern void eina_error_set(Error error);
@@ -146,6 +154,8 @@ public struct Error : IComparable<Error>
146 /// back to the native code. For example, in an event handler. 154 /// back to the native code. For example, in an event handler.
147 /// <para>Since EFL 1.23.</para> 155 /// <para>Since EFL 1.23.</para>
148 /// </summary> 156 /// </summary>
157 [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate",
158 Justification = "It's not an event.")]
149 public static void RaiseIfUnhandledException() 159 public static void RaiseIfUnhandledException()
150 { 160 {
151 Error e = Get(); 161 Error e = Get();
@@ -160,6 +170,8 @@ public struct Error : IComparable<Error>
160 /// Raises an exception. 170 /// Raises an exception.
161 /// <para>Since EFL 1.23.</para> 171 /// <para>Since EFL 1.23.</para>
162 /// </summary> 172 /// </summary>
173 [SuppressMessage("Microsoft.Design", "CA1030:UseEventsWhereAppropriate",
174 Justification = "It's not an event.")]
163 public static void Raise(Error e) 175 public static void Raise(Error e)
164 { 176 {
165 if (e != 0) 177 if (e != 0)
@@ -187,6 +199,98 @@ public struct Error : IComparable<Error>
187 { 199 {
188 return eina_error_msg_register(msg); 200 return eina_error_msg_register(msg);
189 } 201 }
190}
191 202
203 /// <summary>
204 /// Gets a hash for <see cref="Eina.Error" />.
205 /// <para>Since EFL 1.23.</para>
206 /// </summary>
207 /// <returns>A hash code.</returns>
208 public override int GetHashCode()
209 => code.GetHashCode() + Message.GetHashCode(StringComparison.Ordinal);
210
211 /// <summary>
212 /// Compare to a given error.
213 /// <para>Since EFL 1.23.</para>
214 /// </summary>
215 /// <param name="err">Error to be compared with.</param>
216 /// <returns>-1, 0 or 1 if -1 if Error is less, equal or greater than err.</returns>
217 public int CompareTo(Error err) => code.CompareTo(err.code);
218
219 /// <summary>
220 /// Check if is equal to obj.
221 /// <para>Since EFL 1.23.</para>
222 /// </summary>
223 /// <param name="obj">The object to be checked.</param>
224 /// <returns>false if obj is null or not equals, true otherwise.</returns>
225 public override bool Equals(object obj)
226 {
227 if (object.ReferenceEquals(obj, null))
228 return false;
229
230 return this.Equals((Error)obj);
231 }
232
233 /// <summary>
234 /// Check if is equal to err.
235 /// <para>Since EFL 1.23.</para>
236 /// </summary>
237 /// <param name="err">The object to be checked.</param>
238 /// <returns>false if obj is null or not equals, true otherwise.</returns>
239 public bool Equals(Error err) => this.CompareTo(err) == 0;
240
241 /// <summary>
242 /// Check if lhs is equals to rhs.
243 /// <para>Since EFL 1.23.</para>
244 /// </summary>
245 /// <param name="lhs">The left hand side of the operator.</param>
246 /// <param name="rhs">The right hand side of the operator.</param>
247 /// <returns>true if lhs is equals to rhs, false otherwise.</returns>
248 public static bool operator==(Error lhs, Error rhs) => lhs.Equals(rhs);
249
250 /// <summary>
251 /// Check if lhs is not equals to rhs.
252 /// <para>Since EFL 1.23.</para>
253 /// </summary>
254 /// <param name="lhs">The left hand side of the operator.</param>
255 /// <param name="rhs">The right hand side of the operator.</param>
256 /// <returns>true if lhs is not equals to rhs, false otherwise.</returns>
257 public static bool operator!=(Error lhs, Error rhs) => !(lhs == rhs);
258
259 /// <summary>
260 /// Check if lhs is less than rhs.
261 /// <para>Since EFL 1.23.</para>
262 /// </summary>
263 /// <param name="lhs">The left hand side of the operator.</param>
264 /// <param name="rhs">The right hand side of the operator.</param>
265 /// <returns>true if lhs is less than rhs, false otherwise.</returns>
266 public static bool operator<(Error lhs, Error rhs) => (lhs.CompareTo(rhs) < 0);
267
268 /// <summary>
269 /// Check if lhs is greater to rhs.
270 /// <para>Since EFL 1.23.</para>
271 /// </summary>
272 /// <param name="lhs">The left hand side of the operator.</param>
273 /// <param name="rhs">The right hand side of the operator.</param>
274 /// <returns>true if lhs is greater than rhs, false otherwise.</returns>
275 public static bool operator>(Error lhs, Error rhs) => rhs < lhs;
276
277 /// <summary>
278 /// Check if lhs is equals and less than rhs.
279 /// <para>Since EFL 1.23.</para>
280 /// </summary>
281 /// <param name="lhs">The left hand side of the operator.</param>
282 /// <param name="rhs">The right hand side of the operator.</param>
283 /// <returns>true if lhs is equals and less than rhs, false otherwise.</returns>
284 public static bool operator<=(Error lhs, Error rhs) => !(lhs > rhs);
285
286 /// <summary>
287 /// Check if lhs is equals and greater than rhs.
288 /// <para>Since EFL 1.23.</para>
289 /// </summary>
290 /// <param name="lhs">The left hand side of the operator.</param>
291 /// <param name="rhs">The right hand side of the operator.</param>
292 /// <returns>true if lhs is equals and greater than rhs, false otherwise.</returns>
293 public static bool operator>=(Error lhs, Error rhs) => !(lhs < rhs);
294
295}
192} 296}
diff --git a/src/bindings/mono/eina_mono/eina_hash.cs b/src/bindings/mono/eina_mono/eina_hash.cs
index 54fd343..3cc8980 100644
--- a/src/bindings/mono/eina_mono/eina_hash.cs
+++ b/src/bindings/mono/eina_mono/eina_hash.cs
@@ -1,9 +1,25 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
7 23
8using static Eina.TraitFunctions; 24using static Eina.TraitFunctions;
9using static Eina.IteratorNativeFunctions; 25using static Eina.IteratorNativeFunctions;
@@ -15,15 +31,61 @@ namespace Eina
15 31
16[StructLayout(LayoutKind.Sequential)] 32[StructLayout(LayoutKind.Sequential)]
17[EditorBrowsable(EditorBrowsableState.Never)] 33[EditorBrowsable(EditorBrowsableState.Never)]
18public struct HashTupleNative 34internal struct HashTupleNative : IEquatable<HashTupleNative>
19{ 35{
20 public IntPtr key; 36 public IntPtr key;
21 public IntPtr data; 37 public IntPtr data;
22 public uint key_length; 38 public uint key_length;
39
40 /// <summary>
41 /// Gets a hash for <see cref="HashTupleNative" />.
42 /// <para>Since EFL 1.24.</para>
43 /// </summary>
44 /// <returns>A hash code.</returns>
45 public override int GetHashCode()
46 => key.GetHashCode() ^ data.GetHashCode() ^ key_length.GetHashCode();
47
48 /// <summary>Returns whether this <see cref="HashTupleNative" />
49 /// is equal to the given <see cref="object" />.
50 /// <para>Since EFL 1.24.</para>
51 /// </summary>
52 /// <param name="other">The <see cref="object" /> to be compared to.</param>
53 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
54 public override bool Equals(object other)
55 => (!(other is HashTupleNative)) ? false : Equals((HashTupleNative)other);
56
57 /// <summary>Returns whether this <see cref="HashTupleNative" /> is equal
58 /// to the given <see cref="HashTupleNative" />.
59 /// <para>Since EFL 1.24.</para>
60 /// </summary>
61 /// <param name="other">The <see cref="HashTupleNative" /> to be compared to.</param>
62 /// <returns><c>true</c> if is equal to <c>other</c>.</returns>
63 public bool Equals(HashTupleNative other)
64 => (key == other.key) && (data == other.data)
65 && (key_length == other.key_length);
66
67 /// <summary>Returns whether <c>lhs</c> is equal to <c>rhs</c>.
68 /// <para>Since EFL 1.24.</para>
69 /// </summary>
70 /// <param name="lhs">The left hand side of the operator.</param>
71 /// <param name="rhs">The right hand side of the operator.</param>
72 /// <returns><c>true</c> if <c>lhs</c> is equal
73 /// to <c>rhs</c>.</returns>
74 public static bool operator==(HashTupleNative lhs, HashTupleNative rhs)
75 => lhs.Equals(rhs);
76
77 /// <summary>Returns whether <c>lhs</c> is not equal to <c>rhs</c>.
78 /// <para>Since EFL 1.24.</para>
79 /// </summary>
80 /// <param name="lhs">The left hand side of the operator.</param>
81 /// <param name="rhs">The right hand side of the operator.</param>
82 /// <returns><c>true</c> if <c>lhs</c> is not equal
83 /// to <c>rhs</c>.</returns>
84 public static bool operator!=(HashTupleNative lhs, HashTupleNative rhs) => !(lhs == rhs);
23} 85}
24 86
25[EditorBrowsable(EditorBrowsableState.Never)] 87[EditorBrowsable(EditorBrowsableState.Never)]
26public static class HashNativeFunctions 88internal static class HashNativeFunctions
27{ 89{
28 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 90 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
29 eina_hash_new(IntPtr key_length_cb, IntPtr key_cmp_cb, IntPtr key_hash_cb, IntPtr data_free_cb, int buckets_power_size); 91 eina_hash_new(IntPtr key_length_cb, IntPtr key_cmp_cb, IntPtr key_hash_cb, IntPtr data_free_cb, int buckets_power_size);
@@ -135,8 +197,10 @@ public static class HashNativeFunctions
135 197
136/// <summary>Wrapper around native dictionary mapping keys to values. 198/// <summary>Wrapper around native dictionary mapping keys to values.
137/// 199///
138/// Since EFL 1.23. 200/// <para>Since EFL 1.23.</para>
139/// </summary> 201/// </summary>
202[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
203 Justification = "This is a generalized container mapping the native one.")]
140public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable 204public class Hash<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>, IDisposable
141{ 205{
142 [EditorBrowsable(EditorBrowsableState.Never)] 206 [EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/bindings/mono/eina_mono/eina_inarray.cs b/src/bindings/mono/eina_mono/eina_inarray.cs
index 0263faf..6bb8626 100644
--- a/src/bindings/mono/eina_mono/eina_inarray.cs
+++ b/src/bindings/mono/eina_mono/eina_inarray.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.InarrayNativeFunctions; 26using static Eina.InarrayNativeFunctions;
@@ -12,7 +29,7 @@ namespace Eina
12{ 29{
13 30
14[EditorBrowsable(EditorBrowsableState.Never)] 31[EditorBrowsable(EditorBrowsableState.Never)]
15public static class InarrayNativeFunctions 32internal static class InarrayNativeFunctions
16{ 33{
17 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 34 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
18 eina_inarray_new(uint member_size, uint step); 35 eina_inarray_new(uint member_size, uint step);
@@ -72,6 +89,8 @@ public static class InarrayNativeFunctions
72/// <summary>Wrapper around an inplace array. 89/// <summary>Wrapper around an inplace array.
73/// <para>Since EFL 1.23.</para> 90/// <para>Since EFL 1.23.</para>
74/// </summary> 91/// </summary>
92[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
93 Justification="This is a generalized container mapping the native one.")]
75public class Inarray<T> : IEnumerable<T>, IDisposable 94public class Inarray<T> : IEnumerable<T>, IDisposable
76{ 95{
77 public const uint DefaultStep = 0; 96 public const uint DefaultStep = 0;
@@ -467,6 +486,7 @@ public class Inarray<T> : IEnumerable<T>, IDisposable
467 /// <returns>true on success, false otherwise.</returns> 486 /// <returns>true on success, false otherwise.</returns>
468 public bool Append(T[] values) 487 public bool Append(T[] values)
469 { 488 {
489 Contract.Requires(values != null, nameof(values));
470 foreach (T v in values) 490 foreach (T v in values)
471 { 491 {
472 if (Push(v) == -1) 492 if (Push(v) == -1)
diff --git a/src/bindings/mono/eina_mono/eina_inlist.cs b/src/bindings/mono/eina_mono/eina_inlist.cs
index a2769bc..3d2670e 100644
--- a/src/bindings/mono/eina_mono/eina_inlist.cs
+++ b/src/bindings/mono/eina_mono/eina_inlist.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.InlistNativeFunctions; 26using static Eina.InlistNativeFunctions;
@@ -13,7 +30,7 @@ namespace Eina
13{ 30{
14 31
15[EditorBrowsable(EditorBrowsableState.Never)] 32[EditorBrowsable(EditorBrowsableState.Never)]
16public static class InlistNativeFunctions 33internal static class InlistNativeFunctions
17{ 34{
18 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 35 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
19 eina_inlist_append(IntPtr in_list, IntPtr in_item); 36 eina_inlist_append(IntPtr in_list, IntPtr in_item);
@@ -85,6 +102,8 @@ public static class InlistNativeFunctions
85/// <summary>Wrapper around an inplace list. 102/// <summary>Wrapper around an inplace list.
86/// <para>Since EFL 1.23.</para> 103/// <para>Since EFL 1.23.</para>
87/// </summary> 104/// </summary>
105[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
106 Justification="This is a generalized container mapping the native one.")]
88public class Inlist<T> : IEnumerable<T>, IDisposable 107public class Inlist<T> : IEnumerable<T>, IDisposable
89{ 108{
90 [EditorBrowsable(EditorBrowsableState.Never)] 109 [EditorBrowsable(EditorBrowsableState.Never)]
@@ -404,6 +423,7 @@ public class Inlist<T> : IEnumerable<T>, IDisposable
404 /// <param name="values">The values to be added.</param> 423 /// <param name="values">The values to be added.</param>
405 public void AppendArray(T[] values) 424 public void AppendArray(T[] values)
406 { 425 {
426 Contract.Requires(values != null, nameof(values));
407 foreach (T v in values) 427 foreach (T v in values)
408 { 428 {
409 Append(v); 429 Append(v);
diff --git a/src/bindings/mono/eina_mono/eina_iterator.cs b/src/bindings/mono/eina_mono/eina_iterator.cs
index b95e1e6..f142c3c 100644
--- a/src/bindings/mono/eina_mono/eina_iterator.cs
+++ b/src/bindings/mono/eina_mono/eina_iterator.cs
@@ -1,9 +1,25 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
7 23
8using static Eina.TraitFunctions; 24using static Eina.TraitFunctions;
9using static Eina.IteratorNativeFunctions; 25using static Eina.IteratorNativeFunctions;
@@ -12,7 +28,7 @@ namespace Eina
12{ 28{
13 29
14[EditorBrowsable(EditorBrowsableState.Never)] 30[EditorBrowsable(EditorBrowsableState.Never)]
15public static class IteratorNativeFunctions 31internal static class IteratorNativeFunctions
16{ 32{
17 [DllImport(efl.Libs.Eina)] internal static extern void 33 [DllImport(efl.Libs.Eina)] internal static extern void
18 eina_iterator_free(IntPtr iterator); 34 eina_iterator_free(IntPtr iterator);
@@ -29,11 +45,15 @@ public static class IteratorNativeFunctions
29 45
30 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 46 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
31 eina_carray_iterator_new(IntPtr array); 47 eina_carray_iterator_new(IntPtr array);
48 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
49 eina_carray_length_iterator_new(IntPtr array, uint step, uint length);
32} 50}
33 51
34/// <summary>Wrapper around a native Eina iterator. 52/// <summary>Wrapper around a native Eina iterator.
35/// <para>Since EFL 1.23.</para> 53/// <para>Since EFL 1.23.</para>
36/// </summary> 54/// </summary>
55[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
56 Justification="This is a generalized container mapping the native one.")]
37public class Iterator<T> : IEnumerable<T>, IDisposable 57public class Iterator<T> : IEnumerable<T>, IDisposable
38{ 58{
39 [EditorBrowsable(EditorBrowsableState.Never)] 59 [EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/src/bindings/mono/eina_mono/eina_list.cs b/src/bindings/mono/eina_mono/eina_list.cs
index df2fb68..f4882d0 100644
--- a/src/bindings/mono/eina_mono/eina_list.cs
+++ b/src/bindings/mono/eina_mono/eina_list.cs
@@ -1,9 +1,26 @@
1/*
2 * Copyright 2019 by its authors. See AUTHORS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
1#pragma warning disable 1591 16#pragma warning disable 1591
2 17
3using System; 18using System;
4using System.Runtime.InteropServices; 19using System.Runtime.InteropServices;
5using System.Collections.Generic; 20using System.Collections.Generic;
6using System.ComponentModel; 21using System.ComponentModel;
22using System.Diagnostics.CodeAnalysis;
23using System.Diagnostics.Contracts;
7 24
8using static Eina.TraitFunctions; 25using static Eina.TraitFunctions;
9using static Eina.ListNativeFunctions; 26using static Eina.ListNativeFunctions;
@@ -13,7 +30,7 @@ namespace Eina
13{ 30{
14 31
15[EditorBrowsable(EditorBrowsableState.Never)] 32[EditorBrowsable(EditorBrowsableState.Never)]
16public static class ListNativeFunctions 33internal static class ListNativeFunctions
17{ 34{
18 [DllImport(efl.Libs.Eina)] internal static extern IntPtr 35 [DllImport(efl.Libs.Eina)] internal static extern IntPtr
19 eina_list_append(IntPtr list, IntPtr data); 36 eina_list_append(IntPtr list, IntPtr data);
@@ -109,19 +126,24 @@ public static class ListNativeFunctions
109/// <summary>Native wrapper around a linked list of items. 126/// <summary>Native wrapper around a linked list of items.
110/// <para>Since EFL 1.23.</para> 127/// <para>Since EFL 1.23.</para>
111/// </summary> 128/// </summary>
112public class List<T> : IEnumerable<T>, IDisposable 129[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix",
130 Justification="This is a generalized container mapping the native one.")]
131public class List<T> : IList<T>, IEnumerable<T>, IDisposable
113{ 132{
114 133
115 [EditorBrowsable(EditorBrowsableState.Never)] 134 [EditorBrowsable(EditorBrowsableState.Never)]
116 public IntPtr Handle {get;set;} = IntPtr.Zero; 135 public IntPtr Handle {get; set; } = IntPtr.Zero;
136
117 /// <summary>Whether this managed list owns the native one. 137 /// <summary>Whether this managed list owns the native one.
118 /// <para>Since EFL 1.23.</para> 138 /// <para>Since EFL 1.23.</para>
119 /// </summary> 139 /// </summary>
120 public bool Own {get;set;} 140 internal bool Own { get; set; }
141
121 /// <summary>Whether the native list wrapped owns the content it points to. 142 /// <summary>Whether the native list wrapped owns the content it points to.
122 /// <para>Since EFL 1.23.</para> 143 /// <para>Since EFL 1.23.</para>
123 ///</summary> 144 ///</summary>
124 public bool OwnContent {get;set;} 145 internal bool OwnContent { get; set; }
146
125 147
126 /// <summary>Delegate for comparing two elements of this list. 148 /// <summary>Delegate for comparing two elements of this list.
127 /// <para>Since EFL 1.23.</para> 149 /// <para>Since EFL 1.23.</para>
@@ -131,15 +153,16 @@ public class List<T> : IEnumerable<T>, IDisposable
131 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns> 153 /// <returns>-1, 0 or 1 for respectively smaller, equal or larger.</returns>
132 public delegate int Compare(T a, T b); 154 public delegate int Compare(T a, T b);
133 155
134 /// <summary>The number of elements on this list. 156 public bool IsReadOnly { get => !OwnContent; }
135 /// <para>Since EFL 1.23.</para> 157
158 /// <summary>The number of elements in this list.
159 /// <para>Since EFL 1.24.</para>
136 /// </summary> 160 /// </summary>
137 public int Length 161 public int Count
138 { 162 {
139 get { return Count(); } 163 get => (int)eina_list_count_custom_export_mono(Handle);
140 } 164 }
141 165
142
143 private void InitNew() 166 private void InitNew()
144 { 167 {
145 Handle = IntPtr.Zero; 168 Handle = IntPtr.Zero;
@@ -148,38 +171,85 @@ public class List<T> : IEnumerable<T>, IDisposable
148 } 171 }
149 172
150 private IntPtr InternalLast() 173 private IntPtr InternalLast()
151 { 174 => eina_list_last_custom_export_mono(Handle);
152 return eina_list_last_custom_export_mono(Handle);
153 }
154 175
155 private static IntPtr InternalNext(IntPtr list) 176 private static IntPtr InternalNext(IntPtr list)
177 => eina_list_next_custom_export_mono(list);
178
179 private static IntPtr InternalPrev(IntPtr list)
180 => eina_list_prev_custom_export_mono(list);
181
182 private static IntPtr InternalDataGet(IntPtr list)
183 => eina_list_data_get_custom_export_mono(list);
184
185 private static IntPtr InternalDataSet(IntPtr list, IntPtr data)
186 => eina_list_data_set_custom_export_mono(list, data);
187
188 private IntPtr GetNative(int idx, Func<IntPtr, uint, IntPtr> f)
156 { 189 {
157 return eina_list_next_custom_export_mono(list); 190 if (!(0 <= idx && idx < Count))
191 {
192 throw new ArgumentOutOfRangeException(nameof(idx), $"{nameof(idx)} cannot be negative, neither smaller than {nameof(Count)}");
193 }
194
195 var ele = f(Handle, (uint)idx);
196 if (ele == IntPtr.Zero)
197 {
198 throw new ArgumentOutOfRangeException(nameof(idx), $"There is no position {nameof(idx)}");
199 }
200
201 return ele;
158 } 202 }
159 203
160 private static IntPtr InternalPrev(IntPtr list) 204 private IntPtr GetNativeDataPointer(int idx)
205 => GetNative(idx, eina_list_nth);
206
207 private IntPtr GetNativePointer(int idx)
208 => GetNative(idx, eina_list_nth_list);
209
210 private void RequireWritable()
161 { 211 {
162 return eina_list_prev_custom_export_mono(list); 212 if (IsReadOnly)
213 {
214 throw new NotSupportedException("Cannot modify read-only container.");
215 }
163 } 216 }
164 217
165 private static IntPtr InternalDataGet(IntPtr list) 218 private void CheckOwnerships()
166 { 219 {
167 return eina_list_data_get_custom_export_mono(list); 220 if ((Own == false) && (OwnContent == true))
221 {
222 throw new InvalidOperationException(nameof(Own) + "/" + nameof(OwnContent));
223 }
168 } 224 }
169 225
170 private static IntPtr InternalDataSet(IntPtr list, IntPtr data) 226 private void DeleteData(IntPtr ele)
171 { 227 {
172 return eina_list_data_set_custom_export_mono(list, data); 228 if (OwnContent)
229 {
230 NativeFree<T>(InternalDataGet(ele));
231 }
173 } 232 }
174 233
234 private U LoopingThrough<U>(T val, Func<int, U> f1, Func<U> f2)
235 {
236 int i = 0;
237 IntPtr cur = Handle;
238 for (; cur != IntPtr.Zero; ++i, cur = InternalNext(cur))
239 {
240 if (NativeToManaged<T>(InternalDataGet(cur)).Equals(val))
241 {
242 return f1(i);
243 }
244 }
245
246 return f2();
247 }
175 248
176 /// <summary>Creates a new empty list. 249 /// <summary>Creates a new empty list.
177 /// <para>Since EFL 1.23.</para> 250 /// <para>Since EFL 1.23.</para>
178 /// </summary> 251 /// </summary>
179 public List() 252 public List() => InitNew();
180 {
181 InitNew();
182 }
183 253
184 /// <summary>Creates a new list wrapping the given handle.</summary> 254 /// <summary>Creates a new list wrapping the given handle.</summary>
185 [EditorBrowsable(EditorBrowsableState.Never)] 255 [EditorBrowsable(EditorBrowsableState.Never)]
@@ -188,6 +258,7 @@ public class List<T> : IEnumerable<T>, IDisposable
188 Handle = handle; 258 Handle = handle;
189 Own = own; 259 Own = own;
190 OwnContent = own; 260 OwnContent = own;
261 CheckOwnerships();
191 } 262 }
192 263
193 /// <summary>Creates a new list wrapping the given handle.</summary> 264 /// <summary>Creates a new list wrapping the given handle.</summary>
@@ -197,15 +268,13 @@ public class List<T> : IEnumerable<T>, IDisposable
197 Handle = handle; 268 Handle = handle;
198 Own = own; 269 Own = own;
199 OwnContent = ownContent; 270 OwnContent = ownContent;
271 CheckOwnerships();
200 } 272 }
201 273
202 /// <summary>Finalizes this list. 274 /// <summary>Finalizes this list.
203 /// <para>Since EFL 1.23.</para> 275 /// <para>Since EFL 1.23.</para>
204 /// </summary> 276 /// </summary>
205 ~List() 277 ~List() => Dispose(false);
206 {
207 Dispose(false);
208 }
209 278
210 /// <summary>Disposes of this list. 279 /// <summary>Disposes of this list.
211 /// <para>Since EFL 1.23.</para> 280 /// <para>Since EFL 1.23.</para>
@@ -221,12 +290,14 @@ public class List<T> : IEnumerable<T>, IDisposable
221 return; 290 return;
222 } 291 }
223 292
224 if (Own && OwnContent) 293 for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr))
225 { 294 {
226 for (IntPtr curr = h; curr != IntPtr.Zero; curr = InternalNext(curr)) 295 if (!OwnContent)
227 { 296 {
228 NativeFree<T>(InternalDataGet(curr)); 297 break;
229 } 298 }
299
300 DeleteData(curr);
230 } 301 }
231 302
232 if (Own) 303 if (Own)
@@ -254,30 +325,17 @@ public class List<T> : IEnumerable<T>, IDisposable
254 /// <summary>Disposes of this list. 325 /// <summary>Disposes of this list.
255 /// <para>Since EFL 1.23.</para> 326 /// <para>Since EFL 1.23.</para>
256 /// </summary> 327 /// </summary>
257 public void Free() 328 public void Free() => Dispose();
258 {
259 Dispose();
260 }
261
262 /// <summary>Relinquishes of the native list.
263 /// <para>Since EFL 1.23.</para>
264 /// </summary>
265 /// <returns>The previously wrapped native list handle.</returns>
266 public IntPtr Release()
267 {
268 IntPtr h = Handle;
269 Handle = IntPtr.Zero;
270 return h;
271 }
272 329
273 /// <summary>Sets whether this wrapper should own the native list or not. 330 /// <summary>Sets whether this wrapper should own the native list or not.
274 /// <para>Since EFL 1.23.</para> 331 /// <para>Since EFL 1.23.</para>
275 /// </summary> 332 /// </summary>
276 /// <param name="ownAll">If the hash own for all ownerships.</param> 333 /// <param name="ownAll">If the hash own for all ownerships.</param>
277 public void SetOwnership(bool ownAll) 334 internal void SetOwnership(bool ownAll)
278 { 335 {
279 Own = ownAll; 336 Own = ownAll;
280 OwnContent = ownAll; 337 OwnContent = ownAll;
338 CheckOwnerships();
281 } 339 }
282 340
283 /// <summary>Sets whether this wrapper should own the native list and 341 /// <summary>Sets whether this wrapper should own the native list and
@@ -286,19 +344,11 @@ public class List<T> : IEnumerable<T>, IDisposable
286 /// </summary> 344 /// </summary>
287 /// <param name="own">If own the object.</param> 345 /// <param name="own">If own the object.</param>
288 /// <param name="ownContent">If own the content's object.</param> 346 /// <param name="ownContent">If own the content's object.</param>
289 public void SetOwnership(bool own, bool ownContent) 347 internal void SetOwnership(bool own, bool ownContent)
290 { 348 {
291 Own = own; 349 Own = own;
292 OwnContent = ownContent; 350 OwnContent = ownContent;
293 } 351 CheckOwnerships();
294
295 /// <summary>Returns the number of elements in this list.
296 /// <para>Since EFL 1.23.</para>
297 /// </summary>
298 /// <returns>The number of elements.</returns>
299 public int Count()
300 {
301 return (int)eina_list_count_custom_export_mono(Handle);
302 } 352 }
303 353
304 /// <summary>Appends <c>val</c> to the list. 354 /// <summary>Appends <c>val</c> to the list.
@@ -307,8 +357,9 @@ public class List<T> : IEnumerable<T>, IDisposable
307 /// <param name="val">The item to be appended.</param> 357 /// <param name="val">The item to be appended.</param>
308 public void Append(T val) 358 public void Append(T val)
309 { 359 {
310 IntPtr ele = ManagedToNativeAlloc(val); 360 RequireWritable();
311 Handle = eina_list_append(Handle, ele); 361
362 Handle = eina_list_append(Handle, ManagedToNativeAlloc(val));
312 } 363 }
313 364
314 /// <summary>Prepends <c>val</c> to the list. 365 /// <summary>Prepends <c>val</c> to the list.
@@ -317,8 +368,9 @@ public class List<T> : IEnumerable<T>, IDisposable
317 /// <param name="val">The item to be prepended.</param> 368 /// <param name="val">The item to be prepended.</param>
318 public void Prepend(T val) 369 public void Prepend(T val)
319 { 370 {
320 IntPtr ele = ManagedToNativeAlloc(val); 371 RequireWritable();
321 Handle = eina_list_prepend(Handle, ele); 372
373 Handle = eina_list_prepend(Handle, ManagedToNativeAlloc(val));
322 } 374 }
323 375
324 /// <summary>Inserts <c>val</c> in the list in a sorted manner. 376 /// <summary>Inserts <c>val</c> in the list in a sorted manner.
@@ -328,8 +380,11 @@ public class List<T> : IEnumerable<T>, IDisposable
328 /// <param name="val">The item to be inserted.</param> 380 /// <param name="val">The item to be inserted.</param>
329 public void SortedInsert(T val) 381 public void SortedInsert(T val)
330 { 382 {
331 IntPtr ele = ManagedToNativeAlloc(val); 383 RequireWritable();
332 Handle = eina_list_sorted_insert(Handle, EinaCompareCb<T>(), ele); 384
385 Handle = eina_list_sorted_insert(Handle,
386 EinaCompareCb<T>(),
387 ManagedToNativeAlloc(val));
333 } 388 }
334 389
335 /// <summary>Inserts <c>val</c> in the list in a sorted manner with the 390 /// <summary>Inserts <c>val</c> in the list in a sorted manner with the
@@ -341,8 +396,11 @@ public class List<T> : IEnumerable<T>, IDisposable
341 /// <param name="val">The item to be inserted.</param> 396 /// <param name="val">The item to be inserted.</param>
342 public void SortedInsert(Compare compareCb, T val) 397 public void SortedInsert(Compare compareCb, T val)
343 { 398 {
344 IntPtr ele = ManagedToNativeAlloc(val); 399 RequireWritable();
345 Handle = eina_list_sorted_insert(Handle, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)), ele); 400
401 Handle = eina_list_sorted_insert(Handle,
402 Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)),
403 ManagedToNativeAlloc(val));
346 } 404 }
347 405
348 /// <summary>Sorts <c>limit</c> elements in this list inplace. 406 /// <summary>Sorts <c>limit</c> elements in this list inplace.
@@ -351,6 +409,8 @@ public class List<T> : IEnumerable<T>, IDisposable
351 /// <param name="limit">The max number of elements to be sorted.</param> 409 /// <param name="limit">The max number of elements to be sorted.</param>
352 public void Sort(int limit = 0) 410 public void Sort(int limit = 0)
353 { 411 {
412 RequireWritable();
413
354 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>()); 414 Handle = eina_list_sort(Handle, (uint)limit, EinaCompareCb<T>());
355 } 415 }
356 416
@@ -360,7 +420,10 @@ public class List<T> : IEnumerable<T>, IDisposable
360 /// <param name="compareCb">The function to compare two elements of the list.</param> 420 /// <param name="compareCb">The function to compare two elements of the list.</param>
361 public void Sort(Compare compareCb) 421 public void Sort(Compare compareCb)
362 { 422 {
363 Handle = eina_list_sort(Handle, 0, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb))); 423 RequireWritable();
424
425 Handle = eina_list_sort(Handle, (uint)0,
426 Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
364 } 427 }
365 428
366 /// <summary>Sorts <c>limit</c> elements in this list inplace. 429 /// <summary>Sorts <c>limit</c> elements in this list inplace.
@@ -370,15 +433,16 @@ public class List<T> : IEnumerable<T>, IDisposable
370 /// <param name="compareCb">The function to compare two elements of the list.</param> 433 /// <param name="compareCb">The function to compare two elements of the list.</param>
371 public void Sort(int limit, Compare compareCb) 434 public void Sort(int limit, Compare compareCb)
372 { 435 {
373 Handle = eina_list_sort(Handle, (uint)limit, Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb))); 436 RequireWritable();
437
438 Handle = eina_list_sort(Handle, (uint)limit,
439 Marshal.GetFunctionPointerForDelegate(GetNativeCompareCb(compareCb)));
374 } 440 }
375 441
376 private Eina.Callbacks.EinaCompareCb GetNativeCompareCb(Compare managedCb) 442 private Eina.Callbacks.EinaCompareCb GetNativeCompareCb(Compare managedCb)
377 { 443 => (IntPtr a, IntPtr b)
378 return (IntPtr a, IntPtr b) => { 444 => managedCb(NativeToManaged<T>(a), NativeToManaged<T>(b));
379 return managedCb(NativeToManaged<T>(a), NativeToManaged<T>(b)); 445
380 };
381 }
382 446
383 /// <summary>Returns the <c>n</c>th element of this list. Due to marshalling details, the returned element 447 /// <summary>Returns the <c>n</c>th element of this list. Due to marshalling details, the returned element
384 /// may be a different C# object from the one you used to append. 448 /// may be a different C# object from the one you used to append.
@@ -386,33 +450,20 @@ public class List<T> : IEnumerable<T>, IDisposable
386 /// </summary> 450 /// </summary>
387 /// <param name="n">The 0-based index to be retrieved.</param> 451 /// <param name="n">The 0-based index to be retrieved.</param>
388 /// <returns>The value in the specified element.</returns> 452 /// <returns>The value in the specified element.</returns>
389 public T Nth(int n) 453 public T Nth(int n) => NativeToManaged<T>(GetNativeDataPointer(n));
390 {
391 // TODO: check bounds ???
392 IntPtr ele = eina_list_nth(Handle, (uint)n);
393 return NativeToManaged<T>(ele);
394 }
395 454
396 /// <summary>Sets the data at the <c>idx</c> position. 455 /// <summary>Sets the data at the <c>idx</c> position.
397 /// <para>Since EFL 1.23.</para> 456 /// <para>Since EFL 1.23.</para>
398 /// </summary> 457 /// </summary>
399 /// <param name="idx">The 0-based index to be set.</param> 458 /// <param name="idx">The 0-based index to be set.</param>
400 /// <param name="val">The value to be inserted.</param> 459 /// <param name="val">The value to be inserted.</param>
401 public void DataSet(int idx, T val) 460 internal void DataSet(int idx, T val)
402 { 461 {
403 IntPtr pos = eina_list_nth_list(Handle, (uint)idx); 462 RequireWritable();
404 if (pos == IntPtr.Zero)
405 {
406 throw new IndexOutOfRangeException();
407 }
408 463
409 if (OwnContent) 464 IntPtr pos = GetNativePointer(idx);
410 { 465 DeleteData(pos);
411 NativeFree<T>(InternalDataGet(pos)); 466 InternalDataSet(pos, ManagedToNativeAlloc(val));
412 }
413
414 IntPtr ele = ManagedToNativeAlloc(val);
415 InternalDataSet(pos, ele);
416 } 467 }
417 468
418 /// <summary>Accessor for the data at the <c>idx</c> position. 469 /// <summary>Accessor for the data at the <c>idx</c> position.
@@ -436,10 +487,7 @@ public class List<T> : IEnumerable<T>, IDisposable
436 /// </summary> 487 /// </summary>
437 /// <returns>The value contained in the last list position.</returns> 488 /// <returns>The value contained in the last list position.</returns>
438 public T LastDataGet() 489 public T LastDataGet()
439 { 490 => NativeToManaged<T>(eina_list_last_data_get_custom_export_mono(Handle));
440 IntPtr ele = eina_list_last_data_get_custom_export_mono(Handle);
441 return NativeToManaged<T>(ele);
442 }
443 491
444 /// <summary>Reverses this list in place. 492 /// <summary>Reverses this list in place.
445 /// <para>Since EFL 1.23.</para> 493 /// <para>Since EFL 1.23.</para>
@@ -447,6 +495,8 @@ public class List<T> : IEnumerable<T>, IDisposable
447 /// <returns>A reference to this object.</returns> 495 /// <returns>A reference to this object.</returns>
448 public List<T> Reverse() 496 public List<T> Reverse()
449 { 497 {
498 RequireWritable();
499
450 Handle = eina_list_reverse(Handle); 500 Handle = eina_list_reverse(Handle);
451 return this; 501 return this;
452 } 502 }
@@ -456,6 +506,8 @@ public class List<T> : IEnumerable<T>, IDisposable
456 /// </summary> 506 /// </summary>
457 public void Shuffle() 507 public void Shuffle()
458 { 508 {
509 RequireWritable();
510
459 Handle = eina_list_shuffle(Handle, IntPtr.Zero); 511 Handle = eina_list_shuffle(Handle, IntPtr.Zero);
460 } 512 }
461 513
@@ -465,9 +517,10 @@ public class List<T> : IEnumerable<T>, IDisposable
465 /// <returns>A managed array of the elements.</returns> 517 /// <returns>A managed array of the elements.</returns>
466 public T[] ToArray() 518 public T[] ToArray()
467 { 519 {
468 var managed = new T[Count()]; 520 var managed = new T[Count];
469 int i = 0; 521 int i = 0;
470 for (IntPtr curr = Handle; curr != IntPtr.Zero; curr = InternalNext(curr), ++i) 522 for (IntPtr curr = Handle; curr != IntPtr.Zero;
523 curr = InternalNext(curr), ++i)
471 { 524 {
472 managed[i] = NativeToManaged<T>(InternalDataGet(curr)); 525 managed[i] = NativeToManaged<T>(InternalDataGet(curr));
473 } 526 }
@@ -479,8 +532,11 @@ public class List<T> : IEnumerable<T>, IDisposable
479 /// <para>Since EFL 1.23.</para> 532 /// <para>Since EFL 1.23.</para>
480 /// </summary> 533 /// </summary>
481 /// <param name="values">The values to be appended.</param> 534 /// <param name="values">The values to be appended.</param>
482 public void AppendArray(T[] values) 535 public void Append(T[] values)
483 { 536 {
537 Contract.Requires(values != null, nameof(values));
538 RequireWritable();
539
484 foreach (T v in values) 540 foreach (T v in values)
485 { 541 {
486 Append(v); 542 Append(v);
@@ -493,18 +549,14 @@ public class List<T> : IEnumerable<T>, IDisposable
493 /// </summary> 549 /// </summary>
494 /// <returns>The iterator.</returns> 550 /// <returns>The iterator.</returns>
495 public Eina.Iterator<T> GetIterator() 551 public Eina.Iterator<T> GetIterator()
496 { 552 => new Eina.Iterator<T>(eina_list_iterator_new(Handle), true);
497 return new Eina.Iterator<T>(eina_list_iterator_new(Handle), true);
498 }
499 553
500 /// <summary>Gets an iterator that iterates this list in reverse order. 554 /// <summary>Gets an iterator that iterates this list in reverse order.
501 /// <para>Since EFL 1.23.</para> 555 /// <para>Since EFL 1.23.</para>
502 /// </summary> 556 /// </summary>
503 /// <returns>The iterator.</returns> 557 /// <returns>The iterator.</returns>
504 public Eina.Iterator<T> GetReversedIterator() 558 public Eina.Iterator<T> GetReversedIterator()
505 { 559 => new Eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true);
506 return new Eina.Iterator<T>(eina_list_iterator_reversed_new(Handle), true);
507 }
508 560
509 /// <summary>Gets an enumerator into this list. 561 /// <summary>Gets an enumerator into this list.
510 /// <para>Since EFL 1.23.</para> 562 /// <para>Since EFL 1.23.</para>
@@ -523,18 +575,136 @@ public class List<T> : IEnumerable<T>, IDisposable
523 /// </summary> 575 /// </summary>
524 /// <returns>The enumerator.</returns> 576 /// <returns>The enumerator.</returns>
525 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 577 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
526 { 578 => this.GetEnumerator();
527 return this.GetEnumerator();
528 }
529 579
530 /// <summary> Gets an Accessor for this List. 580 /// <summary> Gets an Accessor for this List.
531 /// <para>Since EFL 1.23.</para> 581 /// <para>Since EFL 1.23.</para>
532 /// </summary> 582 /// </summary>
533 /// <returns>The accessor.</returns> 583 /// <returns>The accessor.</returns>
534 public Eina.Accessor<T> GetAccessor() 584 public Eina.Accessor<T> GetAccessor()
585 => new Eina.Accessor<T>(eina_list_accessor_new(Handle),
586 Ownership.Managed);
587<