Beispiel #1
0
        // TODO: Invert if without else
        // ex. if (cond) DoSomething () == if (!cond) return; DoSomething ()
        // beware of loop contexts return should be continue then.
        public void Run(RefactoringContext context)
        {
            var ifStatement = GetIfElseStatement(context);

            using (var script = context.StartScript()) {
                script.Replace(ifStatement.Condition, CppUtil.InvertCondition(ifStatement.Condition));
                script.Replace(ifStatement.TrueStatement, ifStatement.FalseStatement);
                script.Replace(ifStatement.FalseStatement, ifStatement.TrueStatement);
                script.FormatText(ctx => GetIfElseStatement(ctx));
            }
        }
Beispiel #2
0
 static string PSTypeCppName(Type type)
 {
     if (type.IsEnum)
     {
         return(CppUtil.EnumModuleName(type.Name));
     }
     else if (MetaTypes.PSTypeSet.Contains(type))
     {
         return(TypeCppName(type));
     }
     return(CppUtil.CppStyleName(type.Name));
 }
Beispiel #3
0
 public static string GetCppTypeName(Type type)
 {
     if (type.IsEnum)
     {
         return(CppUtil.EnumModuleName(type.Name));
     }
     else if (type.IsGenericType && type.IsGenericTypeDefinition == false)
     {
         if (MetaTypes.PSGenericTypeTypeSet.Contains(type.GetGenericTypeDefinition()))
         {
             return(GenericTypeCppName(type, type.GetGenericArguments().First()));
         }
         throw new System.Exception("无法识别的类型");
     }
     else
     {
         return(PSTypeCppName(type));
     }
 }