New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Format:
Recent snippets for: Glenn Block
C#
public class ViewModelInitializer<TViewModel,TModel> where TViewModel : IViewModel<TModel>
{
    private Func<TViewModel> _viewModelFactory;
 
    public ViewModelInitializer(Func<TViewModel> viewModelFactory)
    {
        _viewModelFactory = viewModelFactory;
    }
 
    public void Initialize(FrameworkElement view, TModel model)
by Glenn Block   February 07, 2010 @ 3:07pm
Tags:
191 Views
no comments
 
C#
// Below RecentlyUsedTrackerConfiguration provides configuration information through property exports. MEF pulls on the property getters and exports that info. 
// If the part needs to be data drvien, you can still access a service behind the scenes in the getter (or the constructor) to get the info.
 
public class RecentlyUsedTrackerConfiguration
{
  public RecentlyUsedTrackerConfiguration()
  {
     //set values here
  }
by Glenn Block   January 26, 2010 @ 6:34pm
Tags:
143 Views
no comments
 
C#
public static class AsyncTestExtensions
{
    public static void EnqueueUntilLoaded(this SilverlightTest test, FrameworkElement element, params Action[] actions)
    {
        var isLoaded = false;
        element.Loaded += (s, e) => isLoaded = true;
        test.EnqueueConditional(() => isLoaded);
        test.EnqueueCallback(actions);
        test.EnqueueTestComplete();
    }
by Glenn Block   January 24, 2010 @ 12:29pm
Tags:
127 Views
no comments
 
C#
namespace System.ComponentModel.Composition.Hosting
{
    public class DeploymentCatalog : ComposablePartCatalog, INotifyComposablePartCatalogChanged
    {
        public DeploymentCatalog();
        public DeploymentCatalog(string uri);
        public DeploymentCatalog(Uri uri);
        public override IQueryable<ComposablePartDefinition> Parts { get; }
        public Uri Uri { get; }
by Glenn Block   January 22, 2010 @ 11:36am
Tags:
70 Views
no comments
 
C#
using System.ComponentModel.Composition;
using Microsoft.Practices.Composite.Events;
 
//this version uses a static backing field so that the instance is automatically shared across all containers.
public class EventAggregatorPart
{
    private static IEventAggregator _eventAggregator;
 
