1
0
mirror of https://github.com/twiglet/cs2j.git synced 2025-01-18 13:15:17 +01:00

support GetTypeCode()

This commit is contained in:
Kevin Glynn 2011-08-16 10:33:59 +02:00
parent b24ce95c44
commit e7b093ba6c
4 changed files with 237 additions and 6 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
@ -101,6 +101,20 @@
<Name>InvokeMember</Name>
<Return>System.Object</Return>
</Method>
<Method>
<Imports>
<Import>CS2JNet.System.TypeSupport</Import>
</Imports>
<Java>TypeSupport.GetTypeCode(${type})</Java>
<Params>
<Param>
<Type>System.Type</Type>
<Name>type</Name>
</Param>
</Params>
<Name>GetTypeCode</Name>
<Return>System.TypeCode</Return>
</Method>
</Methods>
<Properties>
<Property>

View File

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is
Copyright 2007,2008,2009,2010 Rustici Software, LLC
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
-->
<Enum xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:www.twigletsoftware.com:schemas:txtemplate:1:0">
<Imports>
<Import>CS2JNet.System.TypeCode</Import>
</Imports>
<Java>TypeCode</Java>
<Name>System.TypeCode</Name>
<Inherits>
<Type>System.Enum</Type>
</Inherits>
<Members>
<Member>
<Java>${this:16}.Empty</Java>
<Name>Empty</Name>
</Member>
<Member>
<Java>${this:16}.Object</Java>
<Name>Object</Name>
</Member>
<Member>
<Java>${this:16}.DBNull</Java>
<Name>DBNull</Name>
</Member>
<Member>
<Java>${this:16}.Boolean</Java>
<Name>Boolean</Name>
</Member>
<Member>
<Java>${this:16}.Char</Java>
<Name>Char</Name>
</Member>
<Member>
<Java>${this:16}.SByte</Java>
<Name>SByte</Name>
</Member>
<Member>
<Java>${this:16}.Byte</Java>
<Name>Byte</Name>
</Member>
<Member>
<Java>${this:16}.Int16</Java>
<Name>Int16</Name>
</Member>
<Member>
<Java>${this:16}.UInt16</Java>
<Name>UInt16</Name>
</Member>
<Member>
<Java>${this:16}.Int32</Java>
<Name>Int32</Name>
</Member>
<Member>
<Java>${this:16}.UInt32</Java>
<Name>UInt32</Name>
</Member>
<Member>
<Java>${this:16}.Int64</Java>
<Name>Int64</Name>
</Member>
<Member>
<Java>${this:16}.UInt64</Java>
<Name>UInt64</Name>
</Member>
<Member>
<Java>${this:16}.Single</Java>
<Name>Single</Name>
</Member>
<Member>
<Java>${this:16}.Double</Java>
<Name>Double</Name>
</Member>
<Member>
<Java>${this:16}.Decimal</Java>
<Name>Decimal</Name>
</Member>
<Member>
<Java>${this:16}.DateTime</Java>
<Name>DateTime</Name>
</Member>
<Member>
<Java>${this:16}.String</Java>
<Name>String</Name>
</Member>
</Members>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" /><DigestValue>mo6ChmPjcAlAo0NBWLLZbsocykw=</DigestValue></Reference></SignedInfo><SignatureValue>RlUioSuamZxr9dmH+n+zDAoS31RAR3VRqGwbq0J8Ew28sRdZoXTjz2yJwWvSZIzMRNeMc0v8VZbLRMEM39bSKH51gWKuQ8TFyzTBwMzQDeDsNO5kzdxcE1DYGnZKKplPDKPM8n9mlpuDYginKU8dk3dA/CtPgAmc7X90AuPIhew=</SignatureValue></Signature></Enum>

View File

