/// <exception cref="TjsException"></exception> /// <exception cref="VariantException"></exception> private static void GetOctetProperty(Variant result, Variant octet, Variant member ) { // processes properties toward octets. if (member.IsNumber() != true) { string name = member.GetString(); if (name == null) { ThrowFrom_tjs_error(Error.E_MEMBERNOTFOUND, string.Empty); } if (name.Equals("length")) { // get string length ByteBuffer o = octet.AsOctet(); if (o != null) { result.Set(o.Capacity()); } else { result.Set(0); } return; } else { if (name[0] >= '0' && name[0] <= '9') { ByteBuffer o = octet.AsOctet(); int n = int.Parse(name); int len = o != null?o.Capacity() : 0; if (n < 0 || n >= len) { throw new TjsException(Error.RangeError); } result.Set(o.Get(n)); return; } } ThrowFrom_tjs_error(Error.E_MEMBERNOTFOUND, name); } else { // member.Type() == tvtInteger || member.Type() == tvtReal ByteBuffer o = octet.AsOctet(); int n = member.AsInteger(); int len = o != null?o.Capacity() : 0; if (n < 0 || n >= len) { throw new TjsException(Error.RangeError); } result.Set(o.Get(n)); return; } }
/// <exception cref="TjsException"></exception> /// <exception cref="VariantException"></exception> private static void GetOctetProperty(Variant result, Variant octet, int n) { // processes properties toward octets. ByteBuffer o = octet.AsOctet(); int len = o != null?o.Capacity() : 0; if (n < 0 || n >= len) { throw new TjsException(Error.RangeError); } result.Set(o.Get(n)); return; }
/// <exception cref="VariantException"></exception> public static string VariantToExpressionString(Variant val) { // convert given variant to string which can be interpret as an expression. // this function does not convert objects ( returns empty string ) if (val.IsVoid()) { return("void"); } else { if (val.IsInteger()) { return(val.AsString()); } else { if (val.IsReal()) { string s = Variant.RealToHexString(val.AsDouble()); return(s + " /* " + val.AsString() + " */"); } else { if (val.IsString()) { string s = LexBase.EscapeC(val.AsString()); return("\"" + s + "\""); } else { if (val.IsOctet()) { string s = Variant.OctetToListString(val.AsOctet()); return("<%" + s + "%>"); } else { return(string.Empty); } } } } } }
/// <exception cref="VariantException"></exception> public static object[] VariantArrayToJavaObjectArray(Variant[] @params, Type[] types) { if (types.Length == 0) { return(null); } // 元々引数不要 if (@params.Length < types.Length) { return(null); } // パラメータが少ない int count = types.Length; object[] ret = new object[count]; for (int i = 0; i < count; i++) { Type type = types[i]; Variant param = @params[i]; if (type.GetTypeInfo().IsPrimitive) { // プリミティブタイプの场合 if (type == typeof(int)) { ret[i] = Extensions.ValueOf(param.AsInteger()); } else if (type == typeof(double)) { ret[i] = (param.AsDouble()); } else if (type == typeof(bool)) { ret[i] = Extensions.ValueOf(param.AsInteger() != 0); } else if (type == typeof(float)) { ret[i] = ((float)param.AsDouble()); } else if (type == typeof(long)) { ret[i] = Extensions.ValueOf(param.AsInteger()); } else if (type == typeof(char)) { ret[i] = ((char)param.AsInteger()); } else if (type == typeof(byte)) { ret[i] = (unchecked ((byte)param.AsInteger())); } else if (type == typeof(short)) { ret[i] = ((short)param.AsInteger()); } else { // may be Void.TYPE ret[i] = null; } } else if (type == typeof(string)) { ret[i] = param.AsString(); } else if (type == typeof(ByteBuffer)) { ret[i] = param.AsOctet(); } else if (type == typeof(Variant)) { ret[i] = param; } else if (type == typeof(VariantClosure)) { ret[i] = param.AsObjectClosure(); } else if (type == typeof(Dispatch2)) { ret[i] = param.AsObject(); } else if (type == param.ToJavaObject().GetType()) { ret[i] = param.ToJavaObject(); } else { // その他 のクラス ret[i] = null; } } return(ret); }
/// <exception cref="VariantException"></exception> public static object VariantToJavaObject(Variant param, Type type) { if (type.GetTypeInfo().IsPrimitive) { // プリミティブタイプの场合 if (type == typeof(int)) { return(Extensions.ValueOf(param.AsInteger())); } if (type == typeof(double)) { return(param.AsDouble()); } if (type == typeof(bool)) { return(Extensions.ValueOf(param.AsInteger() != 0)); } if (type == typeof(float)) { return((float)param.AsDouble()); } if (type == typeof(long)) { return(Extensions.ValueOf(param.AsInteger())); } if (type == typeof(char)) { return((char)param.AsInteger()); } if (type == typeof(byte)) { return(unchecked ((byte)param.AsInteger())); } if (type == typeof(short)) { return((short)param.AsInteger()); } // may be Void.TYPE return(null); } if (type == typeof(string)) { return(param.AsString()); } if (type == typeof(ByteBuffer)) { return(param.AsOctet()); } if (type == typeof(Variant)) { return(param); } if (type == typeof(VariantClosure)) { return(param.AsObjectClosure()); } if (type == typeof(Dispatch2)) { return(param.AsObject()); } if (type == param.ToJavaObject().GetType()) { return(param.ToJavaObject()); } // その他 のクラス return(null); }
/// <exception cref="VariantException"></exception> public static string VariantToReadableString(Variant val, int maxlen) { string ret = null; if (val == null || val.IsVoid()) { ret = "(void)"; } else { if (val.IsInteger()) { ret = "(int)" + val.AsString(); } else { if (val.IsReal()) { ret = "(real)" + val.AsString(); } else { if (val.IsString()) { ret = "(string)\"" + LexBase.EscapeC(val.AsString()) + "\""; } else { if (val.IsOctet()) { ret = "(octet)<% " + Variant.OctetToListString(val.AsOctet()) + " %>"; } else { if (val.IsObject()) { VariantClosure c = (VariantClosure)val.AsObjectClosure(); StringBuilder str = new StringBuilder(128); str.Append("(object)"); str.Append('('); if (c.mObject != null) { str.Append('['); if (c.mObject is NativeClass) { str.Append(((NativeClass)c.mObject).GetClassName()); } else { if (c.mObject is InterCodeObject) { str.Append(((InterCodeObject)c.mObject).GetName()); } else { if (c.mObject is CustomObject) { string name = ((CustomObject)c.mObject).GetClassNames(); if (name != null) { str.Append(name); } else { str.Append(c.mObject.GetType().FullName); } } else { str.Append(c.mObject.GetType().FullName); } } } str.Append(']'); } else { str.Append("0x00000000"); } if (c.mObjThis != null) { str.Append('['); if (c.mObjThis is NativeClass) { str.Append(((NativeClass)c.mObjThis).GetClassName()); } else { if (c.mObjThis is InterCodeObject) { str.Append(((InterCodeObject)c.mObjThis).GetName()); } else { if (c.mObjThis is CustomObject) { string name = ((CustomObject)c.mObjThis).GetClassNames(); if (name != null) { str.Append(name); } else { str.Append(c.mObjThis.GetType().FullName); } } else { str.Append(c.mObjThis.GetType().FullName); } } } str.Append(']'); } else { str.Append(":0x00000000"); } str.Append(')'); ret = str.ToString(); } else { // native object ? ret = "(octet) [" + val.GetType().FullName + "]"; } } } } } } if (ret != null) { if (ret.Length > maxlen) { return(Sharpen.Runtime.Substring(ret, 0, maxlen)); } else { return(ret); } } return(string.Empty); }