I got the following message:
Warning. The field is never assigned and will always have a default value of null.
My code looks (it is simplified, therefore useless):
public class MyEntity
{
public string MyProp { get; set; }
}
public class MyClass
{
string dbMyProp;
public string MyProp { get { return dbMyProp.Replace("a", "b"); } }
public static readonly Expression<Func<MyEntity, MyClass>> FromMyEntity = e => new MyClass
{
dbMyProp = e.MyProp
};
}
I think this message is incorrect.
Is this a bug in the C # compiler or am I missing something?
UPDATE Field dbMyProp. This is simplified, but it still raises this warning.
UPDATE2 The following code does not raise this warning:
public class MyClass2
{
string dbMyProp;
public string MyProp { get { return dbMyProp.Replace("a", "b"); } }
public static MyClass2 FromMyEntity(MyEntity e)
{
return new MyClass2
{
dbMyProp = e.MyProp
};
}
}
source
share