30 lines
1.0 KiB
C#
30 lines
1.0 KiB
C#
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using Microsoft.CodeAnalysis.Text;
|
|
using Microsoft.VisualStudio.Text;
|
|
using Roslyn.Utilities;
|
|
|
|
namespace dnSpy.Roslyn.EditorFeatures.Extensions
|
|
{
|
|
internal static class TextSpanExtensions
|
|
{
|
|
/// <summary>
|
|
/// Convert a <see cref="TextSpan"/> instance to an <see cref="TextSpan"/>.
|
|
/// </summary>
|
|
public static Span ToSpan(this TextSpan textSpan)
|
|
{
|
|
return new Span(textSpan.Start, textSpan.Length);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert a <see cref="TextSpan"/> to a <see cref="SnapshotSpan"/> on the given <see cref="ITextSnapshot"/> instance
|
|
/// </summary>
|
|
public static SnapshotSpan ToSnapshotSpan(this TextSpan textSpan, ITextSnapshot snapshot)
|
|
{
|
|
Contract.Requires(snapshot != null);
|
|
var span = textSpan.ToSpan();
|
|
return new SnapshotSpan(snapshot, span);
|
|
}
|
|
}
|
|
}
|