C# TypeInfo IsByRef
Description
TypeInfo IsByRef
Gets a value indicating whether the
Type is passed by reference.
Syntax
TypeInfo.IsByRef
has the following syntax.
public bool IsByRef { get; }
Example
using System;//from ww w .ja v a 2 s.co m
using System.Reflection;
public class MyTypeDelegator : TypeDelegator
{
public string myElementType = null;
private Type myType = null ;
public MyTypeDelegator(Type myType) : base(myType)
{
this.myType = myType;
}
protected override bool HasElementTypeImpl()
{
if(myType.IsByRef)
{
myElementType = "reference";
return true;
}
return false;
}
}
public class Type_HasElementTypeImpl
{
public static void Main()
{
int myInt = 0 ;
int[] myArray = new int[5];
MyTypeDelegator myType = new MyTypeDelegator(myArray.GetType());
if( myType.HasElementType)
Console.WriteLine("The type of myArray is {0}.", myType.myElementType);
else
Console.WriteLine("myArray is not an array, pointer, or reference type.");
myType = new MyTypeDelegator(myInt.GetType());
if( myType.HasElementType)
Console.WriteLine("The type of myInt is {0}.", myType.myElementType);
else
Console.WriteLine("myInt is not an array, pointer, or reference type.");
}
}
The code above generates the following result.