New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: TheCodeJunkie
C#
public interface IRuleMetadata
{
    [DefaultValue(0)]
    int ExecutionOrder { get; }
}
 
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class RuleAttribute : ExportAttribute, IRuleMetadata
{
    public RuleAttribute(int executionOrder)
by TheCodeJunkie   February 13, 2010 @ 3:30pm
Tags: MEF
33 Views
no comments
 
C#
public class LoggerRegistry : PartRegistry
{
    public LoggerRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.GetInterfaces().Contains(typeof(ILogger)))
            .Exports(x => x.Export<ExportConvention>()
                .ContractType<ILogger>()
                .ContractName<ILogger>()
                .Members(m => new[] { m }))
by TheCodeJunkie   February 08, 2010 @ 2:38pm
Tags: MEF
29 Views
no comments
 
C#
public class ConventionPart<T> : IPartImportsSatisfiedNotification
{
    /// <summary>
    /// Initializes a new instance of the <see cref="ConventionPart{T}"/> class.
    /// </summary>
    public ConventionPart()
    {
    }
 
    [ImportMany]
by TheCodeJunkie   February 07, 2010 @ 3:14pm
Tags: MEF
52 Views
no comments
 
C#
public class FakeConventionRegistry :  ConventionRegistry
{
    public FakeConventionRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.IsPublic && x.IsAbstract == false)
            .MakeShared()
            .Imports(x =>
            {
                x.Import<ImportConvention>()
by TheCodeJunkie   February 01, 2010 @ 1:33pm
Tags:
11 Views
no comments
 
C#
public class MyConventionRegistry : ConventionRegistry
{
    public MyConventionRegistry()
    {
        Part<PartConvention>()
            .ForTypesMatching(x => x.Name.StartsWith("Foo"))
            .MakeNonShared()
            .Imports(i =>
            {
                i.Import<ImportConvention>().As<IImportConvention>();
by TheCodeJunkie   February 01, 2010 @ 2:08am
Tags:
11 Views
no comments
 
C#
private static void SetSingleValue(MemberInfo member, object instance, IEnumerable<object> value)
{
    switch (member.MemberType)
    {
        case MemberTypes.Field:
            ((FieldInfo)member).SetValue(instance, value.First());
            break;
 
        case MemberTypes.Property:
            ((PropertyInfo)member).SetValue(instance, value.First(), null);
by TheCodeJunkie   January 31, 2010 @ 3:13pm
Tags:
47 Views
1 comments
 
C#
public class Container
{
    protected Container()
    {
        this.Foos = new List<IFooBuilder>();
    }
 
    public IList<IFooBuilder> Foos { get; set; }
 
    public FooBuilder<T> Foo<T>() where T : IFoo, new()
by TheCodeJunkie   January 29, 2010 @ 2:02pm
Tags:
41 Views
2 comments
 
C#
public interface IExpressionBuilder<T>
{
    T GetInstanceFromExpression();
}
 
public interface IImportConventionExpressionBuilder<TImportConvention> :
    IExpressionBuilder<TImportConvention> where TImportConvention : IImportConvention, new()
{
    IImportConventionExpressionBuilder<TImportConvention> AllowDefaultValue();
by TheCodeJunkie   January 25, 2010 @ 1:29pm
Tags:
16 Views
no comments
 
C#
public class FluentBuilder : IFluentBuilder
{
    public FluentBuilder()
    {
        this.Convention = new TestExportConvention();
    }
 
    private ITestExportConvention Convention { get; set; }
 
    public IFluentBuilder Export<T>(Expression<Func<T, object>> expression)
by TheCodeJunkie   January 14, 2010 @ 11:19pm
Tags:
26 Views
no comments
 
C#
public class MefIntegrationTests
{
    [Fact]
    public void ConventionsCatalog_should_export_conventionpart()
    {
        // Setup conventions using the semantic model
        // This is NOT the API that the user will be exposed to,
        // there will be a DSL at the front
 
        var exportConvention =
by TheCodeJunkie   January 14, 2010 @ 4:43am
Tags:
20 Views
no comments
 
C#
public class Fixture
{
    private CompositionContainer _container;
 
    public Fixture()
    {
        var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
        _container = new CompositionContainer(catalog);
    }
by TheCodeJunkie   January 10, 2010 @ 3:05pm
Tags:
44 Views
no comments
 
C#
public class TypeLoaderTests
{
    [Fact]
    public void Load_should_extract_public_types_from_assembly()
    {
        var assembly =
            CSharpAssemblyFactory.Compile(
                @"
                    public class Foo { }
                    public class Bar { }
by TheCodeJunkie   January 07, 2010 @ 2:11pm
Tags:
45 Views
no comments
 
C#
interface ITypeLoader
{
    IEnumerable<Type> Types { get; set;}
    void Load(Assembly assembly);
}
 
interface ITypeLoader2
{
    IEnumerable<Type> GetTypes(Predicate<Type> predicate);
    void Load(Assembly assembly);
by TheCodeJunkie   January 07, 2010 @ 2:37am
Tags:
23 Views
no comments
 
C#
[Fact]
public void GetParts_should_return_definitions_with_import_member_matching_conventions()
{
    var typeLoader =
        new Mock<ITypeLoader>();
    typeLoader.SetupGet(t => t.Types).Returns(new List<Type> { typeof(FakePart) });
 
    var model =
       new ConventionModel();
by TheCodeJunkie   January 05, 2010 @ 3:55am
Tags:
27 Views
no comments
 
C#
public struct RequiredMetadataItem
{
    /// <summary>
    /// Gets or sets the name of the required metadata item.
    /// </summary>
    /// <value>A <see cref="string"/> containing the name of the required metadata item.</value>
    public string Name { get; set; }
 
    /// <summary>
    /// Gets or sets the type of the required metadata item.
by TheCodeJunkie   January 03, 2010 @ 2:33pm
Tags:
30 Views
no comments
 
C#
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.CSharp;
using Xunit;
 
public class AssemblyFactoryTests
{
    [Fact]
    public void Compile_should_return_instance_of_assembly()
by TheCodeJunkie   December 19, 2009 @ 2:11pm
Tags:
110 Views
no comments
 
C#
   [InheritedExport]
   public interface IExtension
   {
       
   }
  
   [AttributeUsage(AttributeTargets.Class)]
   public class ExtensionMetadata : MetadataAttribute
   {
       public ExtensionMetadata(string name) : base(typeof(IExtension))
by TheCodeJunkie   December 13, 2009 @ 12:33pm
Tags:
24 Views
no comments
 
C#
[InheritedLogger]
public interface ILogger
{
    void Append(string message);
}
 
[InheritedLogger(Name = "Foo")]
public class InheritedLogger : ILogger
{
    public void Append(string message)
by TheCodeJunkie   December 11, 2009 @ 12:09pm
Tags:
31 Views
no comments
 
C#
var conventions =
    new ConventionsCatalog();
 
conventions.Configure(c =>
{
    c.CreateParts(t => t.Namespace.Contains("Extension") && t.ImplementsInterface(typeof(IFoo)), a =>
    {
        a.Import<IFoo>(f => f.Calculate(0, 0)).As<IFoo>().AsRecomposable();
        a.Import<IFoo>(f => f.Calculate(1, 2)).As<IFoo>();
    });
by TheCodeJunkie   November 23, 2009 @ 9:58pm
Tags:
38 Views
no comments
 
C#
/// <summary>
    /// THIS CLASS CAN'T BE TESTED LIKE CRAZY SINCE IT'S CLOSED
    /// IE THE NESTED CLOSURE PREVENTS YOU FROM INJECTING MOCK
    /// FOOS TO MAKE SURE THAT PROCESSMESSAGE WORKS LIKE IT
    /// SHOULD.
    /// 
    /// INSTEAD THE CLASS PUTS AN API ONTOP OF THE "RAW" UNDERLAYING
    /// CODE
    /// 
    /// "DSL"
by TheCodeJunkie   November 03, 2009 @ 2:20pm
Tags:
31 Views
no comments
 
C#
this.Listener.ThumbnailButtons.Configure(c =>
{
    c.AddButton()
        .For(this.Handle)
        .WithId(1)
        .WithToolTip("First button")
        .UseIcon(SystemIcons.Asterisk)
        .UseCallback(b => MessageBox.Show("You clicked a button with name: " + b.ToolTip));
 
    c.AddButton()
by TheCodeJunkie   October 13, 2009 @ 2:52pm
Tags:
33 Views
no comments
 
C#
public static class EnumExtensions
{
    public static T Append<T>(this Enum current, T flag)
    {
        return (T)Enum.ToObject(typeof(T), Convert.ToInt32(current) | Convert.ToInt32(flag));
    }
 
    public static T Append<T>(this Enum current, bool condition, T flag)
    {
        var value = condition ?
by TheCodeJunkie   October 10, 2009 @ 2:42pm
Tags:
174 Views
no comments
 
brought to you by:
West Wind Techologies


If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate