public PropertyInfo FindAttachedModelProperty(PropertyInfo queryProperty, PropertyInfo[] modelProperties)
		{
			var queryPropertyName = queryProperty.Name;
			if (queryProperty.PropertyType != typeof (string)) return null;
			if (!queryPropertyName.EndsWith(Suffix)) return null;
			return
				modelProperties.Where(o => o.PropertyType == typeof (string))
				               .FirstOrDefault(modelProperty => queryPropertyName == modelProperty.Name + Suffix);
		}
示例#2
0
        private IdentifierMap MapIdentifier(PropertyInfo[] properties)
        {
            PropertyInfo id = properties.Where(x => x.Name.Equals(DefaultIdentifier)).FirstOrDefault();

            if (id == null)
            {
                throw new MappingException("Entity does not contain an identifier [Id].");
            }

            return new IdentifierMap(id, id.Name, id.PropertyType);
        }
        protected virtual PropertyInfo[] GetEnumerableIndexablePropertyInfos(PropertyInfo[] properties, IStructureProperty parent = null, ICollection<string> nonIndexablePaths = null, ICollection<string> indexablePaths = null)
        {
            if (properties.Length == 0)
                return new PropertyInfo[0];

            var filteredProperties = properties.Where(p =>
                !p.PropertyType.IsSimpleType() &&
                p.PropertyType.IsEnumerableType() &&
                !p.PropertyType.IsEnumerableBytesType());

            if (nonIndexablePaths != null && nonIndexablePaths.Any())
                filteredProperties = filteredProperties.Where(p => !nonIndexablePaths.Contains(
                    PropertyPathBuilder.BuildPath(parent, p.Name)));

            if (indexablePaths != null && indexablePaths.Any())
                filteredProperties = filteredProperties.Where(p => indexablePaths.Contains(
                    PropertyPathBuilder.BuildPath(parent, p.Name)));

            return filteredProperties.ToArray();
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="properties"></param>
 /// <returns></returns>
 private static IEnumerable<PropertyInfo> GetAuditedProperties(PropertyInfo[] properties)
 {
     return properties.Where(x => x.GetCustomAttribute<ParentAuditedAttribute>(false) != null);
 }
		public static PropertySet[] RequireBase(ComponentModel model, PropertyInfo[] properties,
		                                        PropertySetBuilder propertySetBuilder)
		{
			return properties.Where(p => p.DeclaringType != model.Implementation)
				.Select(p => propertySetBuilder(p, false)).ToArray();
		}
示例#6
0
        private List<string> GetPropertyNames(PropertyInfo[] properties)
        {
            List<string> result = new List<string>();

            List<PropertyInfo> props = properties.Where(p => p.Name.EndsWith("RepetitionsUsed")).ToList();
            foreach (PropertyInfo p in props)
                result.Add(p.Name.Remove(p.Name.IndexOf("RepetitionsUsed")));

            return result;
        }
        private void Prune(IContentTypeBase contentType, Type documentClrType, PropertyInfo[] tabProperties, IEnumerable<PropertyInfo> propertiesOfRoot)
        {
            bool modified = false;

            var propertiesToKeep = propertiesOfRoot.Where(x =>
            {
                var attr = x.DeclaringType.GetCodeFirstAttribute<CodeFirstCommonBaseAttribute>(false);
                return x.DeclaringType == documentClrType || attr != null;
            }).Select(x => x.GetCodeFirstAttribute<ContentPropertyAttribute>().Alias)
            .Union(tabProperties.Where(x =>
            {
                var attr = x.DeclaringType.GetCodeFirstAttribute<CodeFirstCommonBaseAttribute>(false);
                return x.DeclaringType == documentClrType || attr != null;
            }).SelectMany(x =>
            {
                return x.PropertyType.GetProperties().Where(y =>
                {
                    return (y.DeclaringType == x.PropertyType || y.DeclaringType.GetCodeFirstAttribute<CodeFirstCommonBaseAttribute>(false) != null) && y.GetCodeFirstAttribute<ContentPropertyAttribute>() != null;
                }).Select(y =>
                    {
                      var attr = y.GetCodeFirstAttribute<ContentPropertyAttribute>();
                      var tabAttr = x.GetCodeFirstAttribute<ContentTabAttribute>();
                      return attr.AddTabAliasToPropertyAlias ? attr.Alias + "_" + tabAttr.Name.Replace(" ", "_") : attr.Alias;
                    });
            })).ToList();

            propertiesToKeep.AddRange(documentClrType.GetCustomAttributes<DoNotRemovePropertyAttribute>(true).Select(x => x.PropertyAlias));

            //loop through all the properties on the ContentType to see if they should be removed.
            var existingUmbracoProperties = contentType.PropertyTypes.ToArray();
            int length = contentType.PropertyTypes.Count();
            for (int i = 0; i < length; i++)
            {
                if (!propertiesToKeep.Any(x => x.Equals(existingUmbracoProperties[i].Alias, StringComparison.InvariantCultureIgnoreCase)))
                {
                    if (contentType.PropertyTypeExists(existingUmbracoProperties[i].Alias))
                    {
                        modified = true;
                        //remove the property
                        contentType.RemovePropertyType(existingUmbracoProperties[i].Alias);
                        var alias = existingUmbracoProperties[i].Alias;
                        var children = GetChildren(contentType);

                        //TODO is this needed? I reckon it shouldn't be
                        RemovePropertyFromChildren(alias, children);
                    }
                }
            }

            if (modified)
            {
                contentType.ResetDirtyProperties(false);
                Save(contentType);
            }
        }