forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpDirectCompilerService.cs
More file actions
40 lines (37 loc) · 1.43 KB
/
Copy pathCSharpDirectCompilerService.cs
File metadata and controls
40 lines (37 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Linq;
using System.Web.Razor.Parser;
using Microsoft.CSharp;
namespace ServiceStack.Razor.Compilation.CSharp
{
/// <summary>
/// Defines a direct compiler service for the C# syntax.
/// </summary>
public class CSharpDirectCompilerService : CompilerServiceBase
{
public CSharpDirectCompilerService(bool strictMode = true, MarkupParser markupParser = null)
: base(
new CSharpCodeProvider(),
new CSharpRazorCodeLanguage(strictMode),
markupParser) { }
/// <summary>
/// Builds a type name for the specified generic type.
/// </summary>
/// <param name="type">The type.</param>
/// <param name="isDynamic">Specifies whether the type is dynamic.</param>
/// <returns>
/// The string typename (including namespace and generic type parameters).
/// </returns>
public override string BuildTypeNameInternal(Type type, bool isDynamic)
{
if (!type.IsGenericType)
return type.FullName;
return type.Namespace
+ "."
+ type.Name.Substring(0, type.Name.IndexOf('`'))
+ "<"
+ (isDynamic ? "dynamic" : string.Join(", ", type.GetGenericArguments().Select(t => BuildTypeNameInternal(t, CompilerServices.IsDynamicType(t)))))
+ ">";
}
}
}