当前位置: 首页>>代码示例>>C#>>正文


C# SourceUnit.GetReader方法代码示例

本文整理汇总了C#中SourceUnit.GetReader方法的典型用法代码示例。如果您正苦于以下问题:C# SourceUnit.GetReader方法的具体用法?C# SourceUnit.GetReader怎么用?C# SourceUnit.GetReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SourceUnit的用法示例。


在下文中一共展示了SourceUnit.GetReader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Add

        public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity) {
            if (severity == Severity.Warning && !ReportWarning(_context.Verbose, errorCode)) {
                return;
            }

            CountError(severity);

            string path;
            string codeLine;
            RubyEncoding encoding;
            int line = span.Start.Line;
            if (sourceUnit != null) {
                path = sourceUnit.Path;
                using (SourceCodeReader reader = sourceUnit.GetReader()) {
                    if (line > 0) {
                        reader.SeekLine(line);
                        codeLine = reader.ReadLine();
                    } else {
                        codeLine = null;
                    }
                    encoding = RubyEncoding.GetRubyEncoding(reader.Encoding);
                }
            } else {
                path = null;
                codeLine = null;
                encoding = RubyEncoding.UTF8;
            }

            if (severity == Severity.Error || severity == Severity.FatalError) {
                throw new SyntaxError(message, path, line, span.Start.Column, codeLine);
            } else {

                if (_WriteSite == null) {
                    Interlocked.CompareExchange(
                        ref _WriteSite,
                        CallSite<Func<CallSite, object, object, object>>.Create(RubyCallAction.Make(_context, "write", 1)),
                        null
                    );
                }

                message = RubyContext.FormatErrorMessage(message, "warning", path, line, span.Start.Column, null);

                _WriteSite.Target(_WriteSite, _context.StandardErrorOutput, MutableString.Create(message, encoding));
            }
        }
开发者ID:bclubb,项目名称:ironruby,代码行数:45,代码来源:RuntimeErrorSink.cs

示例2: Add

        public override void Add(SourceUnit sourceUnit, string message, SourceSpan span, int errorCode, Severity severity)
        {
            if (severity == Severity.Warning && !ReportWarning(_context.Verbose, errorCode)) {
                return;
            }

            CountError(severity);

            string path;
            string codeLine;
            RubyEncoding encoding;
            int line = span.Start.Line;
            if (sourceUnit != null) {
                path = sourceUnit.Path;
                using (SourceCodeReader reader = sourceUnit.GetReader()) {
                    if (line > 0) {
                        try {
                            reader.SeekLine(line);
                            codeLine = reader.ReadLine();
                        } catch (Exception) {
                            codeLine = null;
                        }
                    } else {
                        codeLine = null;
                    }
                    encoding = reader.Encoding != null ? RubyEncoding.GetRubyEncoding(reader.Encoding) : RubyEncoding.UTF8;
                }
            } else {
                path = null;
                codeLine = null;
                encoding = RubyEncoding.UTF8;
            }

            if (severity == Severity.Error || severity == Severity.FatalError) {
                throw new SyntaxError(message, path, line, span.Start.Column, codeLine);
            } else {
                WriteMessage(
                    MutableString.Create(RubyContext.FormatErrorMessage(message, "warning", path, line, span.Start.Column, null), encoding)
                );
            }
        }
开发者ID:TerabyteX,项目名称:main,代码行数:41,代码来源:RuntimeErrorSink.cs

示例3: Initialize

 public void Initialize(SourceUnit/*!*/ sourceUnit) {
     ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");
     Initialize(null, sourceUnit.GetReader(), sourceUnit, SourceLocation.MinValue);
 }
开发者ID:bclubb,项目名称:ironruby,代码行数:4,代码来源:Tokenizer.cs

示例4: AddScriptLines

        /// <summary>
        /// If the SCRIPT_LINES__ constant is set, we need to publish the file being loaded,
        /// along with the contents of the file
        /// </summary>
        private void AddScriptLines(SourceUnit file) {            
            ConstantStorage storage;
            if (!_context.ObjectClass.TryResolveConstant(null, "SCRIPT_LINES__", out storage)) {
                return;
            }

            IDictionary scriptLines = storage.Value as IDictionary;
            if (scriptLines == null) {
                return;
            }

            lock (scriptLines) {
                // Read in the contents of the file

                RubyArray lines = new RubyArray();
                SourceCodeReader reader = file.GetReader();
                RubyEncoding encoding = RubyEncoding.GetRubyEncoding(reader.Encoding);
                using (reader) {
                    reader.SeekLine(1);
                    while (true) {
                        string lineStr = reader.ReadLine();
                        if (lineStr == null) {
                            break;
                        }
                        MutableString line = MutableString.CreateMutable(lineStr.Length + 1, encoding);
                        line.Append(lineStr).Append('\n');
                        lines.Add(line);
                    }
                }

                // Publish the contents of the file, keyed by the file name
                MutableString path = MutableString.Create(file.Document.FileName, _context.GetPathEncoding());
                scriptLines[path] = lines;
            }
        }
开发者ID:kevinkeeney,项目名称:ironruby,代码行数:39,代码来源:Loader.cs

示例5: GetSourceCode

        private string GetSourceCode(SourceUnit source, SourceSpan span)
        {
            if (!span.IsValid)
                return "invalid location";

            char[] buffer = new char[span.Length];

            using (var reader = source.GetReader())
            {
                reader.Read(buffer, span.Start.Index, buffer.Length);
                return new string(buffer);
            }
        }
开发者ID:fgretief,项目名称:IronLua,代码行数:13,代码来源:LuaRuntimeException.cs

示例6: Initialize

        public void Initialize(SourceUnit sourceUnit) {
            ContractUtils.RequiresNotNull(sourceUnit, "sourceUnit");

            Initialize(null, sourceUnit.GetReader(), sourceUnit, SourceLocation.MinValue, DefaultBufferCapacity);
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:5,代码来源:Tokenizer.cs

示例7: InputReader

 public InputReader(SourceUnit sourceUnit)
 {
     _sourceUnit = sourceUnit;
     _reader = sourceUnit.GetReader();
 }
开发者ID:dlurton,项目名称:Happy,代码行数:5,代码来源:InputReader.cs


注:本文中的SourceUnit.GetReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。