本文整理汇总了C#中System.Type.MakeArrayType方法的典型用法代码示例。如果您正苦于以下问题:C# Type.MakeArrayType方法的具体用法?C# Type.MakeArrayType怎么用?C# Type.MakeArrayType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Type
的用法示例。
在下文中一共展示了Type.MakeArrayType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitArray
/// <summary>
/// Emits an array.
/// </summary>
/// <param name="generator"> The generator. </param>
/// <param name="arrayType"> Type of the array. </param>
/// <param name="emitElements"> The emit elements. </param>
public static void EmitArray(this ILGenerator generator, Type arrayType, IList<Action<ILGenerator>> emitElements)
{
var tLocal = generator.DeclareLocal(arrayType.MakeArrayType());
generator.Emit(OpCodes.Ldc_I4, emitElements.Count);
generator.Emit(OpCodes.Newarr, arrayType);
generator.EmitStoreLocation(tLocal.LocalIndex);
for (var i = 0; i < emitElements.Count; i++) {
generator.EmitLoadLocation(tLocal.LocalIndex);
generator.Emit(OpCodes.Ldc_I4, i);
emitElements[i](generator);
generator.Emit(OpCodes.Stelem_Ref);
}
generator.EmitLoadLocation(tLocal.LocalIndex);
}
示例2: MakeElementTypes
internal Type MakeElementTypes(Type type)
{
for (int i = this.m_elementTypes.Length - 1; i >= 0; i--)
{
if (this.m_elementTypes[i] == 3)
{
type = type.MakeArrayType();
}
else
{
if (this.m_elementTypes[i] == 2)
{
type = type.MakeArrayType(this.m_elementTypes[--i]);
}
else
{
if (this.m_elementTypes[i] == 1)
{
type = type.MakePointerType();
}
else
{
if (this.m_elementTypes[i] == 4)
{
type = type.MakeByRefType();
}
}
}
}
}
return type;
}
示例3: Resolve
public Type Resolve (Type type)
{
if (bound)
return type.MakeArrayType (1);
else if (dimensions == 1)
return type.MakeArrayType ();
return type.MakeArrayType (dimensions);
}
示例4: Resolve
internal Type Resolve(Type type)
{
if (_isBound)
return type.MakeArrayType(1);
else if (_dimensions == 1)
return type.MakeArrayType();
return type.MakeArrayType(_dimensions);
}
示例5: DeserializeArray
private static object DeserializeArray(BinaryReader sourceReader, Type elementType, int elementSize, int elementCount)
{
var arrayDataAddress = sourceReader.BaseStream.Position;
var fields = elementType.Fields(
Flags.Public |
Flags.NonPublic |
Flags.Instance);
List<FieldDelegateInformation> fieldMethods;
var item = elementType.CreateInstance();
ProcessFieldTypes(fields, out fieldMethods);
var array = elementType.MakeArrayType().CreateInstance(elementCount);
for (var i = 0; i < elementCount; ++i)
{
var element = elementType.CreateInstance();
sourceReader.BaseStream.Position = arrayDataAddress + i * elementSize;
InvokeFields(sourceReader, element, fields, fieldMethods);
array.SetElement(i, element);
}
return array;
}
示例6: MakeArray
public static Type MakeArray (Type t, List<int> sizes, List<int> loBounds)
{
var mt = t as MetadataType;
if (mt != null) {
if (sizes == null) {
sizes = new List<int> ();
sizes.Add (1);
}
mt.m_arraySizes = sizes;
mt.m_arrayLoBounds = loBounds;
return mt;
}
if (sizes == null || sizes.Count == 1)
return t.MakeArrayType ();
return t.MakeArrayType (sizes.Capacity);
}
示例7: CreateArray
/// <summary>
/// Creates an array of the given type and stores it in a returned local.
/// </summary>
/// <param name="gen">The generator to inject the code into.</param>
/// <param name="type">The type of the array.</param>
/// <param name="size">The size of the array.</param>
/// <returns>A local builder that now contains the array.</returns>
public static LocalBuilder CreateArray(this ILGenerator gen, Type type, int size)
{
var ret = gen.DeclareLocal(type.MakeArrayType());
gen.Emit(OpCodes.Ldc_I4, size);
gen.Emit(OpCodes.Newarr, type);
gen.Emit(OpCodes.Stloc, ret);
return ret;
}
示例8: MakeArrayType
public static Type MakeArrayType(Type elementType)
{
#if CF
return Array.CreateInstance(elementType, 0).GetType(); // ouch
#else
return elementType.MakeArrayType();
#endif
}
示例9: BuildForArrayOf
/// <summary>
/// Builds <see cref="IArrayAccessor"/> for arrays with elements of type <paramref name="arrayElementType"/>.
/// </summary>
public static IArrayAccessor BuildForArrayOf(Type arrayElementType)
{
Guard.AgainstNull(arrayElementType, "arrayElementType");
Type arrayType = arrayElementType.MakeArrayType();
return new ArrayAccessor(arrayElementType, BuildGetMethod(arrayType, arrayElementType),
BuildSetMethod(arrayType, arrayElementType));
}
示例10: CreateArray
public static LocalBuilder CreateArray(this ILGenerator body, Type arrayType, int length)
{
var array = body.DeclareLocal(arrayType.MakeArrayType());
body.Emit(OpCodes.Ldc_I4, length);
body.Emit(OpCodes.Newarr, arrayType);
body.Emit(OpCodes.Stloc, array);
return array;
}
示例11: EmitArrayInitializer
Type EmitArrayInitializer(Type ElementType, CodeExpression Expr, int Index)
{
Generator.Emit(OpCodes.Dup);
Generator.Emit(OpCodes.Ldc_I4, Index);
Type Generated = EmitExpression(Expr);
ForceTopStack(Generated, ElementType);
Generator.Emit(OpCodes.Stelem_Ref);
return ElementType.MakeArrayType();
}
示例12: StandardParse
protected virtual object StandardParse(string[] values, Type targetType, Type elementType)
{
var parser = StringParsing.GetParser(elementType);
var arr = Activator.CreateInstance(elementType.MakeArrayType(), values.Count());
for (var i = 0; i < values.Length; i++)
((Array)arr).SetValue(parser.Parse(values[i], elementType), i);
return arr;
}
示例13: CheckReturnTypeCanBeSatisfiedByArrayOf
protected void CheckReturnTypeCanBeSatisfiedByArrayOf(Type type)
{
var arrayType = type.MakeArrayType();
if (ComponentType.IsAssignableFrom(arrayType))
{
return;
}
ThrowUnsupportedCollectionType();
}
示例14: MakeElementTypes
internal Type MakeElementTypes(Type type)
{
for (int i = m_elementTypes.Length - 1; i >= 0; i --)
{
if (m_elementTypes[i] == SzArray)
{
type = type.MakeArrayType();
}
else if (m_elementTypes[i] == Array)
{
type = type.MakeArrayType(m_elementTypes[--i]);
}
else if ((m_elementTypes[i] == Pointer))
{
type = type.MakePointerType();
}
else if ((m_elementTypes[i] == ByRef))
{
type = type.MakeByRefType();
}
}
return type;
}
示例15: CastElement
public CastElement(ExpressionElement castExpression, string[] destTypeParts, bool isArray, IServiceProvider services)
{
MyCastExpression = castExpression;
MyDestType = GetDestType(destTypeParts, services);
if (MyDestType == null) {
base.ThrowCompileException(CompileErrorResourceKeys.CouldNotResolveType, CompileExceptionReason.UndefinedName, GetDestTypeString(destTypeParts, isArray));
}
if (isArray == true) {
MyDestType = MyDestType.MakeArrayType();
}
if (this.IsValidCast(MyCastExpression.ResultType, MyDestType) == false) {
this.ThrowInvalidCastException();
}
}