/// <summary> /// Retrieves a property from the selected type, recursively using "." as a delimiter /// </summary> /// <param name="target">The target to retrieve the property from</param> /// <param name="path">The path of the property to find</param> /// <returns>The object instance of the property being searched for</returns> public static IMetaProperty GetProperty(this IHasProperties target, string path) { if (target is null) { throw new System.ArgumentNullException(nameof(target)); } if (path is null) { throw new System.ArgumentNullException(nameof(path)); } IMetaProperty m = null; foreach (string chunk in path.Split('.')) { m = (m?.Type ?? target).Properties.FirstOrDefault(p => p.Name == chunk); if (m is null) { return(null); } } return(m); }
private static bool AddPropertyValues(IHasProperties product, CatalogModule.Property property) { bool result; var defaultProperty = product.Properties.FirstOrDefault(p => p.Id.EqualsInvariant(property.Id)); if (defaultProperty == null) { result = false; } else { if (product.PropertyValues == null) { product.PropertyValues = new List <PropertyValue>(); } foreach (var propertyValue in property.Values.Select(value => value.ToCoreModel())) { propertyValue.Property = defaultProperty; propertyValue.PropertyId = defaultProperty.Id; propertyValue.PropertyName = defaultProperty.Name; product.PropertyValues.Add(propertyValue); } result = true; } return(result); }
private ICommonProperty[] GetPatchingProperties(IHasProperties frameworkElementType, FrameworkElementPatchingType patchingType) { return(frameworkElementType.Properties .Where(property => property.NotContainsAttribute <NotPatchingPropertyAttribute>() && (!applicationPatcherWpfConfiguration.SkipConnectingByNameIfNameIsInvalid || nameRulesService.IsNameValid(property.Name, UseNameRulesFor.DependencyProperty)) && ( patchingType == FrameworkElementPatchingType.All || property.ContainsAttribute <PatchingPropertyAttribute>() || property.ContainsAttribute <ConnectPropertyToFieldAttribute>())) .ToArray()); }
private ICommonProperty[] GetPatchingProperties(IHasProperties viewModelType, IHasType commandType, ViewModelPatchingType patchingType) { return(viewModelType.Properties .Select(property => property) .Where(property => property.NotContainsAttribute <NotPatchingPropertyAttribute>() && (!applicationPatcherWpfConfiguration.SkipConnectingByNameIfNameIsInvalid || nameRulesService.IsNameValid(property.Name, UseNameRulesFor.Property)) && ( patchingType == ViewModelPatchingType.All && property.IsNotInheritedFrom(commandType) || property.ContainsAttribute <PatchingPropertyAttribute>() || property.ContainsAttribute <ConnectPropertyToFieldAttribute>())) .ToArray()); }
private static bool TrySetCustomProperty(IHasProperties product, CatalogModule.Property property) { bool result; if (property.Multivalue || property.Dictionary) { var propertyValues = product.PropertyValues?.Where( propertyValue => propertyValue.Property != null && propertyValue.Property.Id.EqualsInvariant(property.Id)).ToArray(); if (propertyValues.IsNullOrEmpty()) { // idle } else { if (propertyValues == null) { // idle } else { foreach (var productPropertyValue in propertyValues) { product.PropertyValues?.Remove(productPropertyValue); } } } result = AddPropertyValues(product, property); } else { var productPropertyValue = product.PropertyValues?.FirstOrDefault( propertyValue => propertyValue.Property != null && propertyValue.Property.Id.EqualsInvariant(property.Id)); if (productPropertyValue != null) { var propertyValue = property.Values.FirstOrDefault(); productPropertyValue.Value = propertyValue?.Value; result = true; } else { result = AddPropertyValues(product, property); } } return(result); }
public static void ReadProperties(IHasProperties owner, XElement root) { var element = root.GetElement("properties"); if (element != null) { foreach (var property in element.GetElements("property")) { var key = property.ReadAttribute("name", string.Empty); var value = property.ReadAttribute("value", string.Empty); owner.Properties.Add(key, value); } } }
private static bool TrySetCustomProperty(IHasProperties product, Property property) { bool result; if (property.Multivalue || property.Dictionary) { var properties = product.Properties?.Where(prop => prop.Id.EqualsInvariant(property.Id)).ToArray(); if (properties.IsNullOrEmpty()) { // idle } else { if (properties == null) { // idle } else { foreach (var productProperty in properties) { productProperty.Values = new List <PropertyValue>(); } } } result = AddPropertyValues(product, property); } else { var productProperty = product.Properties?.FirstOrDefault(prop => prop.Id.EqualsInvariant(property.Id)); if (productProperty != null) { productProperty.Values = property.Values; result = true; } else { result = AddPropertyValues(product, property); } } return(result); }
private void SetVirtualOnProperties(IHasProperties type) { log.Info("Patching properties..."); if (!type.Properties.Any()) { log.Info("Not Found properties"); return; } log.Debug("Properties found:", type.Properties.Select(property => property.FullName)); foreach (var property in type.Properties) { SetVirtualMethod(property.MonoCecil.GetMethod); SetVirtualMethod(property.MonoCecil.SetMethod); } log.Info("Properties was patched"); }
private static bool AddPropertyValues(IHasProperties product, Property property) { bool result; var foundProperty = product.Properties.FirstOrDefault(p => p.Id.EqualsInvariant(property.Id)); if (foundProperty == null) { result = false; } else { foreach (var propertyValue in property.Values) { propertyValue.Property = foundProperty; propertyValue.PropertyId = foundProperty.Id; propertyValue.PropertyName = foundProperty.Name; foundProperty.Values.Add(propertyValue); } result = true; } return(result); }
public static IEnumerable <ICommonProperty> GetProperties(this IHasProperties hasProperties, string propertyTypeFullName) { return(hasProperties.Properties.Where(property => property.Is(propertyTypeFullName))); }
public static IEnumerable <ICommonProperty> GetProperties(this IHasProperties hasProperties, IHasType hasType) { return(hasProperties.GetProperties(hasType.Type)); }
public static ICommonProperty GetProperty(this IHasProperties hasProperties, string propertyName, bool throwExceptionIfNotFound = false) { return((hasProperties.PropertyNameToProperties.TryGetValue(propertyName, out var commonProperties) ? commonProperties : Enumerable.Empty <ICommonProperty>()).SingleOrDefault(throwExceptionIfNotFound, propertyName)); }
public static bool TryGetProperty(this IHasProperties hasProperties, string propertyName, out ICommonProperty foundCommonProperty) { return((foundCommonProperty = hasProperties.GetProperty(propertyName)) != null); }
public static IEnumerable <SyntaxNode> GetPropNodes(this SyntaxGenerator gen, IHasProperties holder) => holder.Properties.OfType <IHasSyntaxNodes>().SelectMany(n => n.GetNodes(gen));