Code Monkey home page Code Monkey logo

Comments (6)

gregveres avatar gregveres commented on June 25, 2024

Given the above, this is the output from a Debug.WriteLine type placed just inside the ImportType scriban function.

12:24:32.392 INFO: 4Sc4Hl5 Task<IHttpActionResult> AnnouncementsController.GetAllAnnouncements(int orgId)
12:24:32.392 INFO: 4Sc4Hl5 in ImportType for
12:24:32.392 INFO: 4Sc4Hl5 
12:24:32.392 INFO: 4Sc4Hl5 in ImportType for
12:24:32.392 INFO: 4Sc4Hl5 int

The first line of this output is from a Debug.WriteLine method that is placed just inside the for loop.

from ntypewriter.

gregveres avatar gregveres commented on June 25, 2024

I am pretty sure I have figured it out.
In the ReturnType function, you have the same issue that I had when you introduced the TypedConstant for the attribute arguments.

This line needs to be updated to take the TypedConstant into consideration.

from ntypewriter.

gregveres avatar gregveres commented on June 25, 2024

I thought I could make a copy of the ReturnType in my custom functions and then fix it there, but it is not as straight forward as expected. I have changed Action.ReturnType to Custom.ReturnType to call my function, but I am running into a type mismatch I think.

Here is the code I am trying:

        public static IType ReturnType(IMethod method)
        {
            var result = method.ReturnType;

            var responseTypeAttribute = method.Attributes.FirstOrDefault(a => a.Name == "ResponseType" || a.Name == "ProducesResponseType");
            var responseTypeArgument = responseTypeAttribute?.Arguments.FirstOrDefault(x => x.Name == "responseType" || x.Name == "Type");
            if (responseTypeArgument?.Value is ITypedConstant type) return type.Value as IType;

            while (result != null && (result.BareName == "Task" || result.BareName == "ActionResult"))
            {
                if (result.IsGeneric)
                {
                    result = result.TypeArguments.FirstOrDefault();
                }
                else
                {
                    result = null;
                }
            }
            return result;
        }

The issue I am running into is that the TypedConstant.Value isn't an IType so the "as IType" that used to be there still fails. The Value field is of the type:
`` Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.NonErrorNamedTypeSymbol```
casting this type to an IType causes the return value to be null.

from ntypewriter.

gregveres avatar gregveres commented on June 25, 2024

I have run out of ideas on how to extract the IType from responseTypeArgument.Value.Value. I have to roll back until there is a fix for this, unfortunately.

from ntypewriter.

gregveres avatar gregveres commented on June 25, 2024

Ugg, there doesn't seem to be a way to roll back.

from ntypewriter.

NeVeSpl avatar NeVeSpl commented on June 25, 2024

That is too many breaking changes, previous behaviour will return in 0.4.4.2, ITypedConstant will be only used for enums.

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.