public void SetMember(MemberInfo member0) { lock (M2C) { M2C[member0] = this; } if (member0 is Type) { IsNonValue = true; return; } member = member0; if (MemberInfoExtensions.MemberIsReadOnly(member0)) { // cant restore? // SkipSaveOnExit = true; IsReadOnly = true; } IsStatic = MemberInfoExtensions.MemberIsStatic(member0); UseSingleton = !IsStatic; ReturnType = MemberInfoExtensions.MemberReturnType(member0); if (ReturnType.IsGenericType && ReturnType.GetGenericTypeDefinition() == (typeof(ListAsSet <>))) { return; } }
public static bool IsPossibleConfig(MemberInfo info) { if (MemberInfoExtensions.HasAttribute(info, typeof(ConfigSettingAttribute))) { return(true); } if (MemberInfoExtensions.HasAttribute(info, typeof(NotConfigurable))) { return(false); } if (info.DeclaringType.IsEnum) { return(false); } { var inf = info as FieldInfo; if (inf != null && (inf.IsStatic || ConfigSettingAttribute.IsSingletonClass(inf.DeclaringType)) && !inf.IsInitOnly && !inf.IsLiteral) { if (MemberInfoExtensions.IsSettableType(inf.FieldType)) { if (inf.DeclaringType.IsValueType) { return(false); } return(true); } } } { var inf = info as PropertyInfo; if (inf != null) { if (inf.GetSetMethod() == null) { return(false); } info = inf.GetGetMethod(); var inf0 = info as MethodInfo; if (inf0 != null && (inf0.IsStatic || ConfigSettingAttribute.IsSingletonClass(inf0.DeclaringType)) && inf.CanRead && inf.CanWrite) { if (MemberInfoExtensions.IsSettableType(inf.PropertyType)) { if (inf0.DeclaringType.IsValueType) { return(false); } return(true); } ; } } } return(false); }
public static object GuessSingletonForType(this Type m) { if (ConfigSettingAttribute.CantBeSingletonValueMember(m)) { return(null); } object _singleton; { foreach (var fnd0 in m.ReflectedType.GetMembers(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.FlattenHierarchy)) { var mrt = fnd0.MemberReturnType(); if (mrt == null) { continue; } if (!m.IsAssignableFrom(mrt)) { continue; } if (ConfigSettingAttribute.CantBeSingletonValueMember(fnd0)) { continue; } _singleton = MemberInfoExtensions.MemberValue(fnd0, null); if (_singleton != null) { return(_singleton); } } } { if (ConfigSettingAttribute.sysvarCtx != null) { _singleton = MemberInfoExtensions.FindSubValueOfType(ConfigSettingAttribute.sysvarCtx, m, 2); if (_singleton != null) { return(_singleton); } } } return(null); }
public static bool CantBeSingletonValueMember(MemberInfo fnd0) { if (fnd0 == null) { return(true); } if (fnd0 is _EventInfo) { return(true); } if (fnd0 is Type) { return(true); } if (!MemberInfoExtensions.MemberIsStatic(fnd0)) { return(true); } if (fnd0.MemberReturnType() == null) { return(true); } return(false); }
public static bool IsGoodForConfig(MemberInfo info, bool notDeclaredOK, bool notPublicOK, bool notWriteableOK, bool notFromStringOK) { if (MemberInfoExtensions.HasAttribute(info, typeof(ConfigSettingAttribute))) { return(true); } if (MemberInfoExtensions.HasAttribute(info, typeof(NotConfigurable))) { return(false); } if (!notDeclaredOK) { return(false); } if (info.DeclaringType.IsEnum) { return(false); } { var inf = info as FieldInfo; if (inf != null) { bool readOnly = inf.IsInitOnly || inf.IsLiteral; if ((inf.IsStatic || IsSingletonClass(inf.DeclaringType)) && (notPublicOK || inf.IsPublic) && (notWriteableOK || !readOnly)) { if (!notFromStringOK) { if (inf.FieldType.IsArray) { return(false); } } //if (readOnly) notFromStringOK = true; if (notFromStringOK || MemberInfoExtensions.IsSettableType(inf.FieldType)) { if (inf.DeclaringType.IsValueType) { if (readOnly) { return(false); } return(false); } return(true); } } } } { var inf = info as PropertyInfo; if (inf != null) { MethodInfo m = inf.GetGetMethod(true) ?? inf.GetSetMethod(true); if ((m.IsStatic || IsSingletonClass(inf.DeclaringType)) && (notPublicOK || m.IsPublic) && inf.CanRead && (notWriteableOK || inf.CanWrite)) { bool readOnly = !inf.CanWrite; //if (readOnly) notFromStringOK = true; if (notFromStringOK || MemberInfoExtensions.IsSettableType(inf.PropertyType)) { if (inf.DeclaringType.IsValueType) { if (readOnly) { return(false); } return(false); } return(true); } ; } } } return(false); }
private object ChangeType(object value, Type parameterType) { return(MemberInfoExtensions.ChangeType(value, parameterType)); }