GithubHelp home page GithubHelp logo

Comments (2)

habbes avatar habbes commented on July 30, 2024 2

@budt12 Since some concerns have been raised about the currently open PR, and discussions are ongoing, I want to suggest a workaround in the meantime. The workaround consists of providing a custom type resolver delegate to the ODataMessageWriterSettings.ClientCustomTypeResolver property. The custom resolver can then implement custom logic to handle types that are not found in your model using the default (case-sensitive) IEdmModel.FindType extension method.

Here's a sample implementation of such a custom resolver. It builds a static case-insensitive copy of the core schema types in the EdmCoreModel. When a type is not found, it looks it up in this cache. Building the cache is a one-time cost. I opted to copy only the core model types in order to keep the cache small and because your use-case seems to be concerned only with EDM primitve types.

private static Dictionary<string, IEdmType> caseInsensitiveCoreTypesCache = BuildCaseInsensitiveCoreTypesCache();

public static IEdmType ResolveType(IEdmType expectedType, string typeName)
{
      IEdmType resolvedType = MyModel.FindType(typeName);
      if (resolvedType == null)
      {
            var qualifiedTypeName = typeName.Contains(".") ? typeName : $"Edm.{typeName}";
            caseInsensitiveCoreTypeCache.TryGetValue(qualifiedTypeName, out resolvedType);
      }

      return resolvedType;
}

private static Dictionary<string, IEdmType> BuildCaseInsensitiveCoreTypesCache()
{
    var cache = new Dictionary<string, IEdmType>(StringComparer.OrdinalIgnoreCase);
    foreach (var type in EdmCoreModel.Instance.SchemaElements)
    {
        cache.Add(type.FullName(), type as IEdmType);
    }

    return cache;
}

And here's how you would pass it to the reader settings:

messageReaderSettings.ClientCustomTypeResolver = ResolveType

from odata.net.

corranrogue9 avatar corranrogue9 commented on July 30, 2024

Let's see if we can parameterize the comparer and run benchmarks at a later time. We will need to benchmark if we can't parameterize the comparer for some reason.

from odata.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.