Giter Club home page Giter Club logo

privateproxy's People

Contributors

aarnott avatar guitarrapc avatar hadashia avatar neuecc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

privateproxy's Issues

Tasks

  • impl for field
    • readonly
  • impl for property
    • get only
    • set only
  • impl for method
  • AsPrivateProxy extension method
    - [ ] reflection fallback
  • unit tests
    • check for flags
    • check for diagnostics
  • ReadMe

Generics , static class and ref field support

I managed to reproduce something similar to this library in the Unity environment and managed to apply it to generics and static classes as well.
https://github.com/Akeit0/ILAttributes
I believe ref fields can also be applied by wrapping a ref into a ref struct.
However, since this is using IL Weaving, this is not as simple as it sounds.
Do you intend to introduce this or wait for formal support?

Support constructors

Pretty much the title. It would be nice to have support for constructors. However, this may not fit the current extension method approach... but extern method could be exposed directly.

using PrivateProxy;

public class Sample
{
    private Sample(int x) {}
}

[GeneratePrivateProxy(typeof(Sample))]
partial struct SampleProxy;

// Generated
partial struct SampleProxy(Sample target)
{
    [UnsafeAccessor(UnsafeAccessorKind.Constructor)]
    public static extern Sample CreateSample(int x);
}

BTW thank you for this nice source generator!

[Bug] Parameter public check

In this part, parameters public checks do nothing. (foreach continue)

 else if (generateMethod && item is IMethodSymbol m)
  {
      // both return type and parameter type must be public
      if (m.ReturnType.DeclaredAccessibility != Accessibility.Public) continue;
      foreach (var parameter in m.Parameters)
      {
          if (parameter.Type.DeclaredAccessibility != Accessibility.Public) continue; 
      }

      if (m.DeclaredAccessibility == Accessibility.Public) continue;
      list.Add(new(item));
  }

And only checking Accessibility.Public doesn't care about element types.
Following is what I'm using in my library.

static bool CanExpose(ITypeSymbol typeSymbol)
{
    if (typeSymbol is IPointerTypeSymbol) return false;
    while(typeSymbol is IArrayTypeSymbol arrayType)
    {
        typeSymbol = arrayType.ElementType;
        if (typeSymbol is IPointerTypeSymbol) return false;
    }
    if(typeSymbol is INamedTypeSymbol namedTypeSymbol)
    {
        if (namedTypeSymbol.IsGenericType)
        {
            foreach (var e in namedTypeSymbol.TypeArguments)
            {
                if (!CanExpose(e)) return false;
            }
        }
           
    }
    var declaredAccessibility = typeSymbol.DeclaredAccessibility;
    switch (declaredAccessibility)
    {
        case Accessibility.Public:
            return true;
        case Accessibility.NotApplicable:
            return true;
        default:
            return false;
    }
}

Cannot generate usable proxy for JsonElement

When trying to generate a private proxy for System.Text.Json.JsonElement,

[GeneratePrivateProxy(typeof(JsonElement))]
public ref partial struct JsonElementProxy;

it seems to generate a dummy/garbage implementation.

ref partial struct JsonElementProxy
{

    ref global::System.Text.Json.JsonElement target;

    public JsonElementProxy(ref global::System.Text.Json.JsonElement target)
    {
        this.target = ref target;
    }

    [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_dummy")]
    static extern ref readonly object ___dummy__(ref global::System.Text.Json.JsonElement target);

    public ref readonly object _dummy => ref ___dummy__(ref this.target);
    [UnsafeAccessor(UnsafeAccessorKind.Field, Name = "_dummyPrimitive")]
    static extern ref readonly int ___dummyPrimitive__(ref global::System.Text.Json.JsonElement target);

    public ref readonly int _dummyPrimitive => ref ___dummyPrimitive__(ref this.target);
}

Any help or guidance would be appreciated!

Backport to older .NET versions with IgnoresAccessChecksToAttribute?

Even though UnsafeAccessorAttribute is new to .NET 8, accessing private members with no overhead has always been possible in older .NET runtimes through the use of IgnoresAccessChecksToAttribute. That are a couple of NuGet packages (like MakeTypesPublic) that provide MSBuild targets to automate all steps required to use it.

My suggestion is that, it would be very nice if the Source Generator could provide a fallback, and generate proxies that use this attribute instead, when building in .NET versions where UnsafeAccessorAttribute is not available.

Unfortunately, though, you can't use IgnoresAccessChecksToAttribute to unlock access inside your own assembly. But I suppose if someone wants that, they can just edit their own source code and make things internal, so this shouldn't be an issue.

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.