Private / Protected / Internal changes
using System;
using TypeKitchen;
namespace test2
{
public class SimpleType
{
internal string ThisIsAString { get; set; }
}
internal class Program
{
private static void Main()
{
var instance = new SimpleType();
try
{
var accessor = WriteAccessor.Create(typeof(SimpleType), AccessorMemberScope.All, out _);
accessor[instance, "ThisIsAString"] = "test";
}
catch (Exception ex)
{
Console.Write("error occured : " + ex.Message); // error occured : Attempt by method 'Write_SimpleType_Fields\, Properties_Private_D80BA31E4EC25FD8C444170139A6190E.set_Item(System.Object, System.String, System.Object)' to access method 'test2.SimpleType.set_ThisIsAString(System.String)' failed.
}
if (Environment.UserInteractive)
Console.ReadKey();
}
}
}
i'm trying to access an internal property but without success... Is that an expected behavior ? I'm not sure to understand the goal of AccessorMemberScope.All if it can't actually access anything else than public.
@erwan-joly It should be able to -- let me see if I can reproduce your issue.
The late-binding accessor wrapper isn't kicking in when it should. There also seems to be an issue in the IL for callvirt. I'll get a patch out hopefully this weekend.
On Fri, Apr 3, 2020 at 10:55 PM Erwan JOLY [email protected] wrote:
using System; using TypeKitchen;
namespace test2 { public class SimpleType { internal string ThisIsAString { get; set; } }
internal class Program { private static void Main() { var instance = new SimpleType(); try { var accessor = WriteAccessor.Create(typeof(SimpleType), AccessorMemberScope.All, out _); accessor[instance, "ThisIsAString"] = "test"; } catch (Exception ex) { Console.Write("error occured : " + ex.Message); // error occured : Attempt by method 'Write_SimpleType_Fields\, Properties_Private_D80BA31E4EC25FD8C444170139A6190E.set_Item(System.Object, System.String, System.Object)' to access method 'test2.SimpleType.set_ThisIsAString(System.String)' failed. } if (Environment.UserInteractive) Console.ReadKey(); } }}
i'm trying to access an internal property but without success... Is that an expected behavior ? I'm not sure to understand the goal of AccessorMemberScope.All if it can't actually access anything else than public.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/danielcrenna/TypeKitchen/issues/3, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAA7USS6HH64JU6H2I4FDKDRK2OQ7ANCNFSM4L45RKVA .
-- Daniel Crenna Conatus Creative Inc. cell:613.400.4286
i tried fixing this by myself but without success.
FYI : it doesn't work for both field and properties. The exception in case of Field is
System.FieldAccessException : Attempt by method 'Read_FooStructPrivate_Fields\, Properties_All_D903032FFB3253D3D893C6C0F3799B0.get_Item(System.Object, System.String)' to access field 'TypeKitchen.Tests.ReadAccessorTests+FooStructPrivate._foo' failed.
from my understanding it field doesn't use callvirt but Ldfld so i'm not sure of what is happening there :/
Hi all!
I'm able to set up internal or private members via private members accessor WriteAccessor.Create(obj, AccessorMemberTypes.Properties, AccessorMemberScope.Private, out members) but behavior is misleading. For instance instead of 228911010879111168 accessor writes value 1330348548968.
Regards