Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public abstract bool Validate(AspectDefinition aspect, ILogger log);