Skip to content

Instantly share code, notes, and snippets.

@vendettamit
vendettamit / CustomAppDomain.cs
Created September 20, 2014 14:51
Creating custom AppDomain
public class DomainController
{
public void CreateDomain()
{
string pathToDlls = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
Trace.WriteLine(AppDomain.CurrentDomain.FriendlyName);
AppDomainSetup domainSetup = new AppDomainSetup { };
domainSetup.ApplicationBase = pathToDlls;
this.testDomain = AppDomain.CreateDomain(Guid.NewGuid().ToString(), null, domainSetup, this.GetPermissionSet());
@vendettamit
vendettamit / AssemblyLoader.cs
Created September 20, 2014 15:01
Load Assembly in AppDomain
this.testDomain.Load(Assembly.GetExecutingAssembly().GetName());
var instance = (CompilerService)this.testDomain.CreateInstanceAndUnwrap(
typeof(CompilerService).Assembly.FullName,
typeof(CompilerService).FullName);
return instance.CompileAndRunTestsInOtherDomain(args);
public class LogInjectionModule : Module {
protected override void AttachToComponentRegistration(IComponentRegistry registry,
IComponentRegistration registration) {
registration.Preparing += OnComponentPreparing;
var implementationType = registration.Activator.LimitType;
var injectors = BuildInjectors(implementationType).ToArray();
if (!injectors.Any()) {
return;
public class DynamicParserJson
{
public static object ConvertJTokenToObject(JToken token)
{
if (token is JValue)
{
return ((JValue)token).Value;
}
if (token is JObject)
{
@vendettamit
vendettamit / MethodInterceptionViaAttributesDynamicProxy.cs
Created September 2, 2015 20:26
Method interception via attributes using dynamic proxy. Argument null checking at run time via method attributes. DynamicProxy2, Castle Core.
public class Program
{
static void Main(string[] args)
{
Bootstrapper.Configure();
var container = Bootstrapper.Container;
var obj = container.Resolve<Program>();
var newString = obj.UseMe(null);
@vendettamit
vendettamit / ThreadSwitchingWithAutoResetEvent.cs
Created September 3, 2015 18:23
Sample is to show the Thread switching using AutoResetEvent.
public class DeviceMonitorSignaling
{
readonly object _lockObj = new object();
EventWaitHandle searchingHandle;
EventWaitHandle monitoringHandle;
bool _running;
bool _monitoring;
volatile Device device;
@vendettamit
vendettamit / AppbootStrapper_CaliburnMicro_SimpleInjector.cs
Created September 10, 2015 23:20
A sample bootstrapper for Caliburn micro and SimpleInjector 3.0 migration changes.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Caliburn.Micro;
using SimpleInjector;
using System.Reflection;
using StackQuestionsClient.ViewModels;
using StackQuestionsClient.utilities;
@vendettamit
vendettamit / StringToValueTypeConverterTests.cs
Created September 11, 2015 15:54
A set of tests writter in NUnit to test a simple String to ValueType Converter.
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TestForEverything.Converters;
namespace TestForEverything
{
@vendettamit
vendettamit / StringToValueTypeConverter.cs
Last active September 11, 2015 15:59
A simple string to valuetype converter using TypeDescriptor.
using System;
using System.ComponentModel;
namespace TestForEverything
{
/// <summary>
/// Extension methos of string providing conversions to primitve types
/// </summary>
public static class ConverterExtensions
{
@vendettamit
vendettamit / Roslyncompiler.cs
Created September 24, 2015 21:12
Run time compilation with Microsoft.CodeAnalysis(Roslyn) services
class Program
{
private static readonly IEnumerable<string> DefaultNamespaces =
new[]
{
"System",
"System.IO",
"System.Net",
"System.Linq",
"System.Text",