protected static void ActivatePropertyDependencies(Type type) { if (_propertyDependencies.ContainsKey(type)) { return; } var dependencyList = new List <PropertyDependency>(); var typeProperties = type.GetProperties(); foreach (var property in typeProperties) { var directDependencies = GetDependantProperties(typeProperties, property.Name); if (directDependencies.Any()) { var dependener = new PropertyDependency(property.Name) { DependantProperties = new HashSet <string>(directDependencies) }; dependencyList.Add(dependener); } } foreach (var propertyDependency in dependencyList) { CollectDependencyHierarchy(dependencyList, propertyDependency); } _propertyDependencies.Add(type, dependencyList); }
private void EnsureDependencies(CollectionRuleActionOptions options, int actionIndex) { foreach (PropertyInfo property in GetPropertiesFromSettings(options)) { string originalValue = (string)property.GetValue(options.Settings); string newValue = originalValue; if (string.IsNullOrEmpty(originalValue)) { continue; } int foundIndex = 0; int startIndex = 0; PropertyDependency propertyDependency = null; while ((foundIndex = newValue.IndexOf(ActionReferencePrefix, startIndex, StringComparison.OrdinalIgnoreCase)) >= 0) { int suffixIndex = newValue.IndexOf(SubstitutionSuffix, foundIndex, StringComparison.OrdinalIgnoreCase); if (suffixIndex == -1) { _ruleContext.Logger.InvalidActionReferenceToken(options.Name ?? actionIndex.ToString(), property.Name); break; } startIndex = suffixIndex; string actionAndResult = newValue[(foundIndex + ActionReferencePrefix.Length)..suffixIndex];
public void Execute_ClassWithNamedAnnotatedProperties_ReturnsServiceNameFromAttribute() { var selector = new AnnotatedPropertyDependencySelector(new PropertySelector()); PropertyDependency propertyDependency = selector.Execute(typeof(FooWithNamedAnnotatedProperyDependency)).FirstOrDefault(); Assert.Equal("AnotherBar", propertyDependency.ServiceName); }
public void ToString_PropertyDependency_ReturnsDescriptiveDescription() { PropertyDependency propertyDependency = new PropertyDependency(); propertyDependency.Property = typeof(FooWithProperyDependency).GetProperty("Bar"); var description = propertyDependency.ToString(); Assert.StartsWith("[Target Type", description); }
public static void RegisterClass(Type type) { var typeInfo = type.GetTypeInfo(); var propertyRegistrations = new Dictionary <DependencyBase, List <string> >(); foreach (var property in typeInfo.DeclaredProperties) { SortedSet <string> dependsOn = new SortedSet <string>(); void AddDependency(string path) { while (path != "") { dependsOn.Add(path); if (path.Contains(".")) { path = path.Substring(0, path.LastIndexOf(".")); } else { path = ""; } } } foreach (var att in property.GetCustomAttributes <DependsOnAttribute>()) { foreach (var prop in att.PropertyPaths) { AddDependency(prop); } } foreach (var path in dependsOn) { var dependency = new PropertyDependency(property.Name); if (propertyRegistrations.TryGetValue(dependency, out var dependencies)) { dependencies.Add(property.Name); } else { propertyRegistrations[dependency] = new List <string>() { property.Name } }; } } Registrations.TryAdd(type, propertyRegistrations); } }
private static bool TryGetPropertyDependency(IStructuralProperty property, ODataEntityDto oDataEntity, out IDependency dependency) { object propertyValue; if (oDataEntity.TryGetPropertyValue(property, out propertyValue)) { dependency = new PropertyDependency(property, propertyValue); return(true); } dependency = null; return(false); }
void AddIfPropertyExists(PropertyDefinition targetProperty, string isGeneratedUsingPropertyName, TypeNode node) { //TODO: all properties var propertyDefinition = targetProperty.DeclaringType.Properties.FirstOrDefault(x => x.Name == isGeneratedUsingPropertyName); if (propertyDefinition == null) { LogInfo($"Could not find property '{isGeneratedUsingPropertyName}' for DependsOnAttribute assigned to '{targetProperty.Name}'."); return; } var dependency = new PropertyDependency { WhenPropertyIsSet = propertyDefinition, ShouldAlsoNotifyFor = targetProperty }; node.PropertyDependencies.Add(dependency); }
void ProcessInstructionForGet(PropertyDefinition property, Instruction instruction) { if (IsPropertyGetInstruction(instruction, out var usedProperty) || IsFieldGetInstruction(instruction, out usedProperty)) { if (usedProperty == property) { //skip where self reference return; } var dependency = new PropertyDependency { ShouldAlsoNotifyFor = property, WhenPropertyIsSet = usedProperty }; node.PropertyDependencies.Add(dependency); } }
void AddIfPropertyExists(PropertyDefinition targetProperty, string isGeneratedUsingPropertyName, TypeNode node) { //TODO: all properties var propertyDefinition = targetProperty.DeclaringType.Properties.FirstOrDefault(x => x.Name == isGeneratedUsingPropertyName); if (propertyDefinition == null) { WriteInfo($"Could not find property '{isGeneratedUsingPropertyName}' for DependsOnAttribute assigned to '{targetProperty.Name}'."); return; } var dependency = new PropertyDependency { WhenPropertyIsSet = propertyDefinition, ShouldAlsoNotifyFor = targetProperty }; node.PropertyDependencies.Add(dependency); }
public void RegisterClass(Type type) { var typeInfo = type.GetTypeInfo(); var propertyPreRegistrations = new Dictionary <DependencyBase, Dictionary <string, Type> >(); foreach (var property in typeInfo.DeclaredProperties) { Dictionary <string, Type> dependsOn = new Dictionary <string, Type>(); foreach (var att in property.GetCustomAttributes <DependsOnAttribute>()) { foreach (var prop in att.PropertyPaths) { dependsOn.Add(prop, ReflectionHelpers.GetTypeOfPath(type, prop.DisassemblePropertyPath())); } } foreach (var pathNType in dependsOn) { var dependency = new PropertyDependency(property.Name); if (propertyPreRegistrations.TryGetValue(dependency, out var dependencies)) { dependencies.Add(pathNType.Key, pathNType.Value); } else { propertyPreRegistrations[dependency] = new Dictionary <string, Type>() { { pathNType.Key, pathNType.Value } } }; } } PreRegistrations.Add(type, propertyPreRegistrations); }
public void ToString_PropertyDependency_ReturnsDescriptiveDescription() { PropertyDependency propertyDependency = new PropertyDependency(); propertyDependency.Property = typeof (FooWithProperyDependency).GetProperty("Bar"); var description = propertyDependency.ToString(); Assert.StartsWith("[Target Type", description); }
private static void CollectDependencyHierarchy(List <PropertyDependency> dependantProperties, PropertyDependency dependantProperty) { var previousCount = 0; while (previousCount != dependantProperty.DependantProperties.Count) { previousCount = dependantProperty.DependantProperties.Count; foreach (var property in dependantProperty.DependantProperties.ToList()) { foreach (var dependancy in dependantProperties.Where(item => item.PropertyName == property).SelectMany(item => item.DependantProperties)) { if (!dependantProperty.DependantProperties.Contains(dependancy)) { dependantProperty.DependantProperties.Add(dependancy); } } } } }
void ProcessInstructionForGet(PropertyDefinition property, Instruction instruction) { PropertyDefinition usedProperty; if (IsPropertyGetInstruction(instruction, out usedProperty) || IsFieldGetInstruction(instruction, out usedProperty)) { if (usedProperty == property) { //skip where self reference return; } var dependency = new PropertyDependency { ShouldAlsoNotifyFor = property, WhenPropertyIsSet = usedProperty }; node.PropertyDependencies.Add(dependency); } }