Esempio n. 1
0
        internal static bool InternalGetInfoFromMember <T>(object target, string memberName, bool checkElementType, out MightyInfo <T> info)
        {
            var callbackSignature = new CallbackSignature(typeof(T), checkElementType);

            var fieldInfo = ReflectionUtilities.GetField(target.GetType(), memberName);

            if (callbackSignature.IsFieldValid(fieldInfo))
            {
                info = new MightyInfo <T>(target, fieldInfo, (T)fieldInfo.GetValue(target));
                return(true);
            }

            var propertyInfo = ReflectionUtilities.GetProperty(target.GetType(), memberName);

            if (callbackSignature.IsPropertyValid(propertyInfo))
            {
                info = new MightyInfo <T>(target, propertyInfo, (T)propertyInfo.GetValue(target));
                return(true);
            }

            var methodInfo = ReflectionUtilities.GetMethod(target.GetType(), memberName);

            if (callbackSignature.IsMethodValid(methodInfo))
            {
                info = new MightyInfo <T>(target, methodInfo, (T)methodInfo.Invoke(target, null));
                return(true);
            }

            info = null;
            return(false);
        }
Esempio n. 2
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. 3
0
 private bool GetDrawerForMember(BaseMightyMember member, CallbackSignature signature, out MightyMethod <object> drawerMethod,
                                 BasePropertyDrawerAttribute attribute)
 {
     if (GetDrawerForMember(member.ID, signature, out drawerMethod))
     {
         return(true);
     }
     EnableDrawer(member, attribute);
     return(GetDrawerForMember(member.ID, signature, out drawerMethod));
 }
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
 private bool GetDrawerForMember(long id, CallbackSignature signature, out MightyMethod <object> drawerMethod) =>
 m_customDrawerCache.TryGetValue(id, signature, out drawerMethod);
Esempio n. 6
0
 private void InitCallback(BaseMightyMember mightyMember, object target, string callbackName, CallbackSignature signature)
 {
     mightyMember.GetMightyMethod <object>(target, callbackName, signature, out var mightyMethod);
     if (mightyMethod != null)
     {
         m_customDrawerCache[mightyMember, signature] = mightyMethod;
     }
 }
Esempio n. 7
0
        private static bool InternalGetMightyVoidMethod(object target, string memberName, CallbackSignature callbackSignature,
                                                        out MightyVoidMethod method)
        {
            var methodInfo = ReflectionUtilities.GetMethod(target.GetType(), memberName);

            if (callbackSignature.IsMethodValid(methodInfo))
            {
                method = new MightyVoidMethod(target, methodInfo);
                return(true);
            }

            method = null;
            return(false);
        }
Esempio n. 8
0
 public static MightyMethod <T> GetMightyMethod <T>(Object context, string memberName, CallbackSignature callbackSignature) =>
 string.IsNullOrWhiteSpace(memberName) ? null :
 InternalGetMightyMethod <T>(context, memberName, callbackSignature, out var method) ? method : null;
 private void InitCallback(BaseMightyMember member, object target, CustomDrawerAttribute attribute, CallbackSignature signature)
 {
     member.Property.GetMightyMethod <object>(target, attribute.DrawerCallback, signature, out var mightyMethod);
     m_customDrawerCache[member, signature] = mightyMethod;
 }