private FieldReference GetGlobalAspectField(AspectDefinition aspect) { var singleton = aspect.Host.Fields.FirstOrDefault(f => f.Name == Constants.AspectGlobalField); if (singleton == null) { throw new Exception("Missed aspect global singleton."); } return(singleton); }
private FieldReference GetInstanceAspectField(AspectDefinition aspect, TypeDefinition source) { var type = source; var fieldName = $"{Constants.AspectInstanceFieldPrefix}{aspect.Host.FullName}"; var field = FindField(type, fieldName); if (field == null) { field = new FieldDefinition(fieldName, FieldAttributes.Family, _typeSystem.Import(aspect.Host)); type.Fields.Add(field); InjectInitialization(GetInstanсeAspectsInitializer(type), field, aspect.CreateAspectInstance); } return(field); }
public PointCut LoadAspect(AspectDefinition aspect, MethodDefinition overrideTarget = null, Action <PointCut> overrideThis = null, TypeDefinition overrideSource = null) { overrideTarget = overrideTarget ?? _proc.Body.Method; overrideThis = overrideThis ?? (pc => pc.This()); overrideSource = overrideSource ?? overrideTarget.DeclaringType; FieldReference aspectField; if (overrideTarget.IsStatic || aspect.Scope == Aspect.Scope.Global) { aspectField = GetGlobalAspectField(aspect); } else { aspectField = GetInstanceAspectField(aspect, overrideSource.Resolve()); overrideThis(this); } Load(aspectField); return(this); }
public abstract bool Validate(AspectDefinition aspect, ILogger log);