Exemplo n.º 1
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 + "");
        }
Exemplo n.º 2
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);
 }