/// <summary> /// Enumerates over the set of instances represented by the current step. /// </summary> /// <param name="instance"></param> /// <returns></returns> public IEnumerable <ModelInstance> GetInstances(ModelInstance instance) { // Exit immediately if the property is not valid for the specified instance if (!DeclaringType.IsInstanceOfType(instance)) { throw new ArgumentException("The current property is not valid for the specified instance."); } // Return each instance exposed by a list property if (IsList) { ModelInstanceList children = instance.GetList(this); if (children != null) { foreach (ModelInstance child in children) { yield return(child); } } } // Return the instance exposed by a reference property else { ModelInstance child = instance.GetReference(this); if (child != null) { yield return(child); } } }
internal void CheckConsistency(Object target) { // only test instance fields if ((Attributes & FieldAttributes.Static) != FieldAttributes.Static) { if (!DeclaringType.IsInstanceOfType(target)) { if (target == null) { #if FEATURE_LEGACYNETCF if (CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) { throw new ArgumentNullException(Environment.GetResourceString("RFLCT.Targ_StatFldReqTarg")); } else #endif throw new TargetException(Environment.GetResourceString("RFLCT.Targ_StatFldReqTarg")); } else { throw new ArgumentException( String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_FieldDeclTarget"), Name, DeclaringType, target.GetType())); } } } }
public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { if (!IsStatic) { if (!DeclaringType.IsInstanceOfType(obj)) { if (obj == null) { throw new TargetException("Non-static method requires a target."); } else { throw new TargetException("Object does not match target type."); } } } if (binder == null) { binder = Type.DefaultBinder; } /*Avoid allocating an array every time*/ ParameterInfo[] pinfo = GetParametersInternal(); ConvertValues(binder, parameters, pinfo, culture, invokeAttr); if (ContainsGenericParameters) { throw new InvalidOperationException("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true."); } Exception exc; object o = null; if ((invokeAttr & BindingFlags.DoNotWrapExceptions) == 0) { try { o = InternalInvoke(obj, parameters, out exc); } catch (ThreadAbortException) { throw; #if MOBILE } catch (MethodAccessException) { throw; #endif } catch (Exception e) { throw new TargetInvocationException(e); } } else { o = InternalInvoke(obj, parameters, out exc); } if (exc != null) { throw exc; } return(o); }
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture) { if (obj == null) { if (!IsStatic) throw new TargetException("Instance constructor requires a target"); } else if (!DeclaringType.IsInstanceOfType(obj)) { throw new TargetException("Constructor does not match target type"); } return DoInvoke(obj, invokeAttr, binder, parameters, culture); }
internal override void CheckConsistency(Object target) { // only test instance fields if ((Attributes & FieldAttributes.Static) != FieldAttributes.Static) { if (!DeclaringType.IsInstanceOfType(target)) { if (target == null) { throw new TargetException(Environment.GetResourceString("RFLCT.Targ_StatFldReqTarg")); } else { throw new ArgumentException( String.Format(CultureInfo.CurrentUICulture, Environment.GetResourceString("Arg_FieldDeclTarget"), Name, DeclaringType, target.GetType())); } } } }
ICorDebugValue GetCorValue(Value objectInstance) { if (objectInstance != null) { if (!DeclaringType.IsInstanceOfType(objectInstance)) { throw new CannotGetValueException("Object is not of type " + DeclaringType.FullName); } } // Current frame is used to resolve context specific static values (eg. ThreadStatic) ICorDebugFrame curFrame = null; if (this.Process.IsPaused && this.Process.SelectedThread != null && this.Process.SelectedThread.LastFunction != null && this.Process.SelectedThread.LastFunction.CorILFrame != null) { curFrame = this.Process.SelectedThread.LastFunction.CorILFrame.CastTo <ICorDebugFrame>(); } try { if (this.IsStatic) { return(DeclaringType.CorType.GetStaticFieldValue(MetadataToken, curFrame)); } else { return(objectInstance.CorObjectValue.GetFieldValue(DeclaringType.CorType.Class, MetadataToken)); } } catch (System.Exception e) { throw new CannotGetValueException(e.Message); } }
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture) { if (!IsStatic) { if (!DeclaringType.IsInstanceOfType(obj)) { if (obj == null) throw new TargetException("Non-static method requires a target."); else throw new TargetException("Object does not match target type."); } } if (binder == null) binder = Type.DefaultBinder; /*Avoid allocating an array every time*/ ParameterInfo[] pinfo = GetParametersInternal(); ConvertValues(binder, parameters, pinfo, culture, invokeAttr); if (ContainsGenericParameters) throw new InvalidOperationException("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true."); Exception? exc; object? o = null; if ((invokeAttr & BindingFlags.DoNotWrapExceptions) == 0) { try { o = InternalInvoke(obj, parameters, out exc); } catch (Mono.NullByRefReturnException) { throw new NullReferenceException(); } catch (OverflowException) { throw; } catch (Exception e) { throw new TargetInvocationException(e); } } else { try { o = InternalInvoke(obj, parameters, out exc); } catch (Mono.NullByRefReturnException) { throw new NullReferenceException(); } } if (exc != null) throw exc; return o; }