Format:
Recent snippets for: TheCodeJunkie
Get["/"] = x => { return "This is the root"; }; Get["/Greet"] = x => { return "Hello World"; }; Get["/Greet/{name}"] = x => { return "Hello " + x.name;
9 Views
no comments
R#5 wants to turn var creator = new ConventionPartCreator(registry); into var creator = new ConventionPartCreator(registry); how do I make it stop!?
60 Views
no comments
public class TestRegistry { public TestRegistry() { Defaults(x => { x.Type<Foo>().Contract("Andreas").Identity<IWidget>(); x.Type<Bar>().Contract("Piotr").Identity<IUnity>(); }); Part()
27 Views
no comments
properties {
$base_directory = resolve-path .
$build_directory = "$base_directory\release"
$source_directory = "$base_directory\src"
$tools_directory = "$base_directory\tools"
$version = "1.0.0.0"
}
include .\psake_ext.ps1
93 Views
no comments
public static class Member { /// <summary> /// Retrieves the member that an expression is defined for. /// </summary> /// <param name="expression">The expression to retreive the member from.</param> /// <returns>A <see cref="MemberInfo"/> instance if the member could be found; otherwise <see langword="null"/>.</returns> private static MemberInfo GetTargetMemberInfo(this Expression expression) { switch (expression.NodeType)
98 Views
no comments
public interface IRuleMetadata { [DefaultValue(0)] int ExecutionOrder { get; } } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public class RuleAttribute : ExportAttribute, IRuleMetadata { public RuleAttribute(int executionOrder)
206 Views
no comments
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 }))
81 Views
no comments
public class ConventionPart<T> : IPartImportsSatisfiedNotification { /// <summary> /// Initializes a new instance of the <see cref="ConventionPart{T}"/> class. /// </summary> public ConventionPart() { } [ImportMany]
109 Views
no comments
public class FakeConventionRegistry : ConventionRegistry { public FakeConventionRegistry() { Part<PartConvention>() .ForTypesMatching(x => x.IsPublic && x.IsAbstract == false) .MakeShared() .Imports(x => { x.Import<ImportConvention>()
33 Views
no comments
public class MyConventionRegistry : ConventionRegistry { public MyConventionRegistry() { Part<PartConvention>() .ForTypesMatching(x => x.Name.StartsWith("Foo")) .MakeNonShared() .Imports(i => { i.Import<ImportConvention>().As<IImportConvention>();
33 Views
no comments
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);
68 Views
1 comments
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()
91 Views
2 comments
public interface IExpressionBuilder<T> { T GetInstanceFromExpression(); } public interface IImportConventionExpressionBuilder<TImportConvention> : IExpressionBuilder<TImportConvention> where TImportConvention : IImportConvention, new() { IImportConventionExpressionBuilder<TImportConvention> AllowDefaultValue();
35 Views
no comments
public class FluentBuilder : IFluentBuilder { public FluentBuilder() { this.Convention = new TestExportConvention(); } private ITestExportConvention Convention { get; set; } public IFluentBuilder Export<T>(Expression<Func<T, object>> expression)
46 Views
no comments
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 =
51 Views
no comments
public class Fixture { private CompositionContainer _container; public Fixture() { var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); _container = new CompositionContainer(catalog); }
68 Views
no comments
public class TypeLoaderTests { [Fact] public void Load_should_extract_public_types_from_assembly() { var assembly = CSharpAssemblyFactory.Compile( @" public class Foo { } public class Bar { }
84 Views
no comments
interface ITypeLoader { IEnumerable<Type> Types { get; set;} void Load(Assembly assembly); } interface ITypeLoader2 { IEnumerable<Type> GetTypes(Predicate<Type> predicate); void Load(Assembly assembly);
44 Views
no comments
[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();
49 Views
no comments
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.
53 Views
no comments
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()
206 Views
no comments
[InheritedExport] public interface IExtension { } [AttributeUsage(AttributeTargets.Class)] public class ExtensionMetadata : MetadataAttribute { public ExtensionMetadata(string name) : base(typeof(IExtension))
41 Views
no comments
[InheritedLogger] public interface ILogger { void Append(string message); } [InheritedLogger(Name = "Foo")] public class InheritedLogger : ILogger { public void Append(string message)
55 Views
no comments
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>(); });
66 Views
no comments
/// <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"
51 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
