Skip to content

Instantly share code, notes, and snippets.

@DinisCruz
DinisCruz / gist:2776587
Created May 23, 2012 17:40
First script that loads Chrome inside O2 (via CefSharp)
var webView = new WebView("http://www.whatismybrowser.com", new BrowserSettings());
panel.invokeOnThread(
()=>{
try
{
webView.Dock = DockStyle.Fill;
panel.clear().Controls.Add(webView);
}
catch(Exception ex)
@DinisCruz
DinisCruz / gist:2776687
Created May 23, 2012 17:57
Trying 4.0 C# ExpandoObject
dynamic expando = new ExpandoObject();
expando.Name = "John";
expando.Speak = new Func<string>(()=> { return "Hi " + expando.Name;});
return expando.Speak();
//using System.Dynamic;
//O2Ref:System.Core.dll
//O2Ref:Microsoft.CSharp.dll
@DinisCruz
DinisCruz / gist:2823628
Created May 29, 2012 09:56
Chrome WPF control with zoom
//var webView = new WebView("http://www.whatismybrowser.com", new BrowserSettings());
var topPanel = panel.clear().add_Panel();
var autoResetEvent = new AutoResetEvent(false);
var webView = (WebView)topPanel.invokeOnThread(
()=>{
//var _webView = new WebView("http://about:blank", new BrowserSettings());
var elementHost = topPanel.add_WPF_Host();
var zoom = elementHost.add_Zoom();
var _webView = zoom.set<WebView>();
@DinisCruz
DinisCruz / gist:2840056
Created May 31, 2012 01:13
O2 Script to Inject Snoop into process with WPF control
//return "Util - DiagramDesigner Editor.h2".local().startProcess();
var process = "O2 Xaml Editor (PoC).h2".local().startProcess();
this.sleep(2000);
var hwnd = process.MainWindowHandle;
if (hwnd == IntPtr.Zero)
return "Could not get MainWindow handle";
"Got main Window Handle: {0}".info(hwnd);
var snoopAssembly = @"Snoop\Snoop.exe".assembly();
@DinisCruz
DinisCruz / gist:2903012
Created June 9, 2012 23:19
O2 Script to show Roslyn Ast Error detection capabilities
//var topPanel = panel.clear().add_Panel();
var topPanel = "Simple AstTester".popupWindow(700,300);
var codeViewer = topPanel.title("Code").add_SourceCodeViewer();
var errorsList = topPanel.insert_Right(300,"AstTree Errors").add_TextArea();
Action<string> showErrors =
(newCode)=>{
codeViewer.editor().clearBookmarksAndMarkers();
var astTree = newCode.tree();
var errors = astTree.errors();
foreach(var error in errors)
@DinisCruz
DinisCruz / gist:2909541
Created June 11, 2012 10:50
O2 Script to use Roslyn to Dynamically compile and execute a method
panel.clear().add_ConsoleOut();
var code = @"
using System;
class Greeter
{
static string Greet()
{
Console.WriteLine(""Hello, World"");
return ""hello from here"";
}
@DinisCruz
DinisCruz / gist:2909592
Created June 11, 2012 11:01
O2 Script to use Roslyn to Dynamically compile and execute a method (Simpler version)
panel.clear().add_ConsoleOut();
var code = @"
using System;
class Greeter
{
static string Greet()
{
Console.WriteLine(""Hello, World!!!"");
return ""Another hello"";
}
@DinisCruz
DinisCruz / gist:2909612
Created June 11, 2012 11:09
O2 Script to use Roslyn to Dynamically compile and execute a method (in one line)
return @"using System; class Greeter { static string Greet() { return ""Another hello!!""; }}"
.tree().compiler("Great").create_Assembly().type("Greeter").invokeStatic("Greet");
//O2Ref:O2_FluentSharp_Roslyn.dll
@DinisCruz
DinisCruz / gist:2911643
Created June 11, 2012 17:59
O2 Script - Refactored Roslyn 'AddingMethodToClass' method
var code = @"
class C
{
}";
// Get ClassDeclarationSyntax corresponding to 'class C' above.
var classDeclaration = code.astTree()
.compilationUnit()
.classes().first();
@DinisCruz
DinisCruz / gist:2911647
Created June 11, 2012 18:00
O2 Script - Original Roslyn 'AddingMethodToClass' method
var tree = SyntaxTree.ParseCompilationUnit(@"
class C
{
}");
var compilationUnit = (CompilationUnitSyntax)tree.GetRoot();
// Get ClassDeclarationSyntax corresponding to 'class C' above.
ClassDeclarationSyntax classDeclaration = compilationUnit.ChildNodes()
.OfType<ClassDeclarationSyntax>().Single();