Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added INativeConvertible on native types to manage conversion in reviewed extensions #373

1 change: 1 addition & 0 deletions src/net/Common/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<TargetFrameworks>net462;net6.0;net7.0;net8.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup Condition="'$(JNET_DOCKER_BUILD_ACTIONS)' == 'true'">
<DefineConstants>$(DefineConstants);JNET_DOCKER_BUILD_ACTIONS</DefineConstants>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Boolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Boolean
public partial class Boolean : INativeConvertible<Boolean, bool>
{
bool INativeConvertible<Boolean, bool>.ToCLR()
{
return BooleanValue();
}
/// <summary>
/// Returns the <see cref="Boolean"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="bool"/> of CLR</param>
/// <returns>The converted <see cref="Boolean"/></returns>
public static Boolean ToJVM(bool clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Boolean"/> to <see cref="bool"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Byte.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Byte
public partial class Byte : INativeConvertible<Byte, byte>
{
byte INativeConvertible<Byte, byte>.ToCLR()
{
return ByteValue();
}
/// <summary>
/// Returns the <see cref="Byte"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="byte"/> of CLR</param>
/// <returns>The converted <see cref="Byte"/></returns>
public static Byte ToJVM(byte clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Byte"/> to <see cref="byte"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Character
public partial class Character : INativeConvertible<Character, char>
{
char INativeConvertible<Character, char>.ToCLR()
{
return CharValue();
}
/// <summary>
/// Returns the <see cref="Character"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="char"/> of CLR</param>
/// <returns>The converted <see cref="Character"/></returns>
public static Character ToJVM(char clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Character"/> to <see cref="char"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Double.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Double //: Number
public partial class Double : INativeConvertible<Double, double>
{
double INativeConvertible<Double, double>.ToCLR()
{
return DoubleValue();
}
/// <summary>
/// Returns the <see cref="Double"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="double"/> of CLR</param>
/// <returns>The converted <see cref="Double"/></returns>
public static Double ToJVM(double clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Double"/> to <see cref="double"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Float.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Float : Number
public partial class Float : INativeConvertible<Float, float>
{
float INativeConvertible<Float, float>.ToCLR()
{
return FloatValue();
}
/// <summary>
/// Returns the <see cref="Float"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="float"/> of CLR</param>
/// <returns>The converted <see cref="Float"/></returns>
public static Float ToJVM(float clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Float"/> to <see cref="float"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Integer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Integer : Number
public partial class Integer : INativeConvertible<Integer, int>
{
int INativeConvertible<Integer, int>.ToCLR()
{
return IntValue();
}
/// <summary>
/// Returns the <see cref="Integer"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="int"/> of CLR</param>
/// <returns>The converted <see cref="Integer"/></returns>
public static Integer ToJVM(int clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Integer"/> to <see cref="int"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Long.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Long : Number
public partial class Long : INativeConvertible<Long, long>
{
long INativeConvertible<Long, long>.ToCLR()
{
return LongValue();
}
/// <summary>
/// Returns the <see cref="Long"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="long"/> of CLR</param>
/// <returns>The converted <see cref="Long"/></returns>
public static Long ToJVM(long clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Long"/> to <see cref="long"/>
/// </summary>
Expand Down
17 changes: 16 additions & 1 deletion src/net/JNet/Developed/Java/Lang/Short.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,27 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System;

namespace Java.Lang
{
public partial class Short : Number
public partial class Short : INativeConvertible<Short, short>
{
short INativeConvertible<Short, short>.ToCLR()
{
return ShortValue();
}
/// <summary>
/// Returns the <see cref="Short"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="short"/> of CLR</param>
/// <returns>The converted <see cref="Short"/></returns>
public static Short ToJVM(short clrValue)
{
return ValueOf(clrValue);
}

/// <summary>
/// Converter from <see cref="Short"/> to <see cref="short"/>
/// </summary>
Expand Down
111 changes: 110 additions & 1 deletion src/net/JNet/Developed/Java/Lang/String.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
*/

using MASES.JCOBridge.C2JBridge;
using MASES.JNet.Specific.Extensions;
using System.Runtime.CompilerServices;
using SystemNet = System;

namespace Java.Lang
{
public partial class String : JVMBridgeBase<String>, SystemNet.IComparable<String>, SystemNet.IEquatable<String>
public partial class String : JVMBridgeBase<String>, INativeConvertible<String, string>, SystemNet.IComparable<String>, SystemNet.IEquatable<String>
{
#region Constructors
/// <summary>
Expand Down Expand Up @@ -76,6 +77,114 @@ bool SystemNet.IEquatable<String>.Equals(Java.Lang.String other)
return base.Equals(other);
}

string INativeConvertible<String, string>.ToCLR()
{
return ToString();
}
/// <summary>
/// Returns the <see cref="String"/> from the <paramref name="clrValue"/> instance
/// </summary>
/// <param name="clrValue">The <see cref="string"/> of CLR</param>
/// <returns>The converted <see cref="String"/></returns>
public static String ToJVM(string clrValue)
{
return clrValue != null ? new Java.Lang.String(clrValue) : null;
}

#endregion

//#region Enumerable/Array Extensions

///// <summary>
///// Converts an <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="Java.Lang.String"/> to an array of <see cref="string"/>
///// </summary>
///// <param name="set">The <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="Java.Lang.String"/> to be converted</param>
///// <returns>The converted array of <see cref="string"/></returns>
//public static implicit operator string[](Java.Lang.String[] set)
//{
// SystemNet.Collections.Generic.List<string> list = new();
// foreach (var item in set)
// {
// list.Add(item);
// }
// return list.ToArray();
//}

///// <summary>
///// Converts an <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="Java.Lang.String"/> to an array of <see cref="string"/>
///// </summary>
///// <param name="set">The <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="Java.Lang.String"/> to be converted</param>
///// <returns>The converted array of <see cref="string"/></returns>
//public static implicit operator string[](Java.Util.Collection<Java.Lang.String> set)
//{
// SystemNet.Collections.Generic.List<string> list = new();
// foreach (var item in set)
// {
// list.Add(item);
// }
// return list.ToArray();
//}

///// <summary>
///// Converts an <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="Java.Lang.String"/> to an array of <see cref="string"/>
///// </summary>
///// <param name="set">The <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="Java.Lang.String"/> to be converted</param>
///// <returns>The converted array of <see cref="string"/></returns>
//public static implicit operator string[](Java.Lang.Iterable<Java.Lang.String> set)
//{
// SystemNet.Collections.Generic.List<string> list = new();
// foreach (var item in set)
// {
// list.Add(item);
// }
// return list.ToArray();
//}

///// <summary>
///// Converts an <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="string"/> to an <see cref="Java.Util.Collection{T}"/> of <see cref="Java.Lang.String"/>
///// </summary>
///// <param name="set">The <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="string"/> to be converted</param>
///// <returns>The converted <see cref="Java.Util.Collection{T}"/> of <see cref="Java.Lang.String"/></returns>
//public static implicit operator Java.Util.Collection<Java.Lang.String>(string[] set)
//{
// Java.Util.ArrayList<Java.Lang.String> list = new();
// foreach (var item in set)
// {
// list.Add(item);
// }
// return list;
//}

///// <summary>
///// Converts an <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="string"/> to an <see cref="Java.Lang.Iterable{T}"/> of <see cref="Java.Lang.String"/>
///// </summary>
///// <param name="set">The array of <see cref="string"/> to be converted</param>
///// <returns>The converted <see cref="Java.Lang.Iterable{T}"/> of <see cref="Java.Lang.String"/></returns>
//public static implicit operator Java.Lang.Iterable<Java.Lang.String>(string[] set)
//{
// Java.Util.ArrayList<Java.Lang.String> list = new();
// foreach (var item in set)
// {
// list.Add(item);
// }
// return list;
//}

///// <summary>
///// Converts an <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="string"/> to an array of <see cref="Java.Lang.String"/>
///// </summary>
///// <param name="collection">The <see cref="SystemNet.Collections.Generic.IEnumerable{T}"/> of <see cref="string"/> to be converted</param>
///// <returns>The array of <see cref="Java.Lang.String"/></returns>
//public static implicit operator Java.Lang.String[](string[] collection)
//{
// SystemNet.Collections.Generic.List<Java.Lang.String> list = new();
// foreach (var item in collection)
// {
// list.Add(item);
// }
// return list.ToArray();
//}

//#endregion
}
}
Loading