Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

FieldAccessor has isReadonly incorrectly set #22

Open
immeraufdemhund opened this issue Jan 8, 2020 · 0 comments
Open

FieldAccessor has isReadonly incorrectly set #22

immeraufdemhund opened this issue Jan 8, 2020 · 0 comments

Comments

@immeraufdemhund
Copy link

snippet from your code

            bool isReadonly = !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral;
            if (!isReadonly)
                _setter = new Lazy<Action<object, object>>(() => DelegateFactory.CreateSet(_fieldInfo));

            HasSetter = !isReadonly;

I stumbled on this when trying to seed data into my database using linqpad connecting with LinqToSql. I had to override MappingProfile.Property to allow for Fields. When I did I was getting an exception that there is no setter.

I spit out the all the fields of the class and all of them had IsInitOnly = false and IsLiteral = false. So as a test I made the following test

void Main()
{
    //Setup();
    object a = new ClientSurveyItem();
    a = new Clown();
    var fieldInfo = a.GetType().GetField("Section");
    bool isReadonly = !fieldInfo.IsInitOnly && !fieldInfo.IsLiteral;
    fieldInfo.Dump($"isReadonly:{isReadonly}");
    //var clientSurveyItem = _dataManager.CreateClientSurveyItem().Result;
}
class Clown
{
    public string Section;
}

my output is isReadonly:True

yet I can very easily do a.Section = "somethign";

tried the same thing with a struct and I get same results

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant