質問編集履歴
2
詳細の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,3 +65,261 @@
|
|
65
65
|
|
66
66
|
|
67
67
|
FormsからDependencyServiceを使い、Android側でXamnarin.Androidライブラリを使うのであれば動くとは思うのですが、.NET Standard libraryから利用する、または、.NET Standard library内で完結するような作りというのは無理でしょうか。
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
---
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
## 追記 20190301
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
* Xamarin.Fomrsプロジェクトを作成
|
80
|
+
|
81
|
+
* Cross-Platform .NET Standard Plugin Templates を追加
|
82
|
+
|
83
|
+
* Xamarin.Formsプロジェクトからライブラリプロジェクトを参照
|
84
|
+
|
85
|
+
* Xamarin.Androidプロジェクトからライブラリプロジェクトを参照
|
86
|
+
|
87
|
+
* Xamarin.iOSプロジェクトはアンロード
|
88
|
+
|
89
|
+
* CrossTestPlugin.shared.csにてTestPluginImplementationをインスタンス化しようとした時にNotImplementedExceptionが吐かれる
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
CrossTestPlugin.shared.cs
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
using System;
|
100
|
+
|
101
|
+
using Plugin.TestPlugin;
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
namespace Plugin.TestPlugin
|
106
|
+
|
107
|
+
{
|
108
|
+
|
109
|
+
/// <summary>
|
110
|
+
|
111
|
+
/// Cross TestPlugin
|
112
|
+
|
113
|
+
/// </summary>
|
114
|
+
|
115
|
+
public static class CrossTestPlugin
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
static Lazy<ITestPlugin> implementation = new Lazy<ITestPlugin>(() => CreateTestPlugin(), System.Threading.LazyThreadSafetyMode.PublicationOnly);
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
/// <summary>
|
124
|
+
|
125
|
+
/// Gets if the plugin is supported on the current platform.
|
126
|
+
|
127
|
+
/// </summary>
|
128
|
+
|
129
|
+
public static bool IsSupported => implementation.Value == null ? false : true;
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
/// <summary>
|
134
|
+
|
135
|
+
/// Current plugin implementation to use
|
136
|
+
|
137
|
+
/// </summary>
|
138
|
+
|
139
|
+
public static ITestPlugin Current
|
140
|
+
|
141
|
+
{
|
142
|
+
|
143
|
+
get
|
144
|
+
|
145
|
+
{
|
146
|
+
|
147
|
+
ITestPlugin ret = implementation.Value;
|
148
|
+
|
149
|
+
if (ret == null)
|
150
|
+
|
151
|
+
{
|
152
|
+
|
153
|
+
throw NotImplementedInReferenceAssembly();
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
return ret;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
static ITestPlugin CreateTestPlugin()
|
166
|
+
|
167
|
+
{
|
168
|
+
|
169
|
+
#if NETSTANDARD1_0 || NETSTANDARD2_0
|
170
|
+
|
171
|
+
return null;
|
172
|
+
|
173
|
+
#else
|
174
|
+
|
175
|
+
#pragma warning disable IDE0022 // Use expression body for methods
|
176
|
+
|
177
|
+
return new TestPluginImplementation(); // ここでNotImplementedException が出る
|
178
|
+
|
179
|
+
#pragma warning restore IDE0022 // Use expression body for methods
|
180
|
+
|
181
|
+
#endif
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
internal static Exception NotImplementedInReferenceAssembly() =>
|
188
|
+
|
189
|
+
new NotImplementedException("This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.");
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
```
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
ITestPlugin.shared.cs
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
using System;
|
210
|
+
|
211
|
+
using System.Collections.Generic;
|
212
|
+
|
213
|
+
using System.Text;
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
namespace Plugin.TestPlugin
|
218
|
+
|
219
|
+
{
|
220
|
+
|
221
|
+
public interface ITestPlugin
|
222
|
+
|
223
|
+
{
|
224
|
+
|
225
|
+
string GetVersionName();
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
TestPlugin.android.cs
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
using Android.Content;
|
242
|
+
|
243
|
+
using System;
|
244
|
+
|
245
|
+
using System.Collections.Generic;
|
246
|
+
|
247
|
+
using System.Text;
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
namespace Plugin.TestPlugin
|
252
|
+
|
253
|
+
{
|
254
|
+
|
255
|
+
/// <summary>
|
256
|
+
|
257
|
+
/// Interface for TestPlugin
|
258
|
+
|
259
|
+
/// </summary>
|
260
|
+
|
261
|
+
public class TestPluginImplementation : ITestPlugin
|
262
|
+
|
263
|
+
{
|
264
|
+
|
265
|
+
public string GetVersionName()
|
266
|
+
|
267
|
+
{
|
268
|
+
|
269
|
+
Context context = Android.App.Application.Context; //Android.App.Application.Context;
|
270
|
+
|
271
|
+
var name = context.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName;
|
272
|
+
|
273
|
+
return name;
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
```
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
```
|
286
|
+
|
287
|
+
TestPlugin.apple.cs
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
using System;
|
292
|
+
|
293
|
+
using System.Collections.Generic;
|
294
|
+
|
295
|
+
using System.Text;
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
namespace Plugin.TestPlugin
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
/// <summary>
|
304
|
+
|
305
|
+
/// Interface for TestPlugin
|
306
|
+
|
307
|
+
/// </summary>
|
308
|
+
|
309
|
+
public class TestPluginImplementation : ITestPlugin
|
310
|
+
|
311
|
+
{
|
312
|
+
|
313
|
+
public string GetVersionName()
|
314
|
+
|
315
|
+
{
|
316
|
+
|
317
|
+
return "ios";
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
```
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,4 +52,16 @@
|
|
52
52
|
|
53
53
|
|
54
54
|
|
55
|
+
環境
|
56
|
+
|
57
|
+
win10 VS2017
|
58
|
+
|
59
|
+
Mac VS for Mac
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
~~~~
|
64
|
+
|
65
|
+
|
66
|
+
|
55
67
|
FormsからDependencyServiceを使い、Android側でXamnarin.Androidライブラリを使うのであれば動くとは思うのですが、.NET Standard libraryから利用する、または、.NET Standard library内で完結するような作りというのは無理でしょうか。
|