public TranslationService(ITranslationContext translationContext) { _repo = translationContext; }
public static ITranslation For(RuntimeVariablesExpression runtimeVariables, ITranslationContext context) { return(ParameterSetTranslation .For(runtimeVariables.Variables, context) .WithTypes(ExpressionType.RuntimeVariables, runtimeVariables.Type)); }
public MethodInvocationTranslatable(IMethod method, ParameterSetTranslation parameters, ITranslationContext context) { _method = method; _parameters = parameters; _explicitGenericArguments = GetRequiredExplicitGenericArguments(context, out var totalLength); EstimatedSize = method.Name.Length + totalLength + parameters.EstimatedSize; }
public TypeNameTranslation(Type type, ITranslationContext context) : this(type, context.Settings) { }
public static int GetKeywordFormattingSize(this ITranslationContext context) => context.Settings.GetKeywordFormattingSize();
public static int GetTypeNameFormattingSize(this ITranslationContext context) => context.Settings.GetTypeNameFormattingSize();
private static ITranslation GetSubjectOrNull(MemberExpression memberAccess, ITranslationContext context) => GetSubjectOrNull(memberAccess.Expression, memberAccess.Member, context);
public static TypeNameTranslation GetTranslationFor( this ITranslationContext context, Type type) { return(new TypeNameTranslation(type, context)); }
public ReturnValueTranslation(GotoExpression @goto, ITranslationContext context) { _returnValueTranslation = context.GetCodeBlockTranslationFor(@goto.Value); TranslationSize = _returnValueTranslation.TranslationSize + "return ".Length; FormattingSize = context.GetControlStatementFormattingSize(); }
public ReturnValueTranslation(GotoExpression @goto, ITranslationContext context) { _returnValueTranslation = context.GetCodeBlockTranslationFor(@goto.Value); EstimatedSize = _returnValueTranslation.EstimatedSize + _returnKeyword.Length; }
public static ITranslation ForNot(ITranslation negatedValue, ITranslationContext context) => new NegationTranslation(ExpressionType.Not, _bang, negatedValue, context);
public RefParameterTranslation(Expression parameter, ITranslationContext context) { _parameterTranslation = context.GetTranslationFor(parameter); TranslationSize = _parameterTranslation.TranslationSize + _ref.Length; FormattingSize = _parameterTranslation.FormattingSize + context.GetKeywordFormattingSize(); }
private ParameterSetTranslation( IMethod method, IEnumerable <Expression> parameters, int count, ITranslationContext context) { _settings = context.Settings; _parenthesesMode = ParenthesesMode.Auto; if (count == 0) { _parameterTranslations = Enumerable <CodeBlockTranslation> .EmptyArray; TranslationSize = _openAndCloseParentheses.Length; return; } var methodProvided = method != null; if (methodProvided && method.IsExtensionMethod) { parameters = parameters.Skip(1); --count; } Count = count; ParameterInfo[] methodParameters; if (methodProvided) { methodParameters = method.GetParameters(); parameters = GetAllParameters(parameters, methodParameters); } else { methodParameters = null; } var hasSingleParameter = Count == 1; var singleParameterIsMultiLineLambda = false; var showParameterTypeNames = context.Settings.ShowLambdaParamTypes; var translationSize = 0; var formattingSize = 0; _parameterTranslations = parameters .Project((p, index) => { ITranslation translation; if (CanBeConvertedToMethodGroup(p, out var lambdaBodyMethodCall)) { translation = new MethodGroupTranslation( Lambda, lambdaBodyMethodCall.GetSubjectTranslation(context), lambdaBodyMethodCall.Method, context); goto CreateCodeBlock; } if (methodProvided) { var parameterIndex = index; if (Count != count) { // If a parameter is a params array then index will increase // past parameterCount, so adjust here: parameterIndex -= Count - count; } // ReSharper disable once PossibleNullReferenceException translation = GetParameterTranslation(p, methodParameters[parameterIndex], context); goto CreateCodeBlock; } translation = context.GetTranslationFor(p); if (showParameterTypeNames && (translation is IParameterTranslation parameterTranslation)) { parameterTranslation.WithTypeNames(context); WithParentheses(); } CreateCodeBlock: translationSize += translation.TranslationSize; formattingSize += translation.FormattingSize; // TODO: Only use code blocks where useful: var parameterCodeBlock = new CodeBlockTranslation(translation, context).WithoutTermination(); if (hasSingleParameter && parameterCodeBlock.IsMultiStatementLambda(context)) { singleParameterIsMultiLineLambda = true; parameterCodeBlock.WithSingleLamdaParameterFormatting(); } return(parameterCodeBlock); }) .ToArray(); _hasSingleMultiStatementLambdaParameter = singleParameterIsMultiLineLambda; TranslationSize = translationSize + (Count * ", ".Length) + 4; FormattingSize = formattingSize; }
internal WwwTranslationContext(ITranslationContext context) { _context = context; }
private MemberAccessTranslation(string memberName, ITranslationContext context) { _context = context; _memberName = memberName; }
public TypeofOperatorTranslation(Type type, ITranslationContext context) { _typeNameTranslation = context.GetTranslationFor(type); TranslationSize = _typeNameTranslation.TranslationSize + "typeof()".Length; FormattingSize = _typeNameTranslation.FormattingSize + context.GetKeywordFormattingSize(); }
public AnonymousTypeInitializerTranslationSet( IList <ITranslation> initializers, ITranslationContext context) : base(initializers, context) { }
public static CodeBlockTranslation GetCodeBlockTranslationFor( this ITranslationContext context, Expression expression) { return(new CodeBlockTranslation(context.GetTranslationFor(expression), context)); }
protected override ITranslatable GetTranslation( ITranslation initializer, ITranslationContext context) { return(initializer); }
public static int GetControlStatementFormattingSize(this ITranslationContext context) => context.GetFormattingSize(TokenType.ControlStatement);
internal HttpTranslationContext(ITranslationContext context) { _context = context; }
public static int GetFormattingSize(this ITranslationContext context, TokenType tokenType) => context.Settings.GetFormattingSize(tokenType);
private void ExtractTranslation(string data, List <UntranslatedTextInfo> untranslatedTextInfos, ITranslationContext context) { var obj = JsonConvert.DeserializeObject <TranslationResponse>(data); var translatedTexts = new List <string>(); int transIdx = 0; for (int i = 0; i < untranslatedTextInfos.Count; i++) { var parts = untranslatedTextInfos[i].TranslationParts; var fullTranslatedText = new StringBuilder(); foreach (var part in parts) { if (part.IsTranslatable) { var translation = obj.translations[transIdx++].text; fullTranslatedText.Append(translation); } else { fullTranslatedText.Append(part.Value); } } var t = fullTranslatedText.ToString(); if (string.IsNullOrWhiteSpace(t)) { throw new Exception("Found no valid translations in beam!"); } translatedTexts.Add(t); } context.Complete(translatedTexts.ToArray()); }
public static ITranslation GetSubjectTranslation(MethodCallExpression methodCall, ITranslationContext context) { return(context.GetTranslationFor(methodCall.GetSubject()) ?? context.GetTranslationFor(methodCall.Method.DeclaringType)); }
public ListInitializerSetTranslation(IList <ElementInit> initializers, ITranslationContext context) : base(initializers, context) { }