Skip to content

Instantly share code, notes, and snippets.

@vendettamit
vendettamit / AssemblyLoader.cs
Created Sep 20, 2014
Load Assembly in AppDomain
View AssemblyLoader.cs
this.testDomain.Load(Assembly.GetExecutingAssembly().GetName());
var instance = (CompilerService)this.testDomain.CreateInstanceAndUnwrap(
typeof(CompilerService).Assembly.FullName,
typeof(CompilerService).FullName);
return instance.CompileAndRunTestsInOtherDomain(args);
@vendettamit
vendettamit / CustomAppDomain.cs
Created Sep 20, 2014
Creating custom AppDomain
View CustomAppDomain.cs
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());
View LogInjectionModule
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;
View JsonToDynamicObjectSerialization.cs
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 Sep 2, 2015
Method interception via attributes using dynamic proxy. Argument null checking at run time via method attributes. DynamicProxy2, Castle Core.
View MethodInterceptionViaAttributesDynamicProxy.cs
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 Sep 3, 2015
Sample is to show the Thread switching using AutoResetEvent.
View ThreadSwitchingWithAutoResetEvent.cs
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 Sep 10, 2015
A sample bootstrapper for Caliburn micro and SimpleInjector 3.0 migration changes.
View AppbootStrapper_CaliburnMicro_SimpleInjector.cs
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 Sep 11, 2015
A set of tests writter in NUnit to test a simple String to ValueType Converter.
View StringToValueTypeConverterTests.cs
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 Sep 11, 2015
A simple string to valuetype converter using TypeDescriptor.
View StringToValueTypeConverter.cs
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 Sep 24, 2015
Run time compilation with Microsoft.CodeAnalysis(Roslyn) services
View Roslyncompiler.cs
class Program
{
private static readonly IEnumerable<string> DefaultNamespaces =
new[]
{
"System",
"System.IO",
"System.Net",
"System.Linq",
"System.Text",
You can’t perform that action at this time.