本文整理汇总了C#中Type.MakeByRefType方法的典型用法代码示例。如果您正苦于以下问题:C# Type.MakeByRefType方法的具体用法?C# Type.MakeByRefType怎么用?C# Type.MakeByRefType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.MakeByRefType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInstanceLocal
private LocalBuilder GetInstanceLocal(Type type)
{
Type instanceLocalType = type.GetTypeInfo().IsValueType ? type.MakeByRefType() : type;
return GetLocal(instanceLocalType);
}
示例2: TestMakeByRefType
public static void TestMakeByRefType(Type t)
{
Type tRef1 = t.MakeByRefType();
Type tRef2 = t.MakeByRefType();
Assert.Equal(tRef1, tRef2);
Assert.True(tRef1.IsByRef);
Assert.True(tRef1.HasElementType);
Assert.Equal(t, tRef1.GetElementType());
string s1 = t.ToString();
string s2 = tRef1.ToString();
Assert.Equal(s2, s1 + "&");
}
示例3: TestIsByRef
public static void TestIsByRef(Type t, bool expected)
{
Assert.Equal(expected, t.IsByRef);
Assert.True(t.MakeByRefType().IsByRef);
}
示例4: GenerateConversion
static Expression GenerateConversion(Expression expr, Type type, int errorPos)
{
Type exprType = expr.Type;
if (exprType == type)
return expr;
if (exprType.IsValueType() && type.IsValueType())
{
if ((IsNullableType(exprType) || IsNullableType(type)) &&
GetNonNullableType(exprType) == GetNonNullableType(type))
return Expression.Convert(expr, type);
if ((IsNumericType(exprType) || IsEnumType(exprType)) &&
(IsNumericType(type)) || IsEnumType(type))
return Expression.ConvertChecked(expr, type);
}
if (exprType.IsAssignableFrom(type) || type.IsAssignableFrom(exprType) || exprType.IsInterface() || type.IsInterface())
return Expression.Convert(expr, type);
// Try to Parse the string rather that just generate the convert statement
if (expr.NodeType == ExpressionType.Constant && exprType == typeof(string))
{
string text = (string)((ConstantExpression)expr).Value;
// DateTime is parsed as UTC time.
DateTime dateTime;
if (type == typeof(DateTime) && DateTime.TryParse(text, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
return Expression.Constant(dateTime, type);
object[] arguments = { text, null };
#if DNXCORE50
MethodInfo method = type.GetMethod("TryParse", new [] { typeof(string), type.MakeByRefType() });
#else
MethodInfo method = type.GetMethod("TryParse", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(string), type.MakeByRefType() }, null);
#endif
if (method != null && (bool)method.Invoke(null, arguments))
return Expression.Constant(arguments[1], type);
}
throw ParseError(errorPos, Res.CannotConvertValue, GetTypeName(exprType), GetTypeName(type));
}