Во-первых, K& R c не имеет понятия "ссылок", просто указатели. &
средства оператора "берут адрес".
, Во-вторых, r
в cannonRect()
локальная переменная и не r
в main()
. Изменение, где локальное r
точки не производит r
в вызывающей подпрограмме.
Наконец, как уже отмечено локальное struct rect
выделяется на стеке и выходит в близкой фигурной скобке,
Работы решения матовой Johnson-пинты, но если бы всеми Вашими DateTimes, как предполагается, является UTC, создавая атрибут, были бы слишком окольными. Вот то, как я упростил его:
public class MyContext : DbContext
{
public DbSet<Foo> Foos { get; set; }
public MyContext()
{
((IObjectContextAdapter)this).ObjectContext.ObjectMaterialized +=
(sender, e) => SetDateTimesToUtc(e.Entity);
}
private static void SetDateTimesToUtc(object entity)
{
if (entity == null)
{
return;
}
var properties = entity.GetType().GetProperties();
foreach (var property in properties)
{
if (property.PropertyType == typeof(DateTime))
{
property.SetValue(entity, DateTime.SpecifyKind((DateTime)property.GetValue(entity), DateTimeKind.Utc));
}
else if (property.PropertyType == typeof(DateTime?))
{
var value = (DateTime?)property.GetValue(entity);
if (value.HasValue)
{
property.SetValue(entity, DateTime.SpecifyKind(value.Value, DateTimeKind.Utc));
}
}
}
}
}