DataGenerator icon indicating copy to clipboard operation
DataGenerator copied to clipboard

FieldAccessor has isReadonly incorrectly set

Open immeraufdemhund opened this issue 5 years ago • 0 comments

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

immeraufdemhund avatar Jan 08 '20 15:01 immeraufdemhund