コード例 #1
0
ファイル: UnitTestCodeGen.cs プロジェクト: zhonli/odata.net
        /// <summary>Set property value on target; supports indexed properties.</summary>
        public static void InvokePropertySet(PropertyInfo propertyInfo, object target, params object[] parameterValues)
        {
            DelegateMethod method = GetSetProperty(propertyInfo);

            if (null == method)
            {
                ThrowMissingMethodException(propertyInfo.DeclaringType, propertyInfo.Name, Type.EmptyTypes, Type.EmptyTypes);
            }
            method.Method(target, parameterValues);
        }
コード例 #2
0
ファイル: UnitTestCodeGen.cs プロジェクト: zhonli/odata.net
        /// <summary>Invoke a method.</summary>
        public static object InvokeMethod(Type methodTarget, string memberName, Type[] parameterTypes, Type[] genericArguments, BindingFlags bindingFlags, object target, params object[] parameterValues)
        {
            if (null == memberName)
            {
                memberName = ".ctor";
            }
            if (null == parameterTypes)
            {
                parameterTypes = Type.EmptyTypes;
            }
            if (null == genericArguments)
            {
                genericArguments = Type.EmptyTypes;
            }
            if (null == parameterValues)
            {
                parameterValues = EmptyValues;
            }

#if TEST_FRAMEWORK
            if (parameterTypes.Length != parameterValues.Length)
            {   // so that parameter values can be derived
                if (".ctor" == memberName)
                {
                    bindingFlags |= BindingFlags.CreateInstance;
                }
                return(methodTarget.InvokeMember(memberName, bindingFlags, null, target, parameterValues));
            }
#else
            if (parameterTypes.Length != parameterTypes.Length)
            {
                ThrowTargetParameterCountException();
            }
#endif
            DelegateMethod method = GetMethod(methodTarget, memberName, parameterTypes, genericArguments);
            if (null == method)
            {
                ThrowMissingMethodException(methodTarget, memberName, parameterTypes, genericArguments);
            }
            return(method.Method(target, parameterValues));
        }