public static PersistablePropertyInformation[] GetPersistableElements(this Type type) { return(AutoCache.Get(type, () => (from each in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) let persistableAttribute = each.GetCustomAttributes(typeof(PersistableAttribute), true).FirstOrDefault() as PersistableAttribute where !each.IsInitOnly && !each.GetCustomAttributes(typeof(NotPersistableAttribute), true).Any() && (each.IsPublic || persistableAttribute != null) select new PersistablePropertyInformation { SetValue = (o, o1, arg3) => each.SetValue(o, o1), GetValue = (o, objects) => each.GetValue(o), SerializeAsType = (persistableAttribute != null ? persistableAttribute.SerializeAsType : null) ?? each.FieldType, DeserializeAsType = (persistableAttribute != null ? persistableAttribute.DeserializeAsType : null) ?? each.FieldType, ActualType = each.FieldType, Name = (persistableAttribute != null ? persistableAttribute.Name : null) ?? each.Name }).Union((from each in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) let setMethodInfo = each.GetSetMethod(true) let getMethodInfo = each.GetGetMethod(true) let persistableAttribute = each.GetCustomAttributes(typeof(PersistableAttribute), true).FirstOrDefault() as PersistableAttribute where ((setMethodInfo != null && getMethodInfo != null) && !each.GetCustomAttributes(typeof(NotPersistableAttribute), true).Any() && (each.GetSetMethod(true).IsPublic&& each.GetGetMethod(true).IsPublic)) || persistableAttribute != null select new PersistablePropertyInformation { SetValue = setMethodInfo != null ? new Action <object, object, object[]>(each.SetValue) : null, GetValue = getMethodInfo != null ? new Func <object, object[], object>(each.GetValue) : null, SerializeAsType = (persistableAttribute != null ? persistableAttribute.SerializeAsType : null) ?? each.PropertyType, DeserializeAsType = (persistableAttribute != null ? persistableAttribute.DeserializeAsType : null) ?? each.PropertyType, ActualType = each.PropertyType, Name = (persistableAttribute != null ? persistableAttribute.Name : null) ?? each.Name })).ToArray() )); /* * Fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(each => * !each.IsInitOnly && !each.GetCustomAttributes(typeof (NotPersistableAttribute), true).Any() && ( * each.IsPublic || * each.GetCustomAttributes(typeof (PersistableAttribute), true).Any()) * ).ToArray(), */ /* * Properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).Where(each => { * * var sm = each.GetSetMethod(true); * var gm = each.GetGetMethod(true); * * return * ((sm != null && gm != null) && * !each.GetCustomAttributes(typeof (NotPersistableAttribute), true).Any() && * (each.GetSetMethod(true).IsPublic && each.GetGetMethod(true).IsPublic)) || * each.GetCustomAttributes(typeof (PersistableAttribute), true).Any(); * }).ToArray()*/ }
public static PersistableInfo GetPersistableInfo(this Type t) { return(AutoCache.Get(t, () => new PersistableInfo(t))); }