private static object ConvertLoopElement(string ElementName, object Value, Type SourceType, Type TargetType) { object obj2; try { obj2 = Conversions.ChangeType(Value, TargetType); } catch (AccessViolationException exception) { throw exception; } catch (StackOverflowException exception2) { throw exception2; } catch (OutOfMemoryException exception3) { throw exception3; } catch (ThreadAbortException exception4) { throw exception4; } catch (Exception) { throw new ArgumentException(Utils.GetResourceString("ForLoop_ConvertToType3", new string[] { ElementName, Utils.VBFriendlyName(SourceType), Utils.VBFriendlyName(TargetType) })); } return(obj2); }
internal void SetFieldValue(FieldInfo Field, object Value) { if (Field.IsInitOnly) { throw new MissingMemberException(Utils.GetResourceString("MissingMember_ReadOnlyField2", new string[] { Field.Name, this.VBFriendlyName })); } if ((this.m_Instance == null) && !Symbols.IsShared(Field)) { throw new NullReferenceException(Utils.GetResourceString("NullReference_InstanceReqToAccessMember1", new string[] { Utils.FieldToString(Field) })); } if (Symbols.IsNonPublicRuntimeMember(Field)) { throw new MissingMemberException(); } Field.SetValue(this.m_Instance, Conversions.ChangeType(Value, Field.FieldType)); }
internal void SetArrayValue(object[] Arguments) { Array instance = (Array)this.m_Instance; int rank = instance.Rank; if ((Arguments.Length - 1) != rank) { throw new RankException(); } object expression = Arguments[Arguments.Length - 1]; Type elementType = this.m_Type.GetElementType(); int index = (int)Conversions.ChangeType(Arguments[0], typeof(int)); if (rank == 1) { instance.SetValue(Conversions.ChangeType(expression, elementType), index); } else { int num3 = (int)Conversions.ChangeType(Arguments[1], typeof(int)); if (rank == 2) { instance.SetValue(Conversions.ChangeType(expression, elementType), new int[] { index, num3 }); } else { int num4 = (int)Conversions.ChangeType(Arguments[2], typeof(int)); if (rank == 3) { instance.SetValue(Conversions.ChangeType(expression, elementType), new int[] { index, num3, num4 }); } else { int[] indices = new int[(rank - 1) + 1]; indices[0] = index; indices[1] = num3; indices[2] = num4; int num6 = rank - 1; for (int i = 3; i <= num6; i++) { indices[i] = (int)Conversions.ChangeType(Arguments[i], typeof(int)); } instance.SetValue(Conversions.ChangeType(expression, elementType), indices); } } } }
internal object GetArrayValue(object[] Indices) { Array instance = (Array)this.m_Instance; int rank = instance.Rank; if (Indices.Length != rank) { throw new RankException(); } int index = (int)Conversions.ChangeType(Indices[0], typeof(int)); if (rank == 1) { return(instance.GetValue(index)); } int num3 = (int)Conversions.ChangeType(Indices[1], typeof(int)); if (rank == 2) { return(instance.GetValue(new int[] { index, num3 })); } int num4 = (int)Conversions.ChangeType(Indices[2], typeof(int)); if (rank == 3) { return(instance.GetValue(new int[] { index, num3, num4 })); } int[] indices = new int[(rank - 1) + 1]; indices[0] = index; indices[1] = num3; indices[2] = num4; int num6 = rank - 1; for (int i = 3; i <= num6; i++) { indices[i] = (int)Conversions.ChangeType(Indices[i], typeof(int)); } return(instance.GetValue(indices)); }
public static bool ForNextCheckObj(object Counter, object LoopObj, ref object CounterResult) { if (LoopObj == null) { throw ExceptionUtils.VbMakeException(0x5c); } if (Counter == null) { throw new NullReferenceException(Utils.GetResourceString("Argument_InvalidNullValue1", new string[] { "Counter" })); } ObjectFlowControl.ForLoopControl loopFor = (ObjectFlowControl.ForLoopControl)LoopObj; bool flag2 = false; if (!loopFor.UseUserDefinedOperators) { TypeCode typeCode = ((IConvertible)Counter).GetTypeCode(); if ((typeCode != loopFor.WidestTypeCode) || (typeCode == TypeCode.String)) { if (typeCode == TypeCode.Object) { throw new ArgumentException(Utils.GetResourceString("ForLoop_CommonType2", new string[] { Utils.VBFriendlyName(Symbols.MapTypeCodeToType(typeCode)), Utils.VBFriendlyName(loopFor.WidestType) })); } TypeCode code2 = Symbols.GetTypeCode(GetWidestType(Symbols.MapTypeCodeToType(typeCode), loopFor.WidestType)); if (code2 == TypeCode.String) { code2 = TypeCode.Double; } loopFor.WidestTypeCode = code2; loopFor.WidestType = Symbols.MapTypeCodeToType(code2); flag2 = true; } } if (flag2 || loopFor.UseUserDefinedOperators) { Counter = ConvertLoopElement("Start", Counter, Counter.GetType(), loopFor.WidestType); if (!loopFor.UseUserDefinedOperators) { loopFor.Limit = ConvertLoopElement("Limit", loopFor.Limit, loopFor.Limit.GetType(), loopFor.WidestType); loopFor.StepValue = ConvertLoopElement("Step", loopFor.StepValue, loopFor.StepValue.GetType(), loopFor.WidestType); } } if (!loopFor.UseUserDefinedOperators) { loopFor.Counter = Operators.AddObject(Counter, loopFor.StepValue); TypeCode code3 = ((IConvertible)loopFor.Counter).GetTypeCode(); if (loopFor.EnumType != null) { CounterResult = Enum.ToObject(loopFor.EnumType, loopFor.Counter); } else { CounterResult = loopFor.Counter; } if (code3 != loopFor.WidestTypeCode) { loopFor.Limit = Conversions.ChangeType(loopFor.Limit, Symbols.MapTypeCodeToType(code3)); loopFor.StepValue = Conversions.ChangeType(loopFor.StepValue, Symbols.MapTypeCodeToType(code3)); return(false); } } else { loopFor.Counter = Operators.InvokeUserDefinedOperator(loopFor.OperatorPlus, true, new object[] { Counter, loopFor.StepValue }); if (loopFor.Counter.GetType() != loopFor.WidestType) { loopFor.Counter = ConvertLoopElement("Start", loopFor.Counter, loopFor.Counter.GetType(), loopFor.WidestType); } CounterResult = loopFor.Counter; } return(CheckContinueLoop(loopFor)); }