本文整理汇总了C#中Array.GetValue方法的典型用法代码示例。如果您正苦于以下问题:C# Array.GetValue方法的具体用法?C# Array.GetValue怎么用?C# Array.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Array
的用法示例。
在下文中一共展示了Array.GetValue方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Copy
/// <summary>
///
/// </summary>
public static void Copy(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length)
{
for (int s = 0, d = destinationIndex; s < length; s++, d++)
{
sourceArray.SetValue(destinationArray.GetValue(d), s + sourceIndex);
}
}
示例2: VerifyGetAllValues
private static void VerifyGetAllValues(NameObjectCollectionBase nameObjectCollection, Array values)
{
Assert.Equal(nameObjectCollection.Count, values.Length);
for (int i = 0; i < values.Length; i++)
{
Assert.Equal(new Foo("Value_" + i), values.GetValue(i));
}
}
示例3: WriteValue
private void WriteValue(Array array)
{
// This method is called only if WriteValue(object) is called with an array
// The contract for XmlWriter.WriteValue(object) requires that this object array be written out as a string.
// E.g. WriteValue(new int[] { 1, 2, 3}) should be equivalent to WriteString("1 2 3").
JsonDataType oldDataType = _dataType;
// Set attribute mode to String because WritePrimitiveValue might write numerical text.
// Calls to methods that write numbers can't be mixed with calls that write quoted text unless the attribute mode is explictly string.
_dataType = JsonDataType.String;
StartText();
for (int i = 0; i < array.Length; i++)
{
if (i != 0)
{
_nodeWriter.WriteText(JsonGlobals.WhitespaceChar);
}
WritePrimitiveValue(array.GetValue(i));
}
_dataType = oldDataType;
}
示例4: WriteValue
private void WriteValue(Array array)
{
FlushBase64();
StartContent();
_writer.WriteStartListText();
_inList = true;
for (int i = 0; i < array.Length; i++)
{
if (i != 0)
{
_writer.WriteListSeparator();
}
WritePrimitiveValue(array.GetValue(i));
}
_inList = false;
_writer.WriteEndListText();
EndContent();
}
示例5: CreateArrayNodeSub
private YamlNode CreateArrayNodeSub(Array array, int i, long[] indices)
{
var type= array.GetType();
var element = type.GetElementType();
var sequence = seq();
if ( i == 0 ) {
sequence.Tag = TypeNameToYamlTag(type);
AppendToAppeared(array, sequence);
}
if ( element.IsPrimitive || element.IsEnum || element == typeof(decimal) )
if ( array.Rank == 1 || ArrayLength(array, i+1) < 20 )
sequence.Properties["Compact"] = "true";
for ( indices[i] = 0; indices[i] < array.GetLength(i); indices[i]++ )
if ( i == array.Rank - 1 ) {
var n = ObjectToNode(array.GetValue(indices), type.GetElementType());
sequence.Add(n);
} else {
var s = CreateArrayNodeSub(array, i + 1, indices);
sequence.Add(s);
}
return sequence;
}
示例6: GetPropertyOwnerForComponent
private object GetPropertyOwnerForComponent(Array a, int i)
{
object propertyOwner = a.GetValue(i);
if (propertyOwner is ICustomTypeDescriptor)
{
propertyOwner = ((ICustomTypeDescriptor)propertyOwner).GetPropertyOwner(this.descriptors[i]);
}
return propertyOwner;
}
示例7: CopyTo
public void CopyTo(BitArray bitArray, Array array, int index, Array expected, Type arrayType)
{
object defaultValue = Activator.CreateInstance(arrayType);
ICollection collection = bitArray;
collection.CopyTo(array, index);
for (int i = 0; i < index; i++)
{
Assert.Equal(defaultValue, array.GetValue(i));
}
for (int i = 0; i < expected.Length; i++)
{
Assert.Equal(expected.GetValue(i), array.GetValue(i + index));
}
for (int i = index + expected.Length; i < array.Length; i++)
{
Assert.Equal(defaultValue, array.GetValue(i));
}
}
示例8: WriteRectangle
// Iterates over a Rectangle array, for each element of the array invokes WriteArrayMember
private void WriteRectangle(WriteObjectInfo objectInfo, int rank, int[] maxA, Array array, NameInfo arrayElemNameTypeInfo, int[] lowerBoundA)
{
int[] currentA = new int[rank];
int[] indexMap = null;
bool isLowerBound = false;
if (lowerBoundA != null)
{
for (int i = 0; i < rank; i++)
{
if (lowerBoundA[i] != 0)
{
isLowerBound = true;
}
}
}
if (isLowerBound)
{
indexMap = new int[rank];
}
bool isLoop = true;
while (isLoop)
{
isLoop = false;
if (isLowerBound)
{
for (int i = 0; i < rank; i++)
{
indexMap[i] = currentA[i] + lowerBoundA[i];
}
WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(indexMap));
}
else
{
WriteArrayMember(objectInfo, arrayElemNameTypeInfo, array.GetValue(currentA));
}
for (int irank = rank - 1; irank > -1; irank--)
{
// Find the current or lower dimension which can be incremented.
if (currentA[irank] < maxA[irank] - 1)
{
// The current dimension is at maximum. Increase the next lower dimension by 1
currentA[irank]++;
if (irank < rank - 1)
{
// The current dimension and higher dimensions are zeroed.
for (int i = irank + 1; i < rank; i++)
{
currentA[i] = 0;
}
}
isLoop = true;
break;
}
}
}
}
示例9: GetCoercedArrayLiteral
/// <summary>
/// Gets the array literal in arrayValue coercing TypeNode[] and EnumNode[] as needed.
/// </summary>
/// <param name="arrayType">A TypeNode representing the array type</param>
/// <param name="arrayValue">The value of the array literal to coerce</param>
/// <returns>An Array object that has been coerced to the appropriate runtime type</returns>
protected Array GetCoercedArrayLiteral(ArrayType arrayType, Array arrayValue)
{
if(arrayType == null)
return null;
if(arrayValue == null)
return null;
// Multi-dimensional arrays are not legal in attribute instances according section 17.1.3 of the C# 1.0 spec
if(arrayValue.Rank != 1)
return null;
TypeNode elemType = arrayType.ElementType;
if(elemType.typeCode != ElementType.ValueType && elemType.typeCode != ElementType.Class)
return arrayValue;
int arraySize = arrayValue.GetLength(0);
Type et = elemType.GetRuntimeType();
if(et == null)
return null;
Array val = Array.CreateInstance(et, arraySize);
for(int i = 0; i < arraySize; i++)
val.SetValue(this.GetCoercedLiteralValue(elemType, arrayValue.GetValue(i)), i);
return val;
}
示例10: compareSequence
// Arrays have only one dimension
static bool compareSequence(Array ar1, Array ar2)
{
Debug.Assert(ar1 != null && ar2 != null);
Type t1 = ar1.GetType();
Type t2 = ar2.GetType();
if (!(ar1.Rank == 1 && ar2.Rank == 1
&& ar1.Length == ar2.Length && t1.GetElementType() == t2.GetElementType()))
return false;
//arrays have same rank and size and element type.
int len = ar1.Length;
Type elemType = t1.GetElementType();
bool ret = true;
for (int i = 0; i < len; i++)
{
if (compareData(ar1.GetValue(i), ar2.GetValue(i)) == false)
{
ret = false;
break;
}
}
return ret;
}