    static EventAggregatorPart()
    {   
by Glenn Block   January 10, 2010 @ 11:30pm
218 Views
no comments
 
C#
 
var catalog = new DirectoryCatalog(@".\");
var rootCatalog = new FilteredCatalog(catalog, cpd=>!cpd.Metadata.ContainsKey("Scope") || (cpd.Metadata.ContainsKey("Scope") && cpd.Metadata["Scope"].Equals("Root"));
var childCatalog = new FilteredCatalog(catalog, cpd=>cpd.Metadata.ContainsKey("Scope") && cpd.Metadata["Scope"].Equals("Child"));
var rootContainer = new CompositionContainer(rootCatalog);
var childContainer = new CompositionContainer(childCatalog, rootContainer);
 
by Glenn Block   January 04, 2010 @ 12:09am
Tags:
41 Views
no comments
 
C#
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
by Glenn Block   December 16, 2009 @ 10:44pm
Tags:
333 Views
no comments
 
Imports System.ComponentModel.Composition
Imports System.ComponentModel.Composition.Hosting
Imports System.ComponentModel.Composition.Deployment
 
Namespace DeploymentCatalogDesignVB
    Namespace Setting_up_the_host_to_download_catalogs
        Public Class App
            Inherits Application
 
            Public Sub Initialize()
by Glenn Block   December 16, 2009 @ 10:41pm
Tags:
173 Views
no comments
 
C#
/*
 
Sample below illustates export inheritance where the base export provides metadata that is overriden by the inheritor
using a custom metadata attribute. 
 
In this case OverridingExtension implements IExtension but then explicitly overrides the base and provides new metadata. 
 
The result is a single export rather than two exports.
 
Notice the inheritor is using an InheritedExport attribute + a custom metadata attribute to override rather than using a custom InheritedExport. 
by Glenn Block   December 13, 2009 @ 1:34pm
Tags:
243 Views
no comments
 
C#
/*

Sample below illustatres export inheritance where the base export provides metadata that is overriden by the inheritor
using an InheritedExport and ExportMetadata attributes. 

In this case OverridingExtension implements IExtension but then explicitly overrides the base and provides new metadata. 

The result is a single export rather than two exports.

*/
by Glenn Block   December 13, 2009 @ 11:03am
Tags:
655 Views
no comments
 
C#
//Design time VM
 
        [Export]
        public ContactVM GetViewModel()
        {
            var contact = new Contact()
            {
                FirstName = "John",
                LastName = "Doe",
                City = "Design time",
by Glenn Block   December 07, 2009 @ 12:39pm
Tags:
310 Views
no comments
 
C#
namespace Microsoft.ComponentModel.Composition.Packaging
{
    public static class ContainerBuilder
    {
        private static PackageCatalog _packageCatalog;
        private static CompositionContainer _container;
        private static object _lock = new Object();
 
        public static CompositionContainer GetContainer()
        {
by Glenn Block   November 26, 2009 @ 11:03am
Tags:
115 Views
no comments
 
C#
using System;
using System.ComponentModel.Composition.Primitives;
using System.Collections.Generic;
using System.ComponentModel.Composition.ReflectionModel;
using System.ComponentModel.Composition;
using System.Reflection;
using System.Linq;
using System.ComponentModel.Composition.Hosting;
using System.Collections;
by Glenn Block   November 17, 2009 @ 1:26pm
Tags: MEF; Poco
633 Views
no comments
 
C#
namespace ExtensibleGrid.GridLibrary
{
    public class ExtensibleDataGrid : DataGrid
    {
        private ConfigDialog dialog { get; set; }
        private IEnumerable<ExtensionItem> extensionItems;
    
        public override void OnApplyTemplate()
        {
            dialog = new ConfigDialog();
by Glenn Block   November 01, 2009 @ 7:21pm
Tags:
90 Views
no comments
 
C#
Binder = ViewBinder.For(this, vm).
    Value(p => p.FirstName).
    Value(p => p.Address).
    AddBinder(new ValueBinder<ContactViewModel>(this.OnMailingList, vm)).
    List(p => p.Cities).
    Action(p => vm.Save()).
    Template<City>("City", t => t.Value(p => p.CityName));
 
by Glenn BLock   October 17, 2009 @ 8:40pm
Tags:
185 Views
no comments
 
C#
public class StringHelper
{
    public static string ToString(object instance)
    {
        var properties = TypeDescriptor.GetProperties(instance);
        StringBuilder output = new StringBuilder();
        foreach (PropertyDescriptor property in properties)
        {
            output.Append(string.Format("{0} - {1}\r\n", property.Name, property.GetValue(instance)));
        }
by Glenn Block   October 06, 2009 @ 1:51am
Tags:
180 Views
2 comments
 
C#
 
 
public class CSLExportProvider : ExportProvider
{
    private IServiceLocator serviceLocator;
    private IDictionary<string, Type> contractMapping;
    
    public CSLExportProvider(IServiceLocator serviceLocator)
    {
        this.contractMapping = new Dictionary<string, Type>();
by Glenn Block   September 26, 2009 @ 12:25am
413 Views
1 comments
 
C#
   /// <summary>
   /// Summary description for MvvmLightExtensionsFixture
   /// </summary>
   [TestClass]
   public class When_Subscribe_is_called_on_SingleSubscriber : MessengerContext
   {
       [TestMethod]
       public void then_message1_is_registered()
       {
           _mock.Verify(c =>c.Register<Message1>(_singleSubscriber, _singleSubscriber.Subscribe));            
by Glenn BLock   September 20, 2009 @ 9:57pm
Tags:
121 Views
no comments
 
C#
[TestClass]
public class MefEventAggregatorTestFixture
{
    [TestMethod]
    public void Subscriber_is_invoked_when_publisher_raises_event()
    {
       var catalog = new InterceptingCatalog(
            new TypeCatalog(typeof(EventAggregator), typeof (FakePublisher), typeof (MockSubscriber))
            );
        var container = new CompositionContainer(catalog);
by Glenn Block   September 01, 2009 @ 6:22pm
154 Views
no comments
 
C#
//See Wes Haggard's updated implementation here: http://codepaste.net/ktdgoh
 
//Adapting collection is a generic collection that allows you to adapt the contents using your own custom logic.
 
    public abstract class AdaptingCollection<T> : 
        ICollection<T>
    {
        private readonly List<T> _innerCollection = new List<T>();
        private List<T> _adaptedCollection;
        private bool _changed=true;
by Glenn BLock   August 18, 2009 @ 9:45pm
Tags: MEF
165 Views
no comments
 
C#
    public class GenericCatalog : ComposablePartCatalog, INotifyComposablePartCatalogChanged
    {
        private ComposablePartCatalog _decoratedCatalog;
        private AggregateCatalog _catalog = new AggregateCatalog();
        private IDictionary<string, Type> _closedTypes = new Dictionary<string, Type>();
        private IDictionary<string, Type> _genericTypes = new Dictionary<string, Type>();
 
        public GenericCatalog(ComposablePartCatalog catalog)
        {
            _decoratedCatalog = catalog;
by Glenn Block   August 07, 2009 @ 12:31am
Tags: MEF
297 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