Beispiel #1
0
 public PropertyMapping(IPropertyValidator pv)
 {
     this.PropertyValidator = pv;
     GetValue = ReflectionTools.CreateGetter <T, P>(pv.PropertyInfo);
     SetValue = ReflectionTools.CreateSetter <T, P>(pv.PropertyInfo);
     Mapping  = Signum.Web.Mapping.New <P>();
 }
Beispiel #2
0
        internal PropertyValidator(PropertyInfo pi)
        {
            this.PropertyInfo = pi;

            this.Validators = pi.GetCustomAttributes(typeof(ValidatorAttribute), false).OfType <ValidatorAttribute>().OrderBy(va => va.Order).ThenBy(va => va.GetType().Name).ToList();

            this.GetValue = ReflectionTools.CreateGetter <T>(pi);
            this.SetValue = ReflectionTools.CreateSetter <T>(pi);
        }
Beispiel #3
0
 static Func <ModifiableEntity, object?>[] ModifiableFieldGetters(Type type)
 {
     lock (getterCache)
         return(getterCache.GetOrCreate(type, () =>
         {
             FieldInfo[] aux = Reflector.InstanceFieldsInOrder(type);
             return aux.Where(fi => Reflector.IsModifiableIdentifiableOrLite(fi.FieldType) && !IsIgnored(fi))
             .Select(fi => ReflectionTools.CreateGetter <ModifiableEntity, object?>(fi) !)
             .ToArray();
         }));
Beispiel #4
0
        internal PropertyValidator(PropertyInfo pi)
        {
            this.PropertyInfo = pi;

            this.Validators = pi.GetCustomAttributes(typeof(ValidatorAttribute), false).OfType <ValidatorAttribute>().OrderBy(va => va.Order).ThenBy(va => va.GetType().Name).ToList();

            var nullable = pi.IsNullable();

            if (nullable == false && !this.Validators.Any(v => v is NotNullValidatorAttribute))
            {
                this.Validators.Add(new NotNullValidatorAttribute());
            }

            this.GetValue = ReflectionTools.CreateGetter <T, object?>(pi) !;
            this.SetValue = ReflectionTools.CreateSetter <T, object?>(pi) !;
        }
        static TypeAttributePack?GetFieldsAndProperties(Type type)
        {
            lock (fieldAndProperties)
            {
                return(fieldAndProperties.GetOrCreate(type, () =>
                {
                    var list = Reflector.InstanceFieldsInOrder(type).Where(fi => fi.HasAttribute <T>() || (Reflector.TryFindPropertyInfo(fi)?.HasAttribute <T>() ?? false)).ToList();

                    if (list.Count == 0)
                    {
                        return null;
                    }

                    return new TypeAttributePack(
                        fields: list.Select(fi => ReflectionTools.CreateGetter <ModifiableEntity, object?>(fi) !).ToArray(),
                        propertyNames: list.Select(fi => Reflector.FindPropertyInfo(fi).Name).ToArray()
                        );
                }));
    public static List <MemberEntry <T> > GenerateList <T>(MemberOptions options, Type?type = null)
    {
        if (type != null && !typeof(T).IsAssignableFrom(type))
        {
            throw new InvalidOperationException($"Type {type} is assignable {typeof(T)}");
        }

        var finalType = type ?? typeof(T);

        PropertyInfo[] properties = (options & MemberOptions.Properties) == 0 ? new PropertyInfo[0] : typeof(T).GetProperties(bf);
        FieldInfo[]    fields     = (options & MemberOptions.Fields) == 0 ? new FieldInfo[0] : typeof(T).GetFields(bf);

        var members = properties.Where(p => p.GetIndexParameters().Length == 0).Cast <MemberInfo>()
                      .Concat(fields.Cast <MemberInfo>()).OrderBy(e => e.MetadataToken).ToArray();

        var result = members.Select(m => new MemberEntry <T>(
                                        m.Name, m,
                                        options.IsSet(MemberOptions.Getter) ? ReflectionTools.CreateGetter <T, object?>(m) : null,
                                        options.IsSet(MemberOptions.Setters) ? ReflectionTools.CreateSetter <T, object?>(m) : null
                                        )).ToList();

        return(result);
    }
Beispiel #7
0
 public PropertyConverter(Type type, IPropertyValidator pv)
 {
     this.PropertyValidator = pv;
     GetValue = ReflectionTools.CreateGetter <ModifiableEntity, object?>(pv.PropertyInfo);
     SetValue = ReflectionTools.CreateSetter <ModifiableEntity, object?>(pv.PropertyInfo);
 }