public ArrayMethodILEmitter(ArrayMethod method) { _method = method; ArrayType arrayType = (ArrayType)method.OwningType; _rank = arrayType.Rank; _elementType = arrayType.ElementType; }
private ArrayMethodILEmitter(ArrayMethod method) { _method = method; ArrayType arrayType = (ArrayType)method.OwningType; _rank = arrayType.Rank; _elementType = arrayType.ElementType; _emitter = new ILEmitter(); // This helper field is needed to generate proper GC tracking. There is no direct way // to create interior pointer. _helperFieldToken = _emitter.NewToken(_method.Context.GetWellKnownType(WellKnownType.Object).GetKnownField("m_pEEType")); }
public void GetCountTest() { ArrayMethod arrayMethod = new ArrayMethod(); Assert.AreEqual(10, arrayMethod.GetCount(new int[] { 4, 4, 5, 8, 5, 3, 6 })); Assert.AreEqual(12, arrayMethod.GetCount(new int[] { 1, 5, 9, 10, 5 })); Assert.AreEqual(6, arrayMethod.GetCount(new int[] { 2, 5, 2, 7 })); Assert.AreEqual(1, arrayMethod.GetCount(new int[] { 1, 2, 3 })); Assert.AreEqual(1, arrayMethod.GetCount(new int[] { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2 })); Assert.AreEqual(-1, arrayMethod.GetCount(new int[] { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 })); Assert.AreEqual(0, arrayMethod.GetCount(new int[] { 2 })); Assert.AreEqual(4, arrayMethod.GetCount(new int[] { 2, 6 })); Assert.AreNotEqual(0, arrayMethod.GetCount(new int[] { 1, 5 })); }
private ArrayMethodILEmitter(ArrayMethod method) { Debug.Assert(method.Kind != ArrayMethodKind.Address, "Should be " + nameof(ArrayMethodKind.AddressWithHiddenArg)); _method = method; ArrayType arrayType = (ArrayType)method.OwningType; _rank = arrayType.Rank; _elementType = arrayType.ElementType; _emitter = new ILEmitter(); // This helper field is needed to generate proper GC tracking. There is no direct way // to create interior pointer. _helperFieldToken = _emitter.NewToken(_method.Context.GetWellKnownType(WellKnownType.Object).GetKnownField("m_pEEType")); }
/// <summary> /// The main. /// </summary> /// <param name="args"> /// The args. /// </param> private static void Main(string[] args) { // array 常用类库的练习 ArrayMethod.ArrayMethodTest(); /* * 数组 Array * 优势, 查询效率 高, 增,删,改 慢 */ // 创建容量为10 的数组 var arr1 = new int[] { 1, 2, 4, 8, 3 }; arr1.ArrMsort(); // 赋值 Console.WriteLine(arr1.ArrToString()); Console.ReadLine(); // 查 时间 O(1) var a1 = arr1[0]; // 末尾添加 (时间O(1)) 如果数组已经满了,出错:数组下标越界 arr1.Append(1); // 首部||中部添加 会将下标之后的值统一向后面移动 var num = 0; for (int i = 0; i < arr1.Length - 1; i++) { num = arr1[i]; arr1[i] = arr1[i + 1]; } arr1[arr1.Length - 1] = num; var a = arr1.ArrToString(); Console.WriteLine(a); Console.ReadLine(); }
public static MethodIL EmitIL(ArrayMethod arrayMethod) { return(new ArrayMethodILEmitter(arrayMethod).EmitIL()); }