本文整理汇总了C#中Reference.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Reference.GetType方法的具体用法?C# Reference.GetType怎么用?C# Reference.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reference
的用法示例。
在下文中一共展示了Reference.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateReference
public string UpdateReference(int referenceId = -1, string propertyId = null, string propertyValue = null , string token = null)
{
if (Request.RequestType.Equals("OPTIONS", StringComparison.InvariantCultureIgnoreCase))
{
return null;
}
try
{
int authUserId = -1;
if (token != null)
{
authUserId = authenticationEngine.authenticate(token);
}
else
{
return AddErrorHeader("An authentication token must be passed in", 2);
}
if (authUserId < 0)
{
return AddErrorHeader("You are not authenticated, please log in!", 2);
}
Reference reference = new Reference();
if (referenceId > 0)
{
reference = userManager.GetReference(referenceId);
if (reference == null)
{
return AddErrorHeader("The reference with the given referenceId does not exist", 1);
}
}
else
{
return AddErrorHeader("A referenceId must be passed in", 1);
}
if (reference.userId != authUserId)
{
return AddErrorHeader("User is not authorized to exit this reference", 3);
}
System.Reflection.PropertyInfo pi;
if(propertyId == null)
{
return AddErrorHeader("A propertyId must be passed in", 1);
}
else
{
pi = reference.GetType().GetProperty(propertyId);
}
if(propertyValue == null)
{
return AddErrorHeader("A propertyValue must be passed in", 1);
}
else
{
pi.SetValue(reference, Convert.ChangeType(propertyValue, pi.PropertyType), null);
userManager.UpdateReference(reference);
return AddSuccessHeader("Experience with id: " + reference.id + " has been successfully updated", true);
}
}
catch(Exception ex)
{
logAccessor.CreateLog(DateTime.Now, "userController - updateReference", ex.StackTrace);
return AddErrorHeader("Something went wrong while updating this reference element", 1);
}
}