本文整理汇总了C#中System.Array.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetType方法的具体用法?C# Array.GetType怎么用?C# Array.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Array
的用法示例。
在下文中一共展示了Array.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultiDimArrayNode
public MultiDimArrayNode(ObjectNode parent, Array array, string name) : base(parent, array, 0, null)
{
if (name == null)
{
this.Name = array.GetType().GetElementType().FormatTypeName() + "[,]";
}
else
{
this.Name = name;
}
this.ElementType = array.GetType().GetElementType();
this.Data = array;
}
示例2: CodeRepresentation
public static string CodeRepresentation(Array a)
{
StringBuilder ret = new StringBuilder();
ret.Append(a.GetType().FullName);
ret.Append("(");
switch (a.Rank) {
case 1: {
for (int i = 0; i < a.Length; i++) {
if (i > 0) ret.Append(", ");
ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0))));
}
}
break;
case 2: {
int imax = a.GetLength(0);
int jmax = a.GetLength(1);
for (int i = 0; i < imax; i++) {
ret.Append("\n");
for (int j = 0; j < jmax; j++) {
if (j > 0) ret.Append(", ");
ret.Append(Ops.StringRepr(a.GetValue(i + a.GetLowerBound(0), j + a.GetLowerBound(1))));
}
}
}
break;
default:
ret.Append(" Multi-dimensional array ");
break;
}
ret.Append(")");
return ret.ToString();
}
示例3: ReDim
/// <summary>
/// 重新定义一个数组列表
/// </summary>
/// <param name="OriginalArray">需要被重定义的数组</param>
/// <param name="NewSize">这个数组的新大小</param>
public static Array ReDim(Array OriginalArray, Int32 NewSize)
{
Type ArrayElementsType = OriginalArray.GetType().GetElementType();
Array newArray = Array.CreateInstance(ArrayElementsType, NewSize);
Array.Copy(OriginalArray, 0, newArray, 0, Math.Min(OriginalArray.Length, NewSize));
return newArray;
}
示例4: InvalidCastException
void ICollection.CopyTo(Array array, int index)
{
if (array is ThemeInfo[])
((ICollection)this._collection).CopyTo(array, index);
else
throw new InvalidCastException(String.Format("Can not cast {0} to ThemeInfo[]", array.GetType()));
}
示例5: ArrayToDescriptor
public static string ArrayToDescriptor(Array array,
TypeRegistry treg,
Type type = null,
string th = null)
{
if (type==null)
type = array.GetType();
if (array.LongLength>MAX_ELM_COUNT)
throw new SlimSerializationException(StringConsts.SLIM_ARRAYS_OVER_MAX_ELM_ERROR.Args(array.LongLength, MAX_ELM_COUNT));
if (type==typeof(object[]))//special case for object[], because this type is very often used in Glue and other places
return "$1|"+array.Length.ToString();
if (th==null)
th = treg.GetTypeHandle(type);
var ar = array.Rank;
if (ar>MAX_DIM_COUNT)
throw new SlimSerializationException(StringConsts.SLIM_ARRAYS_OVER_MAX_DIMS_ERROR.Args(ar, MAX_DIM_COUNT));
var descr = new StringBuilder(th);
descr.Append('|');//separator char
for(int i=0; i<ar; i++)
{
descr.Append(array.GetLowerBound(i));
descr.Append('~');
descr.Append(array.GetUpperBound(i));
if (i<ar-1)
descr.Append(',');
}
return descr.ToString();
}
示例6: ArrayExtension
public ArrayExtension (Array elements)
{
if (elements == null)
throw new ArgumentNullException ("elements");
Type = elements.GetType ().GetElementType ();
items = new ArrayList (elements);
}
示例7: aRedimension
private static Array aRedimension(Array orgArray, Int32 tamaño)
{
Type t = orgArray.GetType().GetElementType();
Array nArray = Array.CreateInstance(t, tamaño);
Array.Copy(orgArray, 0, nArray, 0, Math.Min(orgArray.Length, tamaño));
return nArray;
}
示例8: FromArray
/// <summary>
/// This factory method wraps a SafePinnedObject around the specified array.
/// </summary>
/// <param name="array">The array that you want to pin.</param>
/// <param name="startOffset">The first element in the array whose address you want to pass to native code.</param>
/// <param name="numberOfElements">The number of elements in the array you wish to pass to native code.</param>
/// <returns>The SafePinnedObject wrapping the desired array elements.</returns>
public static SafePinnedObject FromArray(Array array, Int32 startOffset, Int32 numberOfElements) {
// If obj is null, we create this object but it pins nothing (size will be 0)
if (array == null) return new SafePinnedObject(null, 0, 0);
// Validate the structure of the object before pinning it
if (array.Rank != 1)
throw new ArgumentException("array Rank must be 1");
if (startOffset < 0)
throw new ArgumentOutOfRangeException("startOffset", "Must be >= 0");
// Validate the structure of the array's element type
Type elementType = array.GetType().GetElementType();
if (!elementType.IsValueType && !elementType.IsEnum)
throw new ArgumentException("array's elements must be value types or enum types");
if (elementType.IsAutoLayout)
throw new ArgumentException("array's elements must not be auto layout");
// If numElements not specied (-1), assume the remainder of the array length
if (numberOfElements == -1) numberOfElements = array.Length - startOffset;
if (numberOfElements > array.Length)
throw new ArgumentOutOfRangeException("numberOfElements", "Array has fewer elements than specified");
// Convert startOffset from element offset to byte offset
startOffset *= Marshal.SizeOf(elementType);
return new SafePinnedObject(array, startOffset,
numberOfElements * Marshal.SizeOf(elementType)); // Convert numElements to number of bytes
}
示例9: ArrayDeepEquals
public static bool ArrayDeepEquals(Array arr1, Array arr2) {
if (arr1.Length!=arr2.Length || arr1.GetType()!=arr2.GetType())
return false;
for (int i=0; i<arr1.Length; i++) {
var v1 = arr1.GetValue(i);
var v2 = arr2.GetValue(i);
if (v1 is Array && v2 is Array)
if (!ArrayDeepEquals((Array)v1, (Array)v2)) {
return false;
} else
continue;
if (v1==null && v2==null)
continue;
if (v1!=null)
if (!v1.Equals(v2))
return false;
if (v2 != null)
if (!v2.Equals(v1))
return false;
}
return true;
}
示例10: WriteSimpleArray
private static void WriteSimpleArray(this ObjectWriter writer, Array value)
{
writer.WriteTag(FormatterTag.Array);
var elementType = value.GetType().GetElementType();
writer.InnerWrite(elementType);
writer.InnerWrite(value);
}
示例11: ArrayExtension
public ArrayExtension (Array elements)
{
if (elements == null)
throw new ArgumentNullException ("elements");
Type = elements.GetType ().GetElementType ();
Items = new List<object> (elements.Length);
foreach (var o in elements)
Items.Add (o);
}
示例12: ArrayExtension
public ArrayExtension(Array elements)
{
this.arrayElementList = new ArrayList();
if (elements == null)
{
throw new ArgumentNullException("elements");
}
this.arrayElementList.AddRange(elements);
this.arrayType = elements.GetType().GetElementType();
}
示例13: ArrayEquals
/// <summary>
/// Compares to arrays for values equality.
/// </summary>
/// <returns>true if both arrays contain the same values, false otherwise</returns>
internal static bool ArrayEquals(Array l, Array r)
{
if (l == null && r == null)
{
return true;
}
if (l == null || r == null)
{
return false;
}
if (l.GetType() != r.GetType())
{
return false;
}
if (l.Length != r.Length)
{
return false;
}
for (var i = 0; i < l.Length; i++)
{
var lv = l.GetValue(i);
var rv = r.GetValue(i);
if (lv == rv || lv == null && rv == null)
{
continue;
}
if (lv == null || rv == null)
{
return false;
}
if (lv.GetType().IsArray)
{
if (!ArrayEquals(lv as Array, rv as Array))
{
return false;
}
}
else
{
if (!lv.Equals(rv))
{
return false;
}
}
}
return true;
}
示例14: AssertImport
private static void AssertImport(Array expected, string s)
{
JsonReader reader = CreateReader(s);
object o = reader.Get(expected.GetType());
if (expected == null)
Assert.IsNull(o);
Assert.AreEqual(expected, o);
}
示例15: Redim
/// <summary>
/// 重定义数组
/// </summary>
/// <param name="origArray">原来的数组长度</param>
/// <param name="desiredsize">新的宽度</param>
/// <returns></returns>
public static Array Redim(Array origArray, Int32 desiredsize)
{
//确定每个元素类型
Type t = origArray.GetType().GetElementType();
//创建一个含有期望元素个数的新数组
//新数组的类型必须匹配原数组的类型
Array newArray = Array.CreateInstance(t, desiredsize);
//将原数组中的元素拷贝到新数组中
Array.Copy(origArray, 0, newArray, 0, Math.Min(origArray.Length, desiredsize));
return newArray;
}