Exemple #1
0
        private int Switch(MethodInfo method, string aspect, SwitchOperation operation)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }

            if (method.DeclaringType == null)
            {
                throw new ArgumentException($"Method {method.GetSignature()} doesn't have declaring type.");
            }

            if (string.IsNullOrWhiteSpace(aspect))
            {
                throw new ArgumentNullException("aspect");
            }

            var clazz = method.DeclaringType.FullName;

            using (completedLock.ReadLock)
            {
                if (completed.ContainsKey(clazz))
                {
                    // the class is completed
                    return(completed[clazz].SwitchMethodAspect(method.GetSignature(), aspect, operation));
                }
            }

            IClassAspectSwitchOperation op;

            using (operationLock.ReadLock)
            {
                if (!classOperations.ContainsKey(clazz))
                {
                    // the class is not loaded yet
                    op = SwitchFactory.InitializeClassAspectSwitchOperation(sequenceGenerator, aspectOperations);
                    using (operationLock.WriteLock)
                    {
                        classOperations.Add(clazz, op);
                    }
                }
                else
                {
                    op = classOperations[clazz];
                }
            }

            op.SwitchMethodAspect(method.GetSignature(), aspect, operation);
            return(-1);
        }
Exemple #2
0
        private int Switch(PropertyInfo property, SwitchOperation operation)
        {
            if (property == null)
            {
                throw new ArgumentNullException("property");
            }

            if (property.DeclaringType == null)
            {
                throw new ArgumentException($"Property {property.Name} doesn't have declaring type.");
            }

            var clazz = property.DeclaringType.FullName;

            using (completedLock.ReadLock)
            {
                if (completed.ContainsKey(clazz))
                {
                    // the class is completed
                    return(completed[clazz].SwitchProperty(property.Name, operation));
                }
            }

            IClassAspectSwitchOperation op;

            using (operationLock.ReadLock)
            {
                if (!classOperations.ContainsKey(clazz))
                {
                    // the class is not loaded yet
                    op = SwitchFactory.InitializeClassAspectSwitchOperation(sequenceGenerator, aspectOperations);
                    using (operationLock.WriteLock)
                    {
                        classOperations.Add(clazz, op);
                    }
                }
                else
                {
                    op = classOperations[clazz];
                }
            }

            op.SwitchProperty(
                property.GetMethod?.GetSignature(),
                property.SetMethod?.GetSignature(),
                operation);
            return(-1);
        }
Exemple #3
0
        private int Switch(Type type, string aspect, SwitchOperation operation)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (string.IsNullOrWhiteSpace(aspect))
            {
                throw new ArgumentNullException("aspect");
            }

            var clazz = type.FullName;

            using (completedLock.ReadLock)
            {
                if (completed.ContainsKey(clazz))
                {
                    // the class is completed
                    return(completed[clazz].SwitchAspect(aspect, operation));
                }
            }

            IClassAspectSwitchOperation op;

            using (operationLock.ReadLock)
            {
                if (!classOperations.ContainsKey(clazz))
                {
                    // the class is not loaded yet
                    op = SwitchFactory.InitializeClassAspectSwitchOperation(sequenceGenerator, aspectOperations);
                    using (operationLock.WriteLock)
                    {
                        classOperations.Add(clazz, op);
                    }
                }
                else
                {
                    op = classOperations[clazz];
                }
            }

            op.SwitchAspect(aspect, operation);
            return(-1);
        }