本文整理汇总了C#中XrmFakedContext.FindReflectedAttributeType方法的典型用法代码示例。如果您正苦于以下问题:C# XrmFakedContext.FindReflectedAttributeType方法的具体用法?C# XrmFakedContext.FindReflectedAttributeType怎么用?C# XrmFakedContext.FindReflectedAttributeType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XrmFakedContext
的用法示例。
在下文中一共展示了XrmFakedContext.FindReflectedAttributeType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConditionExpressionValueCast
public static object GetConditionExpressionValueCast(string value, XrmFakedContext ctx, string sEntityName, string sAttributeName)
{
if (ctx.ProxyTypesAssembly != null)
{
//We have proxy types so get appropiate type value based on entity name and attribute type
var reflectedType = ctx.FindReflectedType(sEntityName);
if (reflectedType != null)
{
var attributeType = ctx.FindReflectedAttributeType(reflectedType, sAttributeName);
if (attributeType != null)
{
try
{
return GetValueBasedOnType(attributeType, value);
}
catch (Exception e)
{
throw new Exception(string.Format("When trying to parse value for entity {0} and attribute {1}: {2}", sEntityName, sAttributeName, e.Message));
}
}
}
}
//Try parsing a guid
Guid gOut = Guid.Empty;
if (Guid.TryParse(value, out gOut))
return gOut;
//Try checking if it is a numeric value, cause, from the fetchxml it
//would be impossible to know the real typed based on the string value only
// ex: "123" might compared as a string, or, as an int, it will depend on the attribute
// data type, therefore, in this case we do need to use proxy types
bool bIsNumeric = false;
bool bIsDateTime = false;
double dblValue = 0.0;
decimal decValue = 0.0m;
int intValue = 0;
if (double.TryParse(value, out dblValue))
bIsNumeric = true;
if (decimal.TryParse(value, out decValue))
bIsNumeric = true;
if (int.TryParse(value, out intValue))
bIsNumeric = true;
DateTime dtValue = DateTime.MinValue;
if (DateTime.TryParse(value, out dtValue))
bIsDateTime = true;
if(bIsNumeric || bIsDateTime)
{
throw new Exception("When using arithmetic values in Fetch a ProxyTypesAssembly must be used in order to know which types to cast values to.");
}
//Default value
return value;
}