示例#1
0
        /// <summary>
        /// 获取方法的修饰符
        /// </summary>
        /// <param name="reflectMethodInfo">方法反射信息</param>
        /// <returns></returns>
        public static string GetModifier(MethodInfo reflectMethodInfo)
        {
            string result = AsyncReverser.GetAsync(reflectMethodInfo);

            // 没有相应的信息,说明没有使用以上关键字修饰
            if (!reflectMethodInfo.IsHideBySig)
            {
                return(result);
            }


            if (!reflectMethodInfo.DeclaringType.IsInterface)
            {
                //此段代码由工良提供
                if (reflectMethodInfo.IsStatic)
                {
                    return("static " + result);
                }



                // 是否抽象方法
                if (reflectMethodInfo.IsAbstract)
                {
                    return("abstract " + result);
                }



                // virtual、override、实现接口的方法
                if (reflectMethodInfo.IsVirtual)
                {
                    // 实现接口的方法
                    if (reflectMethodInfo.IsFinal)
                    {
                        return(result);
                    }


                    // 没有被重写,则为 virtual
                    if (reflectMethodInfo.Equals(reflectMethodInfo.GetBaseDefinition()))
                    {
                        return("virtual " + result);
                    }
                    else
                    {
                        return("override " + result);
                    }
                }
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// 获取方法的修饰符
        /// </summary>
        /// <param name="reflectMethodInfo">方法反射信息</param>
        /// <returns></returns>
        public static string GetModifier(MethodInfo reflectMethodInfo)
        {
            string result = AsyncReverser.GetAsync(reflectMethodInfo);

            if (reflectMethodInfo.IsStatic)
            {
                return("static " + result);
            }
            else if (!reflectMethodInfo.DeclaringType.IsInterface)
            {
                //如果没有被重写
                if (reflectMethodInfo.Equals(reflectMethodInfo.GetBaseDefinition()))
                {
                    if (reflectMethodInfo.IsAbstract)
                    {
                        return("abstract " + result);
                    }
                    else if (!reflectMethodInfo.IsFinal && reflectMethodInfo.IsVirtual)
                    {
                        return("virtual " + result);
                    }
                    else
                    {
                        var baseType = reflectMethodInfo.DeclaringType.BaseType;
                        if (baseType != null && baseType != typeof(object))
                        {
                            var baseInfo = reflectMethodInfo
                                           .DeclaringType
                                           .BaseType
                                           .GetMethod(reflectMethodInfo.Name, BindingFlags.Public
                                                      | BindingFlags.Instance
                                                      | BindingFlags.NonPublic);
                            if (reflectMethodInfo != baseInfo)
                            {
                                return("new " + result);
                            }
                        }
                    }
                }
                else
                {
                    return(result + "override ");
                }
            }
            return(result + "");
        }
示例#3
0
 /// <summary>
 /// 获取方法的修饰符
 /// </summary>
 /// <param name="reflectMethodInfo">方法反射信息</param>
 /// <returns></returns>
 public static string GetCanOverrideModifier(MethodInfo reflectMethodInfo)
 {
     //如果没有被重写
     if (reflectMethodInfo.Equals(reflectMethodInfo.GetBaseDefinition()))
     {
         string result = AsyncReverser.GetAsync(reflectMethodInfo);
         if (reflectMethodInfo.DeclaringType.IsInterface)
         {
             return(result);
         }
         else if (reflectMethodInfo.IsAbstract)
         {
             return("abstract " + result);
         }
         else if (reflectMethodInfo.IsVirtual)
         {
             return("virtual " + result);
         }
     }
     return(null);
 }