Skip to content

Commit 1c0cc49

Browse files
author
Caitlin Bales (MSFT)
committed
Add logging for language-sanitized properties
1 parent bfaee2c commit 1c0cc49

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/GraphODataTemplateWriter/CodeHelpers/Android/TypeHelperAndroid.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.Android
66
using Microsoft.Graph.ODataTemplateWriter.Extensions;
77
using Vipr.Core.CodeModel;
88
using System;
9+
using NLog;
910

1011
public static class TypeHelperAndroid
1112
{
13+
private static Logger logger = LogManager.GetCurrentClassLogger();
1214
public const string ReservedPrefix = "msgraph_";
1315
public static HashSet<string> ReservedNames
1416
{
@@ -95,6 +97,7 @@ public static string SanitizePropertyName(this string property, OdcmObject odcmP
9597
{
9698
if (ReservedNames.Contains(property))
9799
{
100+
logger.Info("Property {0} is a reserved word in Android. Converting to {1}{0}", property, ReservedPrefix);
98101
return ReservedPrefix + property;
99102
}
100103

@@ -104,6 +107,7 @@ public static string SanitizePropertyName(this string property, OdcmObject odcmP
104107
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Name.ToUpperFirstChar())
105108
{
106109
// Name the property: {metadataName} + "Property"
110+
logger.Info("Property type {0} has the same name as the class. Converting to {0}Property", property);
107111
return string.Concat(property, "Property");
108112
}
109113

src/GraphODataTemplateWriter/CodeHelpers/CSharp/TypeHelperCSharp.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ namespace Microsoft.Graph.ODataTemplateWriter.CodeHelpers.CSharp
66
using System.Collections.Generic;
77
using Microsoft.Graph.ODataTemplateWriter.Extensions;
88
using Vipr.Core.CodeModel;
9+
using NLog;
910

1011
public static class TypeHelperCSharp
1112
{
13+
private static Logger logger = LogManager.GetCurrentClassLogger();
14+
1215
public const string DefaultReservedPrefix = "@";
1316
public static ICollection<string> GetReservedNames()
1417
{
@@ -235,6 +238,7 @@ public static string GetSanitizedPropertyName(this string property, OdcmProperty
235238
{
236239
var reservedPrefix = string.IsNullOrEmpty(prefix) ? DefaultReservedPrefix : prefix;
237240

241+
logger.Info("Property {0} is a reserved word in .NET. Converting to {1}{0}", property.ToUpperFirstChar(), reservedPrefix);
238242
return string.Concat(reservedPrefix, property.ToUpperFirstChar());
239243
}
240244

@@ -247,6 +251,7 @@ public static string GetSanitizedPropertyName(this string property, OdcmProperty
247251
if (odcmProperty.Projection.Type.Name.ToUpperFirstChar() == odcmProperty.Class.Name.ToUpperFirstChar())
248252
{
249253
// Name the property: {metadataName} + "Property"
254+
logger.Info("Property type {0} has the same name as the class. Converting to {0}Property", property);
250255
return string.Concat(property, "Property");
251256
}
252257

src/GraphODataTemplateWriter/Extensions/OdcmModelExtensions.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ namespace Microsoft.Graph.ODataTemplateWriter.Extensions
77
using System.Linq;
88
using Microsoft.Graph.ODataTemplateWriter.Settings;
99
using Vipr.Core.CodeModel;
10+
using NLog;
1011

1112
public static class OdcmModelExtensions
1213
{
14+
private static Logger logger = LogManager.GetCurrentClassLogger();
15+
1316
public static bool IsCollection(this OdcmProperty odcmProperty)
1417
{
1518
return odcmProperty.IsCollection;
@@ -152,8 +155,8 @@ public static OdcmProperty GetServiceCollectionNavigationPropertyForPropertyType
152155
.First();
153156
} catch (Exception e)
154157
{
155-
//TODO: Pass the exception to the logger
156-
Console.WriteLine("Error: The navigation property \"{0}\" on class \"{1}\" does not specify it is self-contained nor is it defined in an EntitySet", odcmProperty.Name.ToString(), odcmProperty.Class.FullName.ToString());
158+
logger.Error("The navigation property \"{0}\" on class \"{1}\" does not specify it is self-contained nor is it defined in an EntitySet", odcmProperty.Name.ToString(), odcmProperty.Class.FullName.ToString());
159+
logger.Error(e);
157160
return null;
158161
}
159162
}

0 commit comments

Comments
 (0)