public void Execute() { var context = new VisitorContext(this); VisitProperties(context); VisitMethods(context); }
public void Visit(MethodDefinition method, VisitorContext context) { if (IsLazy(method)) { var instrumentor = new DoubleCheckedLockingWeaver(method, context); instrumentor.Instrument(); } }
public override void Execute() { var context = new VisitorContext(this); VisitProperties(context); VisitMethods(context); VisitAssemblyReferences(context); }
public void Visit(PropertyDefinition property, VisitorContext context) { if (IsLazy(property) && property.GetMethod != null && !IsLazy(property.GetMethod)) { var instrumentor = new DoubleCheckedLockingWeaver(property.GetMethod, context); instrumentor.Instrument(); } }
protected LazyWeaver(MethodDefinition method, VisitorContext context) { Method = method; Context = context; ObjRef = method.Module.ImportReference(typeof(object)); ObjCtorRef = method.Module.ImportReference(new MethodReference(".ctor", method.Module.TypeSystem.Void, ObjRef) { HasThis = true, }); }
public DoubleCheckedLockingWeaver(MethodDefinition method, VisitorContext context) { _method = method; _context = context; _objRef = method.Module.Import(typeof(object)); _objCtorRef = method.Module.Import(new MethodReference(".ctor", method.Module.TypeSystem.Void, _objRef) { HasThis = true, }); }
protected LazyWeaver(MethodDefinition method, VisitorContext context) { Method = method; Context = context; ObjRef = method.Module.Import(typeof(object)); ObjCtorRef = method.Module.Import(new MethodReference(".ctor", method.Module.TypeSystem.Void, ObjRef) { HasThis = true, }); }
public void Visit(PropertyDefinition property, VisitorContext context) { var lazyAttribute = GetLazyAttribute(property); if (lazyAttribute != null && property.GetMethod != null && !IsLazy(property.GetMethod)) { var instrumentor = GetWeaver(property.GetMethod, context); instrumentor.Instrument(); property.CustomAttributes.Remove(lazyAttribute); } }
public void Visit(MethodDefinition method, VisitorContext context) { var lazyAttribute = GetLazyAttribute(method); if (lazyAttribute != null) { var instrumentor = GetWeaver(method, context); instrumentor.Instrument(); method.CustomAttributes.Remove(lazyAttribute); } }
private void VisitProperties(VisitorContext context) { var propertyVisitors = GetImplementations <IPropertyVisitor>(); var q = from type in ModuleDefinition.Types from property in type.Properties select property; foreach (var property in q.ToList()) { foreach (var visitor in propertyVisitors) { visitor.Visit(property, context); } } }
private void VisitMethods(VisitorContext context) { var methodVisitors = GetImplementations <IMethodVisitor>(); var q = from type in GetTypes(ModuleDefinition.Types) from method in type.GetMethods() select method; foreach (var method in q.ToList()) { foreach (var visitor in methodVisitors) { visitor.Visit(method, context); } } }
private void VisitAssemblyReferences(VisitorContext context) { // Attempt to locate the "AutoLazy" assembly reference. var assemblyName = ModuleDefinition.AssemblyReferences.FirstOrDefault( reference => reference.FullName.StartsWith("AutoLazy") ); // Verify our result. if (assemblyName == null) { // Will happen if AutoLazy is added, but not used. return; } // Remove unnecessary references remaining in our subject assembly. ModuleDefinition.AssemblyReferences.Remove(assemblyName); }
private LazyWeaver GetWeaver(MethodDefinition method, VisitorContext context) { return(method.Parameters.Count == 0 ? (LazyWeaver) new DoubleCheckedLockingWeaver(method, context) : new KeyedLazyWeaver(method, context)); }
private LazyWeaver GetWeaver(MethodDefinition method, VisitorContext context) { return method.Parameters.Count == 0 ? (LazyWeaver)new DoubleCheckedLockingWeaver(method, context) : new KeyedLazyWeaver(method, context); }
public DoubleCheckedLockingWeaver(MethodDefinition method, VisitorContext context) : base(method, context) { }
public KeyedLazyWeaver(MethodDefinition method, VisitorContext context) : base(method, context) { }
protected LazyWeaver(MethodDefinition method, VisitorContext context) { Method = method; Context = context; }