forked from reactiveui/ReactiveUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjectExtension.cs
More file actions
42 lines (34 loc) · 1.03 KB
/
ObjectExtension.cs
File metadata and controls
42 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Object = Java.Lang.Object;
namespace ReactiveUI
{
internal class JavaHolder : Object
{
public readonly object Instance;
public JavaHolder(object instance)
{
Instance = instance;
}
}
internal static class ObjectExtension
{
public static TObject ToNetObject<TObject>(this Object value)
{
if (value == null)
return default(TObject);
if (!(value is JavaHolder))
throw new InvalidOperationException("Unable to convert to .NET object. Only Java.Lang.Object created with .ToJavaObject() can be converted.");
return (TObject)((JavaHolder)value).Instance;
}
public static Object ToJavaObject<TObject>(this TObject value)
{
if (value == null)
return null;
var holder = new JavaHolder(value);
return (Object)holder;
}
}
}