private static IEnumerable <PropertyInfo> PublicProperties(this Type type)
        {
            var propertyInfos = type.Properties(Flags.AllMembers)
                                .Where(info => !info.PropertyType.IsValueType && info.PropertyType != typeof(string) || info.CanRead && info.CanWrite)
                                .Where(IsValid)
                                .Where(info => {
                if (info.PropertyType == typeof(string) || info.PropertyType.IsNullableType())
                {
                    return(true);
                }
                var propertyTypeIsReserved = ReservedPropertyTypes.Any(_ => info.PropertyType == _);
                if (propertyTypeIsReserved)
                {
                    return(false);
                }

                var reservedPropertyInstances = ReservedPropertyInstances.Any(_ => _.IsAssignableFrom(info.PropertyType));
                if (reservedPropertyInstances)
                {
                    return(false);
                }
                if (typeof(IEnumerable).IsAssignableFrom(info.PropertyType))
                {
                    var realType = info.PropertyType.GetRealType();
                    return(!ReservedPropertyTypes.Contains(realType) && !ReservedPropertyInstances.Any(_ => _.IsAssignableFrom(realType)));
                }
                return(!info.PropertyType.IsGenericType && info.PropertyType != type && info.PropertyType != typeof(object));
            })
                                .DistinctBy(info => info.Name);


            return(propertyInfos);
        }
示例#2
0
        private static int HashCode()
        {
            var text = string.Join(Environment.NewLine, PropertyMappingRules.Select(_ => _.key)
                                   .Concat(TypeMappingRules.Select(_ => _.key))
                                   .Concat(AdditionalTypesList.Select(_ => _.FullName))
                                   .Concat(ReservedPropertyTypes.Select(type => type.FullName))
                                   .Concat(ReservedPropertyNames)
                                   .Concat(ReservedPropertyInstances.Select(_ => _.FullName))
                                   .Concat(new[] { ModelMappersNodeName, MapperAssemblyName, ModelMapperAssemblyName, DefaultContainerSuffix }).OrderBy(s => s));
            var hashCode = text
                           .GetHashCode();

            return(hashCode);
        }