private object InvokeInternal(object target, object[] args, bool getValue) { IGetProxyTarget getProxyTarget = target as IGetProxyTarget; if (getProxyTarget != null) { target = getProxyTarget.GetTarget(); } MethodInfo methodInfo = getValue ? this.m_property.GetGetMethod(true) : this.m_property.GetSetMethod(true); if (methodInfo == null) { throw new ArgumentException(Environment.GetResourceString(getValue ? "Arg_GetMethNotFnd" : "Arg_SetMethNotFnd")); } if (!methodInfo.IsPublic) { throw new MethodAccessException(string.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_MethodAccessException_WithMethodName"), methodInfo.ToString(), methodInfo.DeclaringType.FullName)); } RuntimeMethodInfo runtimeMethodInfo = methodInfo as RuntimeMethodInfo; if (runtimeMethodInfo == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo")); } return(runtimeMethodInfo.UnsafeInvoke(target, BindingFlags.Default, null, args, null)); }
internal static ICustomProperty CreateIndexedProperty(object target, string propertyName, Type indexedParamType) { Debug.Assert(target != null); Debug.Assert(propertyName != null); IGetProxyTarget proxy = target as IGetProxyTarget; if (proxy != null) { target = proxy.GetTarget(); } // Only return public instance/static properties PropertyInfo propertyInfo = target.GetType().GetProperty( propertyName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public, null, // default binder null, // ignore return type new Type[] { indexedParamType }, // indexed parameter type null // ignore type modifier ); if (propertyInfo == null) { return(null); } else { return(new CustomPropertyImpl(propertyInfo)); } }
// // Creates a ICustomProperty implementation for Jupiter // Called from ICustomPropertyProvider_GetProperty from within runtime // internal static ICustomProperty CreateProperty(object target, string propertyName) { Debug.Assert(target != null); Debug.Assert(propertyName != null); IGetProxyTarget proxy = target as IGetProxyTarget; if (proxy != null) { target = proxy.GetTarget(); } // Only return public instance/static properties PropertyInfo propertyInfo = target.GetType().GetProperty( propertyName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public); if (propertyInfo == null) { return(null); } else { return(new CustomPropertyImpl(propertyInfo)); } }
internal static unsafe void GetType(object target, TypeNameNative *pIndexedParamType) { IGetProxyTarget proxy = target as IGetProxyTarget; if (proxy != null) { target = proxy.GetTarget(); } SystemTypeMarshaler.ConvertToNative(target.GetType(), pIndexedParamType); }
private object InvokeInternal(object target, object[] args, bool getValue) { // Forward to the right object if we are dealing with a proxy IGetProxyTarget proxy = target as IGetProxyTarget; if (proxy != null) { target = proxy.GetTarget(); } // You can get PropertyInfo for properties with a private getter/public setter (or vice versa) // even if you pass BindingFlags.Public only. And in this case, passing binding flags to // GetValue/SetValue won't work as the default binder ignores those values // Use GetGetMethod/GetSetMethod instead // We get non-public accessors just so that we can throw the correct exception. MethodInfo accessor = getValue ? m_property.GetGetMethod(true) : m_property.GetSetMethod(true); if (accessor == null) { throw new ArgumentException(System.Environment.GetResourceString(getValue ? "Arg_GetMethNotFnd" : "Arg_SetMethNotFnd")); } if (!accessor.IsPublic) { throw new MethodAccessException( String.Format( CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_MethodAccessException_WithMethodName"), accessor.ToString(), accessor.DeclaringType.FullName)); } RuntimeMethodInfo rtMethod = accessor as RuntimeMethodInfo; if (rtMethod == null) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo")); } // We can safely skip access check because this is only used in full trust scenarios. // And we have already verified that the property accessor is public. Contract.Assert(AppDomain.CurrentDomain.PermissionSet.IsUnrestricted()); return(rtMethod.UnsafeInvoke(target, BindingFlags.Default, null, args, null)); }
internal static string ToString(object obj) { IGetProxyTarget proxy = obj as IGetProxyTarget; if (proxy != null) { obj = proxy.GetTarget(); } // Check whether the type implements IStringable. IStringable stringableType = obj as IStringable; if (stringableType != null) { return(stringableType.ToString()); } return(obj.ToString()); }
private object InvokeInternal(object target, object[] args, bool getValue) { IGetProxyTarget getProxyTarget = target as IGetProxyTarget; if (getProxyTarget != null) { target = getProxyTarget.GetTarget(); } MethodInfo methodInfo = getValue ? this.m_property.GetGetMethod(true) : this.m_property.GetSetMethod(true); if (methodInfo == (MethodInfo)null) { throw new ArgumentException(Environment.GetResourceString(getValue ? "Arg_GetMethNotFnd" : "Arg_SetMethNotFnd")); } if (!methodInfo.IsPublic) { throw new MethodAccessException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, Environment.GetResourceString("Arg_MethodAccessException_WithMethodName"), (object)methodInfo.ToString(), (object)methodInfo.DeclaringType.FullName)); } RuntimeMethodInfo runtimeMethodInfo = methodInfo as RuntimeMethodInfo; // ISSUE: variable of the null type __Null local1 = null; if ((MethodInfo)runtimeMethodInfo == (MethodInfo)local1) { throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo")); } object obj = target; int num = 0; // ISSUE: variable of the null type __Null local2 = null; object[] parameters = args; // ISSUE: variable of the null type __Null local3 = null; return(runtimeMethodInfo.UnsafeInvoke(obj, (BindingFlags)num, (Binder)local2, parameters, (CultureInfo)local3)); }