Giter Club home page Giter Club logo

Comments (4)

picrap avatar picrap commented on May 30, 2024

Getter and setter have a [CompilerGeneratedAttribute]. The only thing to do is to find the attribute, then analyze the body code to find the backing field, then remove backing field and do not emit any method.
The advice marker could be a special priority level (such as -1?)

from mradvice.

picrap avatar picrap commented on May 30, 2024
Getter

Generated code with Roslyn:

IL_0000: ldarg.0
IL_0001: ldfld bool MethodLevelTest.AdvisedClass::'<UnadvisedAutoProperty>k__BackingField'
IL_0006: ret

With legacy C# compiler:

IL_0000: ldarg.0
IL_0001: ldfld bool MethodLevelTest.AdvisedClass::'<UnadvisedAutoProperty>k__BackingField'
IL_0006: stloc.0
IL_0007: br.s IL_0009
IL_0009: ldloc.0
IL_000a: ret
Setter

Same thing for both compilers:

IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: stfld bool MethodLevelTest.AdvisedClass::'<UnadvisedAutoProperty>k__BackingField'
IL_0007: ret

from mradvice.

picrap avatar picrap commented on May 30, 2024

It's probably better to use another marker than [Priority], which is not explicit enough. Something like [AbstractTarget] which means the original body and references can be removed (this may also work for methods).

from mradvice.

picrap avatar picrap commented on May 30, 2024

Done (v0.10). However, with C#6 property initializers, there is an incompatibility: since backing storage is removed, initialization from ctor() is then ignored.

from mradvice.

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.