示例#1
0
        public int TryReplace <TReplEnum>(TReplEnum enum_val, IVReplaceTextCursor textCursor, CancellationToken cancellation)
        {
            int cnt = 0;

            textCursor.Reset();
            while (!textCursor.IsEmpty)
            {
                if (TryDetect(textCursor, out Expression expr, cancellation))
                {
                    var str_value = ReplaceAttr.GetArgument(expr);
                    var macro     = StringUtil.GetReplaceMacro(enum_val, ReplaceAttr, str_value);
                    textCursor.GoForwardWithReplacement(macro, expr.RemainingText);
                }
示例#2
0
        public static void ProcessIterator <TReplEnum>(IVReplaceTextCursor textCursor, Action <IVReplaceTextCursor, TReplEnum, ReplaceAttribute> act_replace)
        {
            LangLabel lang      = textCursor.VContext.LangLabel;
            var       enum_vals = (TReplEnum[])Enum.GetValues(typeof(TReplEnum));

            foreach (TReplEnum enumVal in enum_vals)
            {
                var replace_attrs = GetTextAttrib <TReplEnum, ReplaceAttribute>(enumVal)
                                    .Where(ra => ra.Lng == lang);
                foreach (var attr in replace_attrs)
                {
                    act_replace(textCursor, enumVal, attr);
                }
            }
        }
示例#3
0
 public static void ProcessReplace <TReplEnum>(this IVReplaceTextCursor textCursor, CancellationToken cancellation)
 {
     ProcessIterator <TReplEnum>(textCursor, (txt_cursor, enum_val, attr) =>
     {
         if (attr is ReplaceTextCAttribute)
         {
             var ra = (ReplaceTextCAttribute)attr;
             ra.TryReplace <TReplEnum>(enum_val, txt_cursor, cancellation);
         }
         else
         {
             throw new InvalidOperationException(
                 $"Unknown replace attribute '{attr}' in '{typeof(TReplEnum)}'");
         }
     });
 }