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

FieldAccessor has isReadonly incorrectly set #22

@immeraufdemhund

Description

@immeraufdemhund

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions