Format:
Recent snippets for: TheCodeJunkie
public interface IRuleMetadata { [DefaultValue(0)] int ExecutionOrder { get; } } [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] public class RuleAttribute : ExportAttribute, IRuleMetadata { public RuleAttribute(int executionOrder)
28 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 }))
27 Views
no comments
public class ConventionPart<T> : IPartImportsSatisfiedNotification { /// <summary> /// Initializes a new instance of the <see cref="ConventionPart{T}"/> class. /// </summary> public ConventionPart() { } [ImportMany]
51 Views
no comments
public class FakeConventionRegistry : ConventionRegistry { public FakeConventionRegistry() { Part<PartConvention>() .ForTypesMatching(x => x.IsPublic && x.IsAbstract == false) .MakeShared() .Imports(x => { x.Import<ImportConvention>()
11 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>();
11 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);
47 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()
40 Views
2 comments
public interface IExpressionBuilder<T> { T GetInstanceFromExpression(); } public interface IImportConventionExpressionBuilder<TImportConvention> : IExpressionBuilder<TImportConvention> where TImportConvention : IImportConvention, new() { IImportConventionExpressionBuilder<TImportConvention> AllowDefaultValue();
13 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)
26 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 =
20 Views
no comments
public class Fixture { private CompositionContainer _container; public Fixture() { var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); _container = new CompositionContainer(catalog); }
43 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 { }
45 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);
22 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();
26 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.
30 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()
101 Views
no comments
[InheritedExport] public interface IExtension { } [AttributeUsage(AttributeTargets.Class)] public class ExtensionMetadata : MetadataAttribute { public ExtensionMetadata(string name) : base(typeof(IExtension))
23 Views
no comments
[InheritedLogger] public interface ILogger { void Append(string message); } [InheritedLogger(Name = "Foo")] public class InheritedLogger : ILogger { public void Append(string message)
30 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>(); });
36 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"
30 Views
no comments
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()
33 Views
no comments
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 ?
167 Views
no comments
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search