@ -0,0 +1,46 @@
/*
Copyright 2010,2011 Kevin Glynn (kevin.glynn@twigletsoftware.com)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Author(s):
Kevin Glynn (kevin.glynn@twigletsoftware.com)
*/
package CS2JNet.System;
/**
* @author keving
*
*/
public enum TypeCode {
Empty, // A null reference.
Object, // A general type representing any reference or value type not explicitly represented by another TypeCode.
DBNull, // A database null (column) value.
Boolean, // A simple type representing Boolean values of true or false.
Char, // An integral type representing unsigned 16-bit integers with values between 0 and 65535. The set of possible values for the Char type corresponds to the Unicode character set.
SByte, // An integral type representing signed 8-bit integers with values between -128 and 127.
Byte, // An integral type representing unsigned 8-bit integers with values between 0 and 255.
Int16, // An integral type representing signed 16-bit integers with values between -32768 and 32767.
UInt16, // An integral type representing unsigned 16-bit integers with values between 0 and 65535.
Int32, // An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.
UInt32, // An integral type representing unsigned 32-bit integers with values between 0 and 4294967295.
Int64, // An integral type representing signed 64-bit integers with values between -9223372036854775808 and 9223372036854775807.
UInt64, // An integral type representing unsigned 64-bit integers with values between 0 and 18446744073709551615.
Single, // A floating point type representing values ranging from approximately 1.5 x 10 -45 to 3.4 x 10 38 with a precision of 7 digits.
Double, // A floating point type representing values ranging from approximately 5.0 x 10 -324 to 1.7 x 10 308 with a precision of 15-16 digits.
Decimal, // A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 significant digits.
DateTime, // A type representing a date and time value.
String // A sealed class type representing Unicode character strings.
}

View File

@ -32,6 +32,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import CS2JNet.System.Reflection.BindingFlags;
@ -169,9 +170,86 @@ public class TypeSupport {
}
}
public static Field GetField(Class myType,
String fieldName) throws NoSuchFieldException, Exception {
return GetField(myType, fieldName, BindingFlags.getDefault());
}
public static Field GetField(Class myType,
String fieldName) throws NoSuchFieldException, Exception {
return GetField(myType, fieldName, BindingFlags.getDefault());
}
public static TypeCode GetTypeCode(Class myType) {
TypeCode ret = TypeCode.Object;
if (myType.isPrimitive()) {
if (myType.equals(Boolean.TYPE)) {
ret = TypeCode.Boolean;
}
else if (myType.equals(Character.TYPE)) {
ret = TypeCode.Char;
}
else if (myType.equals(Byte.TYPE)) {
ret = TypeCode.Byte;
}
else if (myType.equals(Short.TYPE)) {
ret = TypeCode.Int16;
}
else if (myType.equals(Integer.TYPE)) {
ret = TypeCode.Int32;
}
else if (myType.equals(Long.TYPE)) {
ret = TypeCode.Int64;
}
else if (myType.equals(Float.TYPE)) {
ret = TypeCode.Single;
}
else if (myType.equals(Double.TYPE)) {
ret = TypeCode.Double;
}
else if (myType.equals(Void.TYPE)) {
// No equivalent, return object I guess
}
}
else {
if (myType.isInstance(Boolean.FALSE)) {
ret = TypeCode.Boolean;
}
else if (myType.isInstance(Character.MAX_VALUE)) {
ret = TypeCode.Char;
}
else if (myType.isInstance(Byte.MAX_VALUE)) {
ret = TypeCode.Byte;
}
else if (myType.isInstance(Short.MAX_VALUE)) {
ret = TypeCode.Int16;
}
else if (myType.isInstance(Integer.MAX_VALUE)) {
ret = TypeCode.Int32;
}
else if (myType.isInstance(Long.MAX_VALUE)) {
ret = TypeCode.Int64;
}
else if (myType.isInstance(Float.MAX_VALUE)) {
ret = TypeCode.Single;
}
else if (myType.isInstance(Double.MAX_VALUE)) {
ret = TypeCode.Double;
}
else if (myType.isInstance(new Date())) {
ret = TypeCode.Double;
}
else if (myType.isInstance("")) {
ret = TypeCode.String;
}
}
return ret;
}
public static void Testmain(String[] args)
{
Boolean b = true;
int i = 0;
System.out.println(TypeCode.Boolean);
System.out.println(GetTypeCode(b.getClass()));
System.out.println(GetTypeCode(((Integer)i).getClass()));
}
}