Esempio n. 1
0
        public static bool GetInfoFromMember <T>(this BaseMightyMember mightyMember, object target, string memberName,
                                                 out MightyInfo <T> info, GetValuePredicate <T> predicate = null, bool neverInWrapper = false)
        {
            if (string.IsNullOrWhiteSpace(memberName))
            {
                info = null;
                return(false);
            }

            if (predicate != null && predicate(memberName, out var outValue))
            {
                info = new MightyInfo <T>(null, null, outValue);
                return(true);
            }

            if (target is BaseWrapperAttribute wrapper)
            {
                if (neverInWrapper)
                {
                    return(mightyMember.GetInfoFromMember(mightyMember.GetWrapperTarget(wrapper), memberName, out info, predicate));
                }
                if (GetCallbackName(target, memberName, out var callbackName))
                {
                    return(mightyMember.GetInfoFromMember(mightyMember.GetWrapperTarget(wrapper), callbackName, out info, predicate));
                }
            }

            if (InternalGetInfoFromMember(target, memberName, true, out info))
            {
                return(true);
            }

            if (!(mightyMember is MightySerializedField serializedField))
            {
                return(false);
            }

            target = serializedField.Property.GetPropertyTargetReference();
            if (target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 &&
                InternalGetInfoFromMember(target, memberName, true, out info))
            {
                return(true);
            }


            if (!TypeUtilities.TryConvertStringToType(memberName, out T value))
            {
                return(false);
            }

            info = new MightyInfo <T>(target, null, value);
            return(true);
        }
Esempio n. 2
0
        public static bool GetArrayInfoFromMember(this BaseMightyMember mightyMember, object target, string memberName,
                                                  out MightyInfo <object[]> mightyInfo)
        {
            if (string.IsNullOrEmpty(memberName))
            {
                mightyInfo = null;
                return(false);
            }

            if (target is BaseWrapperAttribute wrapper && GetCallbackName(target, memberName, out var callbackName))
            {
                return(GetArrayInfoFromMember(mightyMember, mightyMember.GetWrapperTarget(wrapper),
                                              callbackName, out mightyInfo));
            }
            if (InternalGetArrayInfoFromMember(target, memberName, out mightyInfo))
            {
                return(true);
            }

            if (!(mightyMember is MightySerializedField serializedField))
            {
                return(false);
            }

            target = serializedField.Property.GetPropertyTargetReference();
            return(target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 &&
                   InternalGetArrayInfoFromMember(target, memberName, out mightyInfo));
        }
Esempio n. 3
0
        public static bool GetMightyVoidMethod(this BaseMightyMember mightyMember, object target, string memberName,
                                               CallbackSignature callbackSignature, out MightyVoidMethod method)
        {
            if (string.IsNullOrWhiteSpace(memberName))
            {
                method = null;
                return(false);
            }

            if (target is BaseWrapperAttribute wrapper && GetCallbackName(target, memberName, out var callbackName))
            {
                return(mightyMember.GetMightyVoidMethod(mightyMember.GetWrapperTarget(wrapper), callbackName, callbackSignature,
                                                        out method));
            }

            if (InternalGetMightyVoidMethod(target, memberName, callbackSignature, out method))
            {
                return(true);
            }

            if (!(mightyMember is MightySerializedField serializedField))
            {
                return(false);
            }

            target = serializedField.Property.GetPropertyTargetReference();
            return(target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 &&
                   InternalGetMightyVoidMethod(target, memberName, callbackSignature, out method));
        }
Esempio n. 4
0
        public static object GetCallbackTarget(BaseMightyMember mightyMember, object target, string callbackName,
                                               CallbackSignature callbackSignature, out MemberInfo outMember)
        {
            outMember = null;
            if (string.IsNullOrWhiteSpace(callbackName))
            {
                return(null);
            }
            if (target.GetType().GetMemberInfo(callbackName, callbackSignature, out outMember))
            {
                return(target);
            }

            if (target is BaseWrapperAttribute wrapper && GetCallbackName(target, callbackName, out var callbackNameValue))
            {
                return(GetCallbackTarget(mightyMember, mightyMember.GetWrapperTarget(wrapper), callbackNameValue,
                                         callbackSignature, out outMember));
            }

            return(null);
        }
Esempio n. 5
0
        public static bool GetValueFromMember <T>(this BaseMightyMember mightyMember, object target, string memberName, out T value,
                                                  GetValuePredicate <T> predicate = null)
        {
            if (string.IsNullOrWhiteSpace(memberName))
            {
                value = default;
                return(false);
            }

            if (predicate != null && predicate(memberName, out value))
            {
                return(true);
            }

            if (target is BaseWrapperAttribute wrapper && GetCallbackName(target, memberName, out var callbackName))
            {
                return(mightyMember.GetValueFromMember(mightyMember.GetWrapperTarget(wrapper), callbackName, out value, predicate));
            }

            if (InternalGetValueFromMember(target, memberName, true, out value))
            {
                return(true);
            }

            if (!(mightyMember is MightySerializedField serializedField))
            {
                return(false);
            }

            target = serializedField.Property.GetPropertyTargetReference();
            if (target.GetType().GetCustomAttributes(typeof(SerializableAttribute), true).Length > 0 &&
                InternalGetValueFromMember(target, memberName, true, out value))
            {
                return(true);
            }

            return(TypeUtilities.TryConvertStringToType(memberName, out value));
        }