예제 #1
0
        private MappingInfo GetMappingInfo()
        {
            var mappingInfo = new MappingInfo();

            try
            {
                var descriptor = new SparkViewDescriptor()
                                 .AddTemplate(_path);

                var entry = _engine.CreateEntryInternal(descriptor, false);

                mappingInfo.GeneratedCode = entry.SourceCode;

                mappingInfo.Mapping = entry.SourceMappings
                                      .Where(m => string.Equals(m.Source.Begin.SourceContext.FileName, _path,
                                                                StringComparison.InvariantCultureIgnoreCase))
                                      .Select(m => new _SOURCEMAPPING
                {
                    start1 = m.Source.Begin.Offset,
                    end1   = m.Source.End.Offset,
                    start2 = m.OutputBegin,
                    end2   = m.OutputEnd
                })
                                      .ToArray();

                mappingInfo.Count = mappingInfo.Mapping.Length;
            }
            catch (Exception ex)
            {
                mappingInfo.GenerationError = ex;
            }

            if (mappingInfo.Count == 0)
            {
                mappingInfo.Mapping = new _SOURCEMAPPING[1];
            }
            return(mappingInfo);
        }