// 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)); } }
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)); }
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)); } }