/// <inheritdoc/> public int RegisterSwitch(string clazz, string property, string methodSignature, string aspect, bool value) { using (builderLock.WriteLock) #if DEBUG using (completedLock.ReadLock) #endif using (switchLock.WriteLock) { #if DEBUG // the code will be called in client assembly, so reducing unnecessary validations for performance consideration if (string.IsNullOrEmpty(clazz)) { throw new ArgumentNullException("clazz"); } if (completed.ContainsKey(clazz)) { throw new ArgumentException($"{clazz} is completed for switch registration already."); } #endif var id = switchList.Count; switchList.Add(value); if (!buildingUps.ContainsKey(clazz)) { buildingUps.Add(clazz, SwitchFactory.InitializeClassAspectSwitch(switchList, switchLock)); } buildingUps[clazz].RegisterSwitch(id, property, methodSignature, aspect); return(id); } }
/// <inheritdoc/> public void SwitchAspect(string aspect, SwitchOperation operation, int sequence) { #if DEBUG // the code will be called in client assembly, so reducing unnecessary validations for performance consideration if (string.IsNullOrEmpty(aspect)) { throw new ArgumentNullException("aspect"); } if (sequence < 0) { throw new ArgumentOutOfRangeException("sequence"); } #endif if (aspectSwitchDictionary.ContainsKey(aspect)) { SwitchExistingAspect(aspect, operation, sequence); } else { var duplicate = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, operation); aspectSwitchDictionary.Add(aspect, duplicate); } SwitchAllAspect(aspect, operation, sequence); }
private int SwitchMethodAspectInternal(string methodSignature, string aspect, SwitchOperation operation, int sequence) { if (methodAspectSwitchDictionary.ContainsKey(methodSignature)) { if (methodAspectSwitchDictionary[methodSignature].ContainsKey(aspect)) { if (sequence == UseGeneratedSequence) { var operationStatus = methodAspectSwitchDictionary[methodSignature][aspect]; operationStatus.Switch(operation); sequence = operationStatus.Sequence; } else { methodAspectSwitchDictionary[methodSignature][aspect].Switch(operation, sequence); } } else { var operationStatus = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, operation); sequence = operationStatus.Sequence; methodAspectSwitchDictionary[methodSignature].Add(aspect, operationStatus); } } else { var operationStatus = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, operation); sequence = operationStatus.Sequence; methodAspectSwitchDictionary.Add(methodSignature, new Dictionary <string, SwitchOperationStatus> { { aspect, operationStatus } }); } return(sequence); }
private int SwitchMethodInternal(string methodSignature, SwitchOperation operation, int sequence) { if (methodSwitchDictionary.ContainsKey(methodSignature)) { if (sequence == UseGeneratedSequence) { methodSwitchDictionary[methodSignature].Switch(operation); } else { methodSwitchDictionary[methodSignature].Switch(operation, sequence); } sequence = methodSwitchDictionary[methodSignature].Sequence; } else { var operationStatus = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, operation); sequence = operationStatus.Sequence; methodSwitchDictionary.Add(methodSignature, operationStatus); } SwitchAllExistingMethodAspect(methodSignature, operation, sequence); return(sequence); }
private void InitializeAspectSwitches(IReadOnlyDictionary <string, SwitchOperationStatus> aspectOperations) { foreach (var aspectOperation in aspectOperations) { var operation = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, aspectOperation.Value); aspectSwitchDictionary.Add(aspectOperation.Key, operation); } }
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); }
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); }
/// <inheritdoc/> public void Switch(SwitchOperation operation) { int sequence; if (Operation == null) { Operation = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, operation); sequence = Operation.Sequence; } else { sequence = SwitchExistingClass(operation); } SwitchAll(operation, sequence); }
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); }
private int Switch(string aspect, SwitchOperation operation) { if (string.IsNullOrWhiteSpace(aspect)) { throw new ArgumentNullException("aspect"); } var switched = 0; using (completedLock.ReadLock) using (operationLock.ReadLock) { foreach (var completed in completed.Values) { if (completed.IsAspectApplied(aspect)) { switched += completed.SwitchAspect(aspect, operation); } } SwitchOperationStatus operationStatus; if (aspectOperations.ContainsKey(aspect)) { operationStatus = aspectOperations[aspect]; operationStatus.Switch(operation); } else { operationStatus = SwitchFactory.InitializeSwitchOperationStatus(sequenceGenerator, operation); using (operationLock.WriteLock) { aspectOperations.Add(aspect, operationStatus); } } foreach (var classOperation in classOperations.Values) { classOperation.SwitchAspect(aspect, operation); } } return(switched); }