From 14fdec36f0836ebd034b539c3ab442b8e093a345 Mon Sep 17 00:00:00 2001 From: Lewis Cheng Date: Wed, 28 Oct 2015 20:12:35 -0700 Subject: [PATCH] Fix FxCop warnings under Release --- .../Model/ModelProducer.cs | 18 +++++++++++++----- .../Routing/RestierRoutingConvention.cs | 13 +++++++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs b/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs index a8abb32c..26838090 100644 --- a/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs +++ b/src/Microsoft.Restier.EntityFramework/Model/ModelProducer.cs @@ -71,10 +71,7 @@ private static IDictionary { PrimitiveTypeKind.Time, EdmPrimitiveTypeKind.Duration } }; - static ModelProducer() - { - Instance = new ModelProducer(); - } + private static IModelBuilder instance; private ModelProducer() { @@ -83,7 +80,18 @@ private ModelProducer() /// /// Gets the single instance of this model producer. /// - public static ModelProducer Instance { get; private set; } + public static IModelBuilder Instance + { + get + { + if (instance == null) + { + instance = new ModelProducer(); + } + + return instance; + } + } /// public Task GetModelAsync(InvocationContext context, CancellationToken cancellationToken) diff --git a/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs b/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs index 8d28c8b3..cf4cb567 100644 --- a/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs +++ b/src/Microsoft.Restier.WebApi/Routing/RestierRoutingConvention.cs @@ -115,13 +115,18 @@ private static bool HasControllerForEntitySetOrSingleton( ODataPathSegment firstSegment = odataPath.Segments.FirstOrDefault(); if (firstSegment != null) { - if (firstSegment is EntitySetPathSegment) + var entitySetSegment = firstSegment as EntitySetPathSegment; + if (entitySetSegment != null) { - controllerName = (firstSegment as EntitySetPathSegment).EntitySetName; + controllerName = entitySetSegment.EntitySetName; } - else if (firstSegment is SingletonPathSegment) + else { - controllerName = (firstSegment as SingletonPathSegment).SingletonName; + var singletonSegment = firstSegment as SingletonPathSegment; + if (singletonSegment != null) + { + controllerName = singletonSegment.SingletonName; + } } }