2017-03-05 23:44:37 +01:00
|
|
|
// Copyright © 2010-2017 The CefSharp Authors. All rights reserved.
|
2015-08-03 10:41:29 +10:00
|
|
|
//
|
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-03-22 09:00:52 +08:00
|
|
|
using System.Collections;
|
2017-12-21 13:00:36 +10:00
|
|
|
using System.Collections.Generic;
|
2015-08-03 11:37:49 +10:00
|
|
|
using System.Diagnostics;
|
2017-12-21 13:00:36 +10:00
|
|
|
using System.Text;
|
2015-07-29 13:39:07 +02:00
|
|
|
using System.Threading;
|
|
|
|
|
|
|
|
|
|
namespace CefSharp.Example
|
|
|
|
|
{
|
|
|
|
|
public class AsyncBoundObject
|
|
|
|
|
{
|
2015-08-03 11:37:49 +10:00
|
|
|
//We expect an exception here, so tell VS to ignore
|
|
|
|
|
[DebuggerHidden]
|
2015-07-29 13:39:07 +02:00
|
|
|
public void Error()
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("This is an exception coming from C#");
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-03 11:37:49 +10:00
|
|
|
//We expect an exception here, so tell VS to ignore
|
|
|
|
|
[DebuggerHidden]
|
2015-07-29 13:39:07 +02:00
|
|
|
public int Div(int divident, int divisor)
|
|
|
|
|
{
|
|
|
|
|
return divident / divisor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Hello(string name)
|
|
|
|
|
{
|
|
|
|
|
return "Hello " + name;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 13:00:36 +10:00
|
|
|
public string DoSomething()
|
2015-07-29 13:39:07 +02:00
|
|
|
{
|
|
|
|
|
Thread.Sleep(1000);
|
2017-12-21 13:00:36 +10:00
|
|
|
|
|
|
|
|
return "Waited for 1000ms before returning";
|
2015-07-29 13:39:07 +02:00
|
|
|
}
|
2017-03-13 11:37:55 +00:00
|
|
|
|
2018-01-08 15:12:52 +10:00
|
|
|
public JsSerializableStruct ReturnObject(string name)
|
2017-10-23 14:24:04 +05:00
|
|
|
{
|
2018-01-08 15:12:52 +10:00
|
|
|
return new JsSerializableStruct
|
2017-10-23 14:24:04 +05:00
|
|
|
{
|
|
|
|
|
Value = name
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-05 12:20:02 +10:00
|
|
|
public JsSerializableClass ReturnClass(string name)
|
|
|
|
|
{
|
|
|
|
|
return new JsSerializableClass
|
|
|
|
|
{
|
|
|
|
|
Value = name
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-08 15:12:52 +10:00
|
|
|
public JsSerializableStruct[] ReturnStructArray(string name)
|
2017-03-13 11:37:55 +00:00
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
2018-01-08 15:12:52 +10:00
|
|
|
new JsSerializableStruct { Value = name + "Item1" },
|
|
|
|
|
new JsSerializableStruct { Value = name + "Item2" }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public JsSerializableClass[] ReturnClassesArray(string name)
|
|
|
|
|
{
|
|
|
|
|
return new[]
|
|
|
|
|
{
|
|
|
|
|
new JsSerializableClass { Value = name + "Item1" },
|
|
|
|
|
new JsSerializableClass { Value = name + "Item2" }
|
2017-03-13 11:37:55 +00:00
|
|
|
};
|
|
|
|
|
}
|
2017-12-21 13:00:36 +10:00
|
|
|
|
2018-01-18 01:46:58 +00:00
|
|
|
public string[] EchoArray(string[] arg)
|
|
|
|
|
{
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[] EchoValueTypeArray(int[] arg)
|
|
|
|
|
{
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int[][] EchoMultidimensionalArray(int[][] arg)
|
|
|
|
|
{
|
|
|
|
|
return arg;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 13:00:36 +10:00
|
|
|
public string DynamiObjectList(IList<dynamic> objects)
|
|
|
|
|
{
|
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
foreach(var browser in objects)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("Browser(Name:" + browser.Name + ";Engine:" + browser.Engine.Name + ");");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return builder.ToString();
|
|
|
|
|
}
|
2018-03-22 09:00:52 +08:00
|
|
|
|
|
|
|
|
public Dictionary<string, int> MethodReturnsDictionary1()
|
|
|
|
|
{
|
|
|
|
|
return new Dictionary<string, int>()
|
|
|
|
|
{
|
|
|
|
|
{"five", 5},
|
|
|
|
|
{"ten", 10}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, object> MethodReturnsDictionary2()
|
|
|
|
|
{
|
|
|
|
|
return new Dictionary<string, object>()
|
|
|
|
|
{
|
|
|
|
|
{"onepointfive", 1.5},
|
|
|
|
|
{"five", 5},
|
|
|
|
|
{"ten", "ten"},
|
|
|
|
|
{"twotwo", new Int32[]{2, 2} }
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Dictionary<string, IDictionary> MethodReturnsDictionary3()
|
|
|
|
|
{
|
|
|
|
|
return new Dictionary<string, IDictionary>()
|
|
|
|
|
{
|
|
|
|
|
{"data", MethodReturnsDictionary2()}
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-07-29 13:39:07 +02:00
|
|
|
}
|
|
|
|
|
}
|