本文整理汇总了C#中System.Web.OData.Delta.TryGetPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:C# Delta.TryGetPropertyValue方法的具体用法?C# Delta.TryGetPropertyValue怎么用?C# Delta.TryGetPropertyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.OData.Delta
的用法示例。
在下文中一共展示了Delta.TryGetPropertyValue方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Patch
public IHttpActionResult Patch([FromODataUri] int key, Delta<Product> patch)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
Delta<V2VM.Product> v2Patch = new Delta<V2VM.Product>();
foreach (string name in patch.GetChangedPropertyNames())
{
object value;
if (patch.TryGetPropertyValue(name, out value))
{
v2Patch.TrySetPropertyValue(name, value);
}
}
var v2Product = _repository.Patch((long)key, v2Patch, Request);
return Updated(Mapper.Map<Product>(v2Product));
}
示例2: Patch
public IHttpActionResult Patch(int key, Delta<SpatialCustomer> customer)
{
// Assert part
Assert.Equal(3, key);
Assert.Equal(new[] {"Location"}, customer.GetChangedPropertyNames());
object value;
customer.TryGetPropertyValue("Location", out value);
GeographyPoint point = value as GeographyPoint;
Assert.NotNull(point);
Assert.Equal(7, point.Longitude);
Assert.Equal(8, point.Latitude);
Assert.Equal(9, point.Z);
Assert.Equal(10, point.M);
return Ok();
}
示例3: Patch
public async Task<IHttpActionResult> Patch([FromODataUri] int key, Delta<Customer> patch)
{
object id;
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
else if (patch.TryGetPropertyValue("Id", out id) && (int)id != key)
{
return BadRequest("The key from the url must match the key of the entity in the body");
}
Customer originalEntity = await context.Customers.FindAsync(key);
if (originalEntity == null)
{
return NotFound();
}
else
{
patch.Patch(originalEntity);
await context.SaveChangesAsync();
}
return Updated(originalEntity);
}
示例4: Put
public IHttpActionResult Put(int key, Delta<DateAndTimeOfDayModel> dt)
{
Assert.Equal(new[] { "Birthday", "CreatedTime" }, dt.GetChangedPropertyNames());
// Birthday
object value;
bool success = dt.TryGetPropertyValue("Birthday", out value);
Assert.True(success);
DateTime dateTime = Assert.IsType<DateTime>(value);
Assert.Equal(DateTimeKind.Unspecified, dateTime.Kind);
Assert.Equal(new DateTime(2199, 1, 2), dateTime);
// CreatedTime
success = dt.TryGetPropertyValue("CreatedTime", out value);
Assert.True(success);
TimeSpan timeSpan = Assert.IsType<TimeSpan>(value);
Assert.Equal(new TimeSpan(0, 14, 13, 15, 179), timeSpan);
return Updated(dt);
}
示例5: Put
public IHttpActionResult Put(int key, Delta<DateTimeModel> dt)
{
Assert.Equal(new[] { "BirthdayA", "BirthdayB" }, dt.GetChangedPropertyNames());
object value;
bool success = dt.TryGetPropertyValue("BirthdayA", out value);
Assert.True(success);
DateTime dateTime = Assert.IsType<DateTime>(value);
Assert.Equal(DateTimeKind.Unspecified, dateTime.Kind);
Assert.Equal(new DateTime(2098, 12, 31, 17, 2, 3), dateTime);
success = dt.TryGetPropertyValue("BirthdayB", out value);
Assert.True(success);
Assert.Null(value);
return Updated(dt);
}