Giter Site home page Giter Site logo

Comments (4)

gregveres avatar gregveres commented on August 25, 2024

I solved this a different way.

My first solution was to dump out all of the Is* flags on type and realize that List<> has IsGeneric true and that I could get the type from the type.TypeArguments.

Then I realized that Type.Unwrap exists for this purpose. So now I am using that instead of needing to test against empty.

However, I have a different use case where I think I need to test against empty...

I have the interface being dumped out properly and all the necessary imports happening, but the last piece of the puzzle is when the class is derived from another class. I need to extract the type from the BaseClass, extract the base class's type and import that. My first inclination is to test the BaseClass against null, but then empty doesn't exist.

from ntypewriter.

gregveres avatar gregveres commented on August 25, 2024

I am going to close this. I discovered that I missed the "null" entry in Scriban that I can use instead of empty. And this works just fine.

For the example above, I was able to use Class.HasBaseClass to avoid testing against null. But I did run up against a case where I needed to use the Type.ArrayType value when Type.IsEnumerable was true. It turns out that IsEnumerable is true in lots of cases where ArrayType is null and can't be used. So checking against null worked well there.

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on August 25, 2024

Why simply not use IsArray property? "empty" will be available in version 0.0.8

from ntypewriter.

gregveres avatar gregveres commented on August 25, 2024

I don't recall the exact case, but I was dumping out all the Is* flags and I am pretty sure that IsArray was true for some other case where ArrayType was still null.

But no matter because "null" as a Scriban keyword is available. I had missed it in the Scriban docs the first few times I was looking through their languages page. I am successfully testing against "null" now.

from ntypewriter.

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.