diff --git a/src/Core/Vipr.Core/CodeModel/OdcmModel.cs b/src/Core/Vipr.Core/CodeModel/OdcmModel.cs index 25d19306..fef60fc4 100644 --- a/src/Core/Vipr.Core/CodeModel/OdcmModel.cs +++ b/src/Core/Vipr.Core/CodeModel/OdcmModel.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Collections.Generic; using System.Linq; @@ -54,15 +55,17 @@ public void AddType(OdcmType type) } _Types.Add(type); - ; + odcmNamespace.Types.Add(type); } public bool TryResolveType(string name, string @namespace, out T type) where T : OdcmType { + string canonicalName = OdcmObject.MakeCanonicalName(name, @namespace); + foreach (OdcmType candidate in _Types) { - if (string.Equals(candidate.Name, name) && string.Equals(candidate.Namespace, @namespace)) + if (candidate.CanonicalName().Equals(canonicalName, StringComparison.InvariantCulture)) { type = candidate as T; return true; diff --git a/src/Core/Vipr.Core/CodeModel/OdcmObject.cs b/src/Core/Vipr.Core/CodeModel/OdcmObject.cs index 7530dc7c..d391761a 100644 --- a/src/Core/Vipr.Core/CodeModel/OdcmObject.cs +++ b/src/Core/Vipr.Core/CodeModel/OdcmObject.cs @@ -21,7 +21,7 @@ public virtual string CanonicalName() public static string MakeCanonicalName(string name, string @namespace) { - return string.Format("{0}.{1}", name, @namespace); + return string.Format("{1}.{0}", name, @namespace); } public static string MakeCanonicalName(string name, string @namespace, params OdcmType[] parameters) diff --git a/src/Core/Vipr.Core/CodeModel/OdcmType.cs b/src/Core/Vipr.Core/CodeModel/OdcmType.cs index ebaad058..d9fe89a8 100644 --- a/src/Core/Vipr.Core/CodeModel/OdcmType.cs +++ b/src/Core/Vipr.Core/CodeModel/OdcmType.cs @@ -22,7 +22,7 @@ public string FullName public override string CanonicalName() { - return string.Format("{0}.{1}", Namespace, base.CanonicalName()); + return MakeCanonicalName(base.CanonicalName(), Namespace); } } } diff --git a/src/Writers/CSharpWriter/Attribute.cs b/src/Writers/CSharpWriter/Attribute.cs index f1465478..f8a2f8ec 100644 --- a/src/Writers/CSharpWriter/Attribute.cs +++ b/src/Writers/CSharpWriter/Attribute.cs @@ -27,12 +27,12 @@ public static Attribute ForLowerCaseProperty() }; } - public static Attribute ForMicrosoftOdataClientKey(OdcmClass odcmClass) + public static Attribute ForMicrosoftOdataClientKey(OdcmEntityClass odcmClass) { return new Attribute { Type = new Type(new Identifier("global::Microsoft.OData.Client", "Key")), - Parameters = ((OdcmEntityClass)odcmClass).Key.ToDictionary(p => p.Name, p => null) + Parameters = odcmClass.Key.ToDictionary(p => p.Name, p => null) }; } diff --git a/src/Writers/CSharpWriter/Attributes.cs b/src/Writers/CSharpWriter/Attributes.cs index 9cb973a7..c56cf469 100644 --- a/src/Writers/CSharpWriter/Attributes.cs +++ b/src/Writers/CSharpWriter/Attributes.cs @@ -8,7 +8,7 @@ namespace CSharpWriter { public class Attributes { - public static IEnumerable ForConcrete(OdcmClass odcmClass) + public static IEnumerable ForConcrete(OdcmEntityClass odcmClass) { return new[] { diff --git a/src/Writers/CSharpWriter/Class.cs b/src/Writers/CSharpWriter/Class.cs index a2e4679d..6c951d6a 100644 --- a/src/Writers/CSharpWriter/Class.cs +++ b/src/Writers/CSharpWriter/Class.cs @@ -67,7 +67,7 @@ public static Class ForComplex(OdcmClass odcmClass) }; } - public static Class ForConcrete(OdcmClass odcmClass) + public static Class ForConcrete(OdcmEntityClass odcmClass) { return new Class { @@ -87,7 +87,7 @@ public static Class ForConcrete(OdcmClass odcmClass) }; } - public static Class ForCollection(OdcmClass odcmClass) + public static Class ForCollection(OdcmEntityClass odcmClass) { return new Class { diff --git a/src/Writers/CSharpWriter/CollectionGetByIdIndexer.cs b/src/Writers/CSharpWriter/CollectionGetByIdIndexer.cs index 0fc12c3d..ef888940 100644 --- a/src/Writers/CSharpWriter/CollectionGetByIdIndexer.cs +++ b/src/Writers/CSharpWriter/CollectionGetByIdIndexer.cs @@ -12,9 +12,9 @@ public class CollectionGetByIdIndexer : Indexer { public Dictionary ParameterToPropertyMap { get; private set; } - public CollectionGetByIdIndexer(OdcmClass odcmClass) + public CollectionGetByIdIndexer(OdcmEntityClass odcmClass) { - var keyProperties = ((OdcmEntityClass)odcmClass).Key; + var keyProperties = odcmClass.Key; ParameterToPropertyMap = keyProperties.ToDictionary(Parameter.FromProperty, p => p); diff --git a/src/Writers/CSharpWriter/Features.cs b/src/Writers/CSharpWriter/Features.cs index 768455d0..90934499 100644 --- a/src/Writers/CSharpWriter/Features.cs +++ b/src/Writers/CSharpWriter/Features.cs @@ -33,7 +33,7 @@ public static IEnumerable ForOdcmClass(OdcmClass odcmClass) case OdcmClassKind.MediaEntity: case OdcmClassKind.Entity: - return Features.ForOdcmClassEntity(odcmClass); + return Features.ForOdcmClassEntity((OdcmEntityClass)odcmClass); case OdcmClassKind.Service: return Enumerable.Empty(); @@ -70,7 +70,7 @@ private static IEnumerable ForOdcmClassService(OdcmClass odcmClass, Odc }; } - private static IEnumerable ForOdcmClassEntity(OdcmClass odcmClass) + private static IEnumerable ForOdcmClassEntity(OdcmEntityClass odcmClass) { return new[] { diff --git a/src/Writers/CSharpWriter/IndexerSignature.cs b/src/Writers/CSharpWriter/IndexerSignature.cs index 745499ee..9243dd9c 100644 --- a/src/Writers/CSharpWriter/IndexerSignature.cs +++ b/src/Writers/CSharpWriter/IndexerSignature.cs @@ -12,7 +12,7 @@ public abstract class IndexerSignature : ParameterizedFunction public bool IsSettable { get; protected set; } public bool IsGettable { get; protected set; } - public static IEnumerable ForCollectionInterface(OdcmClass odcmClass) + public static IEnumerable ForCollectionInterface(OdcmEntityClass odcmClass) { return new IndexerSignature[] { diff --git a/src/Writers/CSharpWriter/Indexers.cs b/src/Writers/CSharpWriter/Indexers.cs index 993d1f14..1c57151a 100644 --- a/src/Writers/CSharpWriter/Indexers.cs +++ b/src/Writers/CSharpWriter/Indexers.cs @@ -8,7 +8,7 @@ namespace CSharpWriter { public class Indexers { - public static IEnumerable ForCollection(OdcmClass odcmClass) + public static IEnumerable ForCollection(OdcmEntityClass odcmClass) { return new Indexer[] { diff --git a/src/Writers/CSharpWriter/Interface.cs b/src/Writers/CSharpWriter/Interface.cs index 126f6191..7aded909 100644 --- a/src/Writers/CSharpWriter/Interface.cs +++ b/src/Writers/CSharpWriter/Interface.cs @@ -55,7 +55,7 @@ public static Interface ForFetcher(OdcmClass odcmClass) }; } - public static Interface ForCollection(OdcmClass odcmClass) + public static Interface ForCollection(OdcmEntityClass odcmClass) { return new Interface { diff --git a/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Collection_Interface.cs b/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Collection_Interface.cs index 21bfa1ab..46e3a96c 100644 --- a/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Collection_Interface.cs +++ b/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Collection_Interface.cs @@ -93,7 +93,7 @@ public void It_exposes_an_AddAsync_method() private Type[] GetKeyPropertyTypes() { - return ((OdcmEntityClass)Class).Key + return Class.Key .Select(p => p.Type) .Select(t => Proxy.GetClass(t.Namespace, t.Name)) .ToArray(); diff --git a/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Concrete_Class.cs b/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Concrete_Class.cs index 6b1fa6a7..c79d6047 100644 --- a/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Concrete_Class.cs +++ b/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Concrete_Class.cs @@ -64,7 +64,7 @@ public void The_Concrete_class_is_attributed_with_MicrosoftOdataClientKey_Attrib private IEnumerable EntityKeyNames { - get { return ((OdcmEntityClass)Class).Key.Select(p => p.Name); } + get { return Class.Key.Select(p => p.Name); } } [Fact] diff --git a/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Derived.cs b/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Derived.cs index 2ca6a9ea..9f91974e 100644 --- a/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Derived.cs +++ b/test/CSharpWriterUnitTests/Given_an_OdcmClass_Entity_Derived.cs @@ -136,7 +136,7 @@ public void The_Base_Concrete_explicitly_implements_a_ToDerived_method() private IEnumerable GetKeyTypes() { - return ((OdcmEntityClass)Class).Key + return Class.Key .Select(p => p.Type) .Select(t => Proxy.GetClass(t.Namespace, t.Name)); }