예제 #1
0
        public void DotvvmCompilationException_SerializationAndDeserialization_WorksCorrectly()
        {
            var compilationException =
                new DotvvmCompilationException("Compilation error", new Exception("inner exception"));

            var serializedObject = JsonConvert.SerializeObject(compilationException);

            var deserializedObject = JsonConvert.DeserializeObject <DotvvmCompilationException>(serializedObject);
        }
예제 #2
0
        public void DotvvmCompilationException_SerializationAndDeserialization_WorksCorrectly()
        {
            var compilationException =
                new DotvvmCompilationException("Compilation error", new Exception("inner exception"));

            var settings         = DefaultSerializerSettingsProvider.Instance.Settings;
            var serializedObject = JsonConvert.SerializeObject(compilationException, settings);

            var deserializedObject = JsonConvert.DeserializeObject <DotvvmCompilationException>(serializedObject, settings);
        }
예제 #3
0
        protected override IAbstractBinding CompileBinding(DothtmlBindingNode node, BindingParserOptions bindingOptions, IDataContextStack context)
        {
            Expression      expression   = null;
            Exception       parsingError = null;
            ITypeDescriptor resultType   = null;

            if (context == null)
            {
                parsingError = new DotvvmCompilationException("The DataContext couldn't be evaluated because of the errors above.", node.Tokens);
            }
            else
            {
                try
                {
                    expression = bindingExpressionBuilder.Parse(node.Value, (DataContextStack)context, bindingOptions);
                    resultType = new ResolvedTypeDescriptor(expression.Type);
                }
                catch (Exception exception)
                {
                    parsingError = exception;
                }
            }
            return(treeBuilder.BuildBinding(bindingOptions, context, node, resultType, parsingError, expression));
        }
예제 #4
0
 private SourceModel ExtractSourceFromDotvvmCompilationException(DotvvmCompilationException compilationException)
 {
     if (compilationException.Tokens != null && compilationException.Tokens.Any())
     {
         var errorColumn = compilationException.Tokens.FirstOrDefault()?.ColumnNumber ?? 0;
         var errorLength = compilationException.Tokens.Where(t => t.LineNumber == compilationException.LineNumber).Sum(t => t.Length);
         if (compilationException.FileName != null)
         {
             return(ErrorFormatter.LoadSourcePiece(compilationException.FileName, compilationException.LineNumber ?? 0,
                                                   errorColumn: errorColumn,
                                                   errorLength: errorLength));
         }
         else
         {
             var line = string.Concat(compilationException.Tokens.Select(s => s.Text));
             return(CreateAnonymousLine(line, lineNumber: compilationException.Tokens.FirstOrDefault()?.LineNumber ?? 0));
         }
     }
     else if (compilationException.FileName != null)
     {
         return(ErrorFormatter.LoadSourcePiece(compilationException.FileName, compilationException.LineNumber ?? 0, errorColumn: compilationException.ColumnNumber ?? 0, errorLength: compilationException.ColumnNumber != null ? 1 : 0));
     }
     return(null);
 }
예제 #5
0
        protected override IAbstractBinding CompileBinding(DothtmlBindingNode node, BindingParserOptions bindingOptions, IDataContextStack context)
        {
            Expression expression = null;
            Exception parsingError = null;
            ITypeDescriptor resultType = null;

            if (context == null)
            {
                parsingError = new DotvvmCompilationException("The DataContext couldn't be evaluated because of the errors above.", node.Tokens);
            }
            else
            {
                try
                {
                    expression = bindingExpressionBuilder.Parse(node.Value, (DataContextStack)context, bindingOptions);
                    resultType = new ResolvedTypeDescriptor(expression.Type);
                }
                catch (Exception exception)
                {
                    parsingError = exception;
                }
            }
            return treeBuilder.BuildBinding(bindingOptions, node, context, parsingError, resultType, expression);
        }