Skip to content

Instantly share code, notes, and snippets.

View mgroves's full-sized avatar

Matthew D. Groves mgroves

View GitHub Profile
@mgroves
mgroves / gist:785556
Created January 19, 2011 02:10
lazy load 4
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
private Type _type;
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)
{
@mgroves
mgroves / gist:785557
Created January 19, 2011 02:10
lazy load 4
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
private Type _type;
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)
{
@mgroves
mgroves / gist:785559
Created January 19, 2011 02:11
lazy load 5
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
if(!locationInfo.LocationType.IsInterface)
{
Message.Write(SeverityType.Error, "001", "LazyLoad can only be used on Interfaces!");
return false;
}
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)
@mgroves
mgroves / gist:787189
Created January 20, 2011 00:38
lazy load 3
[LazyLoad] private IProductRepository _productRepository;
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
args.ProceedGetValue(); // this actually fetches the field and populates the args.Value
if (args.Value == null)
{
@mgroves
mgroves / gist:787197
Created January 20, 2011 00:43
lazy load 4
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
private Type _type;
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
if(!locationInfo.LocationType.IsInterface)
{
Message.Write(SeverityType.Error, "001", "LazyLoad can only be used on Interfaces in {0}.{1}", locationInfo.DeclaringType, locationInfo.Name);
@mgroves
mgroves / gist:787198
Created January 20, 2011 00:45
lazy load 4
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
private Type _type;
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)
{
@mgroves
mgroves / gist:787201
Created January 20, 2011 00:46
lazy load 5
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
if(!locationInfo.LocationType.IsInterface)
{
Message.Write(SeverityType.Error, "001", "LazyLoad can only be used on Interfaces in {0}.{1}", locationInfo.DeclaringType, locationInfo.Name);
return false;
}
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)
@mgroves
mgroves / gist:787202
Created January 20, 2011 00:46
lazy load 5
public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo)
{
if(!locationInfo.LocationType.IsInterface)
{
Message.Write(SeverityType.Error, "001", "LazyLoad can only be used on Interfaces in {0}.{1}", locationInfo.DeclaringType, locationInfo.Name);
return false;
}
_type = DependencyMap.GetConcreteType(locationInfo.LocationType);
if(_type == null)
@mgroves
mgroves / gist:788140
Created January 20, 2011 16:34
T4 test generation
<#@ template language="C#" hostspecific="true" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Collections.Generic" #>
<#
string TestXml =
@"<?xml version=""1.0"" encoding=""utf-8""?>
<WebTest Name=""{0}"" Id=""{2}"" Owner="""" Priority=""0"" Enabled=""True"" CssProjectStructure="""" CssIteration="""" Timeout=""0"" WorkItemIds="""" xmlns=""http://microsoft.com/schemas/VisualStudio/TeamTest/2006"" Description="""" CredentialUserName="""" CredentialPassword="""" PreAuthenticate=""True"" Proxy="""" StopOnError=""False"">
<Items>
<Request Method=""GET"" Version=""1.1"" Url=""{{{{webserver}}}}/freecache.aspx"" ThinkTime=""0"" Timeout=""300"" ParseDependentRequests=""True"" FollowRedirects=""True"" RecordResult=""True"" Cache=""False"" ResponseTimeGoal=""0"" Encoding=""utf-8"" ExpectedHttpStatusCode=""0"" ExpectedResponseUrl="""" />
private IProductRepository _productRepository;
private IProductRepository ProductRepository
{
get
{
if(_productRepository == null)
{
_productRepository = new ProductRepository();
}
return _productRepository;