/// <summary> /// Initialize a new instance of the <see cref="ParameterDescriptor"/> class. /// </summary> /// <param name="methodDescriptor">The parent <see cref="MethodDescriptor"/>.</param> /// <param name="parameterInfo">The <see cref="ParameterInfo"/> to wrap.</param> internal ParameterDescriptor(MethodDescriptor methodDescriptor, ParameterInfo parameterInfo) : base(parameterInfo.ParameterType, parameterInfo.Name) { if (parameterInfo.IsOutParam()) { var memberInfo = parameterInfo.Member; var declaringType = memberInfo.DeclaringType; throw new ArgumentException(string.Format("Cannot apply rules to an 'out' parameter. Type = '{0}'. Method = '{1}'. Parameter = '{2}'", declaringType.ToUserFriendlyString(), memberInfo.Name, parameterInfo.Name), "parameterInfo"); } Position = parameterInfo.Position; Method = methodDescriptor; AddRulesForParameterInfo(parameterInfo); }
/// <summary> /// Get a <see cref="MethodDescriptor"/> for a <see cref="RuntimeTypeHandle"/>. /// </summary> /// <param name="runtimeMethodHandle">The <see cref="RuntimeTypeHandle"/> for which to get the <see cref="MethodDescriptor"/>.</param> /// <returns>A <see cref="MethodDescriptor"/> corresponding to <paramref name="runtimeMethodHandle"/>.</returns> public static MethodDescriptor GetMethod(RuntimeMethodHandle runtimeMethodHandle) { MethodDescriptor methodDescriptor; var success = methodCache.TryGetValue(runtimeMethodHandle, out methodDescriptor); if (!success) { lock (methodCacheDictionaryLock) { if (!methodCache.TryGetValue(runtimeMethodHandle, out methodDescriptor)) { methodDescriptor = new MethodDescriptor(runtimeMethodHandle); methodCache.Add(runtimeMethodHandle, methodDescriptor); } } } return methodDescriptor; }