This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPropertyHelper.cs
More file actions
89 lines (82 loc) · 3.03 KB
/
PropertyHelper.cs
File metadata and controls
89 lines (82 loc) · 3.03 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
namespace NuGet.Insights
{
public static class PropertyHelper
{
public static string GetPrettyType(string classNamespacePrefix, ISet<string> propertyNames, IPropertySymbol symbol)
{
var propType = symbol.Type.ToString();
var nonNullPropType = propType.TrimEnd('?');
var prettyPropType = nonNullPropType;
// Clean up the type name by removing unnecessary namespaces.
const string systemPrefix = "System.";
if (prettyPropType.StartsWith(systemPrefix, StringComparison.Ordinal) && prettyPropType.IndexOf('.', systemPrefix.Length) < 0)
{
prettyPropType = prettyPropType.Substring(systemPrefix.Length);
}
else if (prettyPropType.StartsWith(classNamespacePrefix, StringComparison.Ordinal))
{
prettyPropType = prettyPropType.Substring(classNamespacePrefix.Length);
}
// To avoid property name collisions, only use the pretty version if it doesn't match a property name.
if (propertyNames.Contains(prettyPropType))
{
prettyPropType = nonNullPropType;
}
return prettyPropType;
}
public static string GetKustoDataType(CsvPropertyModel property)
{
if (property.KustoType != null)
{
return property.KustoType;
}
switch (property.Type)
{
case "bool":
case "bool?":
return "bool";
case "ushort":
case "ushort?":
case "short":
case "short?":
case "int":
case "int?":
return "int";
case "float":
case "float?":
case "double":
case "double?":
return "real";
case "uint":
case "uint?":
case "long":
case "long?":
return "long";
case "System.Guid":
case "System.Guid?":
return "guid";
case "System.TimeSpan":
case "System.TimeSpan?":
return "timespan";
case "System.DateTimeOffset":
case "System.DateTimeOffset?":
return "datetime";
case "System.Version":
case "string":
return "string";
default:
if (property.IsEnum || property.IsNullableEnum)
{
return "string";
}
else
{
return "dynamic";
}
}
}
}
}