Sorry for my poor English
I added a cases that I missed before to testPropObject
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ToRemObjects
{
public class TestClass
{
double m;
public double testProperty
{
get
{
return m;
}
set
{
m = value;
}
}
}
public class RemObjectsConsole
{
Dictionary<string, object> bag = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
public RemObjectsConsole()
{
}
public double propDouble
{
get { return 1.2D; }
set { Console.WriteLine("propDouble:{0}", value); }
}
public double getDouble()
{
return 1.3D;
}
public void writeDouble(double value)
{
Console.WriteLine("writeDouble:{0}", value);
}
public double getDateAsDouble()
{
return 1357908756.0D;
}
public int getDateAsInt()
{
return 1357908756;
}
public int propInt
{
get { return 150; }
set { Console.WriteLine("propInt:{0}", value); }
}
public int getInt()
{
return 150;
}
public void writeInt(int value)
{
Console.WriteLine("writeInt:{0}", value);
}
public string propString
{
get { return "string.value"; }
set { Console.WriteLine("propString:{0}", (value == null ? "<<null>>" : value)); }
}
public void writeString(string value)
{
Console.WriteLine("writeString:{0}", (value == null ? "<<null>>" : value));
}
public string getString()
{
return "My get string...";
}
public bool propBoolean
{
get { return true; }
set { Console.WriteLine("propBoolean:{0}", value); }
}
public void writeBoolean(bool value)
{
Console.WriteLine("writeBoolean:{0}", value);
}
public bool getBoolean()
{
return true;
}
public DateTime propDate
{
get { return new DateTime(1974, 1, 1); }
set { Console.WriteLine("propDate:{0}", value); }
}
public void writeDate(DateTime value)
{
Console.WriteLine("writeDate:{0}", value);
}
public DateTime getDate()
{
return new DateTime(1974, 1, 1);
}
public object propObject
{
get { return this; }
set { Console.WriteLine("propObject:{0}:{1}", (null == value ? "<<null>>" : value.GetType().Name), (null == value ? "<<null>>" : value)); }
}
public void writeObject(object value)
{
Console.WriteLine("writeObject:{0}:{1}", (null == value ? "<<null>>" : value.GetType().Name), (null == value ? "<<null>>" : value));
}
public override string ToString()
{
return "My Console.ToString to string ...";
}
public void load(string commandText, params object[] parameters)
{
// do somting...
int i = 0;
}
public void load2(string commandText, object[] parameters)
{
// do somting...
int i = 0;
}
public void loadStrings(params string[] parameters)
{
// do somting...
int i = 0;
}
public void loadDoubles(params double[] parameters)
{
// do somting...
int i = 0;
}
public void loadStrings2(string[] parameters)
{
// do somting...
int i = 0;
}
public object this[string name]
{
get
{
object value;
bag.TryGetValue(name, out value);
return value;
}
set
{
bag[name] = value;
}
}
public object this[int index]
{
get
{
object value;
bag.TryGetValue(index.ToString(), out value);
return value;
}
set
{
bag[index.ToString()] = value;
}
}
public void ThrowException()
{
throw new ApplicationException("test exception ....");
}
}
class Program
{
static void Main(string[] args)
{
using (var esc = new RemObjects.Script.EcmaScriptComponent())
{
object o = null;
esc.ExposeType(typeof(TestClass), typeof(TestClass).Name);
esc.Include("test1", @"
function testObj() {
this.toString = function() {
return ‘My testObj.toString …’;
}
}
function testPropString(cc) {
var a;
var z = {a:1,a:2};
var tObj = new testObj();
cc.propString = a;
cc.propString = z;//Exception:Object must implement IConvertible.
cc.propString = tObj;//Exception:Object must implement IConvertible.
cc.writeString(z);//Exception:Object must implement IConvertible.
cc.writeString(tObj);//Exception:Object must implement IConvertible.
cc.propString = undefined;
cc.propString = null;
cc.propString = 1.3;
cc.propString = ‘js.string’;
cc.propString = true;
cc.propString = Number(1.5);
cc.propString = new String(‘js.string’);//Exception:Object must implement IConvertible.
cc.writeString(new String(‘js.string’));
cc.propString = new Boolean(true); //Exception:Object must implement IConvertible.
cc.writeString(new Boolean(true));
cc.propString = new Number(1.5); //Exception:Object must implement IConvertible.
cc.writeString(new Number(1.5));
cc.propString = new Date(); //Exception:Object must implement IConvertible.
cc.writeString(new Date());
cc.propString = new Array(2,1); //Exception:Object must implement IConvertible.
cc.writeString(new Array(2,1)); //Exception:Object must implement IConvertible.
cc.writeObject(cc.propString.substr(0,3));
cc.writeObject(cc.getString().substr(0,3));
cc.writeObject(cc.propString.valueOf());
cc.writeObject(cc.getString().valueOf());
// context is same, meaning also, but different result ???
var ts0 = cc.toString(); // -> ToRemObjects.RemObjectsConsole
var ts1 = cc.ToString(); // -> My Console.ToString to string ...
cc.writeString(ts0);
cc.writeString(ts1);
}
function testPropDouble(cc) {
var a;
cc.propDouble = a;
cc.propDouble = undefined;
cc.propDouble = null;
cc.propDouble = 1.3;
cc.propDouble = 13;
cc.propDouble = ‘1.6’;
cc.propDouble = ‘16’;
cc.propDouble = ‘a’;
cc.propDouble = ‘1.7a’;
cc.propDouble = ‘17a’;
cc.propDouble = true;
cc.propDouble = false;
cc.propDouble = Number(1.5);
cc.propDouble = new Boolean(true);//Exception:Object must implement IConvertible.
cc.writeDouble(new Boolean(true));
cc.propDouble = new Number(1.5);//Exception:Object must implement IConvertible.
cc.writeDouble(new Number(1.5));
cc.propDouble = new Date();//Exception:Object must implement IConvertible.
cc.writeDouble(new Date());
cc.writeDouble( cc.getDouble().valueOf() );//TypeError: number.prototype.valueOf is not generic
cc.writeDouble( cc.propDouble.valueOf() );//TypeError: number.prototype.valueOf is not generic
cc.writeObject(cc.getDouble().toFixed(2));
cc.writeObject(cc.propDouble.toFixed(2));
}
function testPropInt(cc) {
var a;
//cc.propInt = Number.NaN;//OverflowException (Value was either too large or too small for an Int32.), OK
//cc.writeInt(Number.NaN);//OverflowException (Value was either too large or too small for an Int32.), OK
cc.propInt = a;// going to 0???
cc.writeInt(a);// going to 0???
cc.propInt = undefined;// going to 0???
cc.writeInt(undefined);// going to 0???
cc.propInt = null;
cc.writeInt(null);
cc.propInt = ‘45’;
cc.writeInt(‘45’);
cc.propInt = 450;
cc.writeInt(450);
//cc.propInt = ‘47a’; //FormatException(Input string was not in a correct format.) Ok Number(‘47a’) -> NaN, parsing string exactly is OK parseInt(‘47a’), for me behaviour is right
//cc.writeInt(‘47a’); //FormatException(Input string was not in a correct format.) Ok
cc.propInt = ‘3.3’; //FormatException(Input string was not in a correct format.) ??? Number(‘3.3’)->number-> int
cc.writeInt(‘3.3’); //FormatException(Input string was not in a correct format.) ??? Number(‘3.3’)->number-> int
cc.writeInt(Number(‘3.3’)); // but this work why not above one
cc.propInt = true;
cc.writeInt(true);
cc.propInt = false;
cc.writeInt(false);
cc.propInt = new Boolean(false);//Exception:Object must implement IConvertible.
cc.writeInt(new Boolean(false));
cc.propInt = new Boolean(true);//Exception:Object must implement IConvertible.
cc.writeInt(new Boolean(true));
cc.propInt = new Number(1.6);//Exception:Object must implement IConvertible.
cc.writeInt(new Number(1.6));// going to 2??? int i = (int)1.6 -> i==1
cc.propInt = 1.7; // going to 2??? int i = (int)1.6 -> i==1
cc.writeInt(1.7); // going to 2??? int i = (int)1.6 -> i==1
//cc.writeInt(new Date());// exception, OK
cc.getInt().valueOf();//TypeError: number.prototype.valueOf is not generic
cc.propInt.valueOf();//TypeError: number.prototype.valueOf is not generic
cc.writeObject(cc.getInt().toFixed(2));
cc.writeObject(cc.propInt.toFixed(2));
}
function testPropBoolean(cc) {
/*
If the Boolean object has no initial value, or if the passed value is one of the following:
0,-0,null,’’,false,undefined,NaN
the object is set to false. For any other value it is set to true (even with the string ‘false’)!
*/
var o = {};
//cc.propBoolean = o;//Exception:Object must implement IConvertible.
cc.propBoolean = “”"";
cc.writeBoolean("""");
cc.propBoolean = Number.NaN;
cc.writeBoolean(Number.NaN);
cc.propBoolean = 0;
cc.writeBoolean(0);
cc.propBoolean = -0;
cc.writeBoolean(-0);
cc.propBoolean = undefined;
cc.writeBoolean(undefined);
cc.propBoolean = null;
cc.writeBoolean(null);
cc.propBoolean = ‘false’;//true,problem,???
cc.writeBoolean(‘false’);//true,problem,???
cc.propBoolean = new String(‘true’);//Exception:Object must implement IConvertible.
cc.writeBoolean(new String(‘true’));
cc.propBoolean = new Number(1);//Exception:Object must implement IConvertible.
cc.writeBoolean(new Number(1));
cc.propBoolean = true;
cc.writeBoolean(true);
cc.propBoolean = false;
cc.writeBoolean(false);
cc.propBoolean = new Boolean(true);//Exception:Object must implement IConvertible.
cc.writeBoolean(new Boolean(true));
cc.propBoolean = 1;
cc.writeBoolean(1);
cc.propBoolean = 1.6;
cc.writeBoolean(1.6);
cc.writeBoolean(cc.propBoolean.valueOf());
cc.writeBoolean(cc.getBoolean().valueOf());
}
function testPropDate(cc) {
var jsDate = new Date(1968,2,4,1,1,1,1);//js Date object constructor month is zero based??? there is problem,
// this result to 4.2.1968 01:01:02 a need to be 4.3.1968 01:01:01
var strDate = ‘December 17, 1995 03:24:00’;
var jsDateByStr = new Date(strDate);
var jsDateNow = new Date();
var jsDateByNetObj = new Date(cc.propDate);
cc.writeObject(jsDate);cc.writeObject(jsDate.toString());
cc.writeObject(jsDateNow);
cc.writeObject(jsDateByStr);
cc.writeObject(jsDateByNetObj);
cc.propDate = jsDateNow; //Exception:Object must implement IConvertible.
cc.writeDate(jsDateNow);
cc.propDouble = jsDateNow; //Exception:Object must implement IConvertible.
cc.writeDouble(jsDateNow);
cc.propDate = 1357908756.0;
cc.writeDate(1357908756.0);
cc.propDate = cc.getDateAsInt();//Exception:Invalid cast from 'Int32' to 'DateTime'. why this is number as 1357908756.0 and is posible
cc.writeDate(cc.getDateAsInt());//Exception:Invalid cast from 'Int32' to 'DateTime'.
cc.propDate = new Number(2357908756.0); //Exception:Object must implement IConvertible.
cc.writeDate(new Number(2357908756.0));
cc.propDate = strDate;
cc.writeDate(strDate);
cc.propDate = new String(strDate); //Exception:Object must implement IConvertible.
cc.writeDate(new String(strDate));
cc.writeObject(new Date(cc.getDateAsInt()));
cc.writeObject(new Date(cc.getDateAsDouble()));
cc.writeObject(cc.propDate.getFullYear());
cc.writeObject(cc.getDate().getFullYear());
cc.writeObject(cc.propDate.valueOf());
cc.writeObject(cc.getDate().valueOf());
}
function testPropObject(cc) {
var a;
cc.propObject = a;
cc.writeObject(a);
cc.propObject = undefined;
cc.writeObject(undefined);
cc.propObject = null;
cc.writeObject(null);
cc.propObject = {a: 1, b: ‘ss’};
cc.writeObject({a: 1, b: ‘ss’});
cc.propObject = 1.4;
cc.writeObject(1.3);
cc.propObject = false;
cc.writeObject(false);
cc.propObject = Number(1.5);
cc.writeObject(Number(1.5));
cc.propObject = new String(‘str’);// result to EcmaScriptObject differnt from method call
cc.writeObject(new String(‘str’));// result to String
cc.propObject = new Boolean(false);// result to EcmaScriptObject differnt from method call
cc.writeObject(new Boolean(false));// result to Boolean
cc.propObject = new Number(1.5);// result to EcmaScriptObject differnt from method call
cc.writeObject(new Number(1.5));// result to Double
cc.propObject = new Date();// result to EcmaScriptObject differnt from method call
cc.writeObject(new Date());// result to DateTime
cc.propObject = new Array();
cc.writeObject(new Array());
cc.writeObject( cc.getDate() );
cc.writeObject( cc.getDate().valueOf() );
cc.writeObject( new Date(cc.getDate()) );
cc.writeObject( new Date(cc.getDate()).valueOf() );
cc.writeObject( cc.getDouble() );
//cc.writeObject( cc.getDouble().valueOf() );//TypeError: number.prototype.valueOf is not generic
cc.writeObject( new Number(cc.getDouble()) );
cc.writeObject( new Number(cc.getDouble()).valueOf() );
cc.writeObject( cc.getBoolean() );
cc.writeObject( cc.getBoolean().valueOf() );
cc.writeObject( new Boolean(cc.getBoolean()) );
cc.writeObject( new Boolean(cc.getBoolean()).valueOf() );
cc.writeObject( cc.getString() );
cc.writeObject( cc.getString().valueOf() );
cc.writeObject( new String(cc.getString()) );
cc.writeObject( new String(cc.getString()).valueOf() );
cc.writeObject( cc.getInt() );
//cc.writeObject( cc.getInt().valueOf() );//TypeError: number.prototype.valueOf is not generic
cc.writeObject( new Number(cc.getInt()) );
cc.writeObject( new Number(cc.getInt()).valueOf() );
cc.writeObject( 12 );
}
function testSomeOthers(cc) {
cc.load(‘command text’, 1.2,‘ss’,new Date(), true);
cc.load(‘command text’, [10, 1.2,‘ss’,new Date(), true]); //going to one addional parameter of type array,
// if second parameter is one (no third) and is of type array then
// call function without makeing new array from array, I don’t this can be done and is right
//cc.load2(‘command text’, [10, 1.2,‘ss’,new Date(), true]);