Skip to content

Instantly share code, notes, and snippets.

View mgroves's full-sized avatar

Matthew D. Groves mgroves

View GitHub Profile
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PostSharpAssemblyBindingPolicySet>Silverlight20</PostSharpAssemblyBindingPolicySet>
</PropertyGroup>
</Project>
@mgroves
mgroves / gist:756430
Created December 27, 2010 19:06
Monodroid options menu
public override bool OnCreateOptionsMenu(IMenu menu)
{
var item = menu.Add(0,1,1,"Refresh");
item.SetIcon(Resource.drawable.ic_menu_refresh);
return true;
}
public override bool OnOptionsItemSelected(IMenuItem item)
{
switch (item.Title.ToS())
@mgroves
mgroves / gist:762877
Created January 2, 2011 22:23
PostSharp and TinyIoC sittin in a tree
using System;
using Android.Content;
using MonoStockPortfolio.Core.PortfolioRepositories;
using MonoStockPortfolio.Core.Services;
using MonoStockPortfolio.Core.StockData;
using PostSharp.Aspects;
using TinyIoC;
namespace MonoStockPortfolio.Framework
{
@mgroves
mgroves / gist:783998
Created January 18, 2011 04:41
Lazy loading 1
private IProductRepository _productRepository;
private IProductRepository ProductRepository
{
get
{
if(_productRepository == null)
{
_productRepository = new ProductRepository();
}
return _productRepository;
@mgroves
mgroves / gist:784003
Created January 18, 2011 04:51
Lazy Loading 2
private IProductRepository _productRepository;
private IProductRepository ProductRepository
{
get
{
if(_productRepository == null)
{
_productRepository = ObjectFactory.GetInstance<IProductRepository>();
}
return _productRepository;
@mgroves
mgroves / gist:784015
Created January 18, 2011 05:12
Lazy load 3
[LazyLoad] private IProductRepository _productRepository;
public class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
if (args.Value == null)
{
var locationType = args.Location.LocationType;
var instantiation = ObjectFactory.GetInstance(locationType);
@mgroves
mgroves / gist:785516
Created January 19, 2011 01:30
lazy loading 3
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
var form = (ProductForm)args.Instance; // this form is only used here to write to a listbox for demonstration
args.ProceedGetValue();
if (args.Value == null)
{
@mgroves
mgroves / gist:785517
Created January 19, 2011 01:30
lazy load 3
[LazyLoad] private IProductRepository _productRepository;
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
var form = (ProductForm)args.Instance; // this form is only used here to write to a listbox for demonstration
args.ProceedGetValue();
@mgroves
mgroves / gist:785518
Created January 19, 2011 01:31
lazy load 3
[LazyLoad] private IProductRepository _productRepository;
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
args.ProceedGetValue();
if (args.Value == null)
{
@mgroves
mgroves / gist:785545
Created January 19, 2011 02:01
lazy loading 4
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
private Type _type;
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
// DependencyMap.GetConcreteType will just return the concrete type given an interface
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)