private static void SetPropertySwitches(PropertySwitches switches, string method, int id) { const string getterPrefix = "get_"; const string setterPrefix = "set_"; if (method.StartsWith(getterPrefix)) { if (switches.Getter >= 0) { throw new ArgumentException($"Getter method {method} has been set"); } switches.Getter = id; } else if (method.StartsWith(setterPrefix)) { if (switches.Setter >= 0) { throw new ArgumentException($"Setter method {method} has been set"); } switches.Setter = id; } else { throw new ArgumentException($"Invalid getter or setter method name: {method}"); } }
private int Switch(PropertySwitches propertySwitches, SwitchOperation operation) { var result = 0; var getter = propertySwitches.Getter; if (getter >= 0) { switchList[getter] = Switch(switchList[getter], operation); result++; } var setter = propertySwitches.Setter; if (setter >= 0) { switchList[setter] = Switch(switchList[setter], operation); result++; } return(result); }
/// <inheritdoc/> public void RegisterSwitch(int id, string propertyName, string methodSignature, string aspect) { #if DEBUG // the code will be called in client assembly, so reducing unnecessary validations for performance consideration if (string.IsNullOrWhiteSpace(aspect)) { throw new ArgumentNullException("aspect"); } if (string.IsNullOrWhiteSpace(methodSignature)) { throw new ArgumentException("Method of property can't be empty"); } if (!string.IsNullOrWhiteSpace(methodSignature) && methodSwitchDictionary.ContainsKey(methodSignature) && methodSwitchDictionary[methodSignature].ContainsKey(aspect)) { throw new ArgumentException($"Aspect {aspect} is added for property method {propertyName} already", "aspect"); } if (aspectSwitchDictionary.ContainsKey(aspect) && aspectSwitchDictionary[aspect].Contains(id)) { throw new ArgumentException($"Id {id} is added to aspect {aspect} already", "id"); } #endif // This method is not supposed to be called with multithread style, so no locking applied complete.Assert(false); if (!string.IsNullOrWhiteSpace(propertyName)) { if (propertySwitchDictionary.ContainsKey(propertyName)) { var aspectDictionary = propertySwitchDictionary[propertyName]; if (aspectDictionary.ContainsKey(aspect)) { SetPropertySwitches(aspectDictionary[aspect], methodSignature, id); } else { var propertySwitches = new PropertySwitches(); SetPropertySwitches(propertySwitches, methodSignature, id); aspectDictionary.Add(aspect, propertySwitches); } } else { var propertySwitches = new PropertySwitches(); SetPropertySwitches(propertySwitches, methodSignature, id); propertySwitchDictionary.Add(propertyName, new Dictionary <string, PropertySwitches> { { aspect, propertySwitches } }); } } if (!string.IsNullOrWhiteSpace(methodSignature)) { if (methodSwitchDictionary.ContainsKey(methodSignature)) { methodSwitchDictionary[methodSignature].Add(aspect, id); } else { methodSwitchDictionary.Add(methodSignature, new Dictionary <string, int> { { aspect, id } }); } } if (aspectSwitchDictionary.ContainsKey(aspect)) { aspectSwitchDictionary[aspect].Add(id); } else { aspectSwitchDictionary.Add(aspect, new List <int> { id }); } }