/// <summary> /// Initializes a new instance of the DomainOperationEntry class /// </summary> /// <param name="domainServiceType">The <see cref="DomainService"/> Type this operation is a member of.</param> /// <param name="name">The name of the operation</param> /// <param name="operation">The <see cref="DomainOperation"/></param> /// <param name="returnType">The return Type of the operation</param> /// <param name="parameters">The parameter definitions for the operation</param> /// <param name="attributes">The method level attributes for the operation</param> protected DomainOperationEntry(Type domainServiceType, string name, DomainOperation operation, Type returnType, IEnumerable <DomainOperationParameter> parameters, AttributeCollection attributes) { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (returnType == null) { throw new ArgumentNullException(nameof(returnType)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } if (attributes == null) { throw new ArgumentNullException(nameof(attributes)); } if (domainServiceType == null) { throw new ArgumentNullException(nameof(domainServiceType)); } if (operation == DomainOperation.None) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resource.InvalidDomainOperationEntryType, Enum.GetName(typeof(DomainOperation), operation))); } bool isTaskType = TypeUtility.IsTaskType(returnType); this._methodName = isTaskType ? RemoveAsyncFromName(name) : name; this._actualReturnType = returnType; this.ReturnType = isTaskType ? TypeUtility.GetTaskReturnType(returnType) : returnType; this._attributes = attributes; this.Operation = operation; this._domainServiceType = domainServiceType; List <DomainOperationParameter> effectiveParameters = parameters.ToList(); int paramCount = effectiveParameters.Count; if (paramCount > 0) { DomainOperationParameter lastParameter = effectiveParameters[paramCount - 1]; if (lastParameter.IsOut && lastParameter.ParameterType.HasElementType && lastParameter.ParameterType.GetElementType() == typeof(int)) { this.HasOutCountParameter = true; effectiveParameters = effectiveParameters.Take(paramCount - 1).ToList(); } } this.Parameters = effectiveParameters.AsReadOnly(); }
private static IEnumerable <DomainOperationParameter> GetMethodParameters(MethodInfo methodInfo) { ParameterInfo[] actualParameters = methodInfo.GetParameters(); List <DomainOperationParameter> parameters = new List <DomainOperationParameter>(); foreach (ParameterInfo parameterInfo in actualParameters) { bool isOut = parameterInfo.IsOut && parameterInfo.ParameterType.HasElementType; DomainOperationParameter parameter = new DomainOperationParameter( parameterInfo.Name, parameterInfo.ParameterType, new AttributeCollection(parameterInfo.GetCustomAttributes(true).Cast <Attribute>().ToArray()), isOut); parameters.Add(parameter); } return(parameters); }
/// <summary> /// Checks whether a parameter expects a value to be passed by-value. /// </summary> /// <param name="parameter">The parameter to check.</param> /// <returns>True if the parameter expects a by-value value.</returns> private static bool IsByVal(DomainOperationParameter parameter) { return !parameter.IsOut && !parameter.ParameterType.IsByRef; }
private static IEnumerable<DomainOperationParameter> GetMethodParameters(MethodInfo methodInfo) { ParameterInfo[] actualParameters = methodInfo.GetParameters(); List<DomainOperationParameter> parameters = new List<DomainOperationParameter>(); foreach (ParameterInfo parameterInfo in actualParameters) { bool isOut = parameterInfo.IsOut && parameterInfo.ParameterType.HasElementType; DomainOperationParameter parameter = new DomainOperationParameter( parameterInfo.Name, parameterInfo.ParameterType, new AttributeCollection(parameterInfo.GetCustomAttributes(true).Cast<Attribute>().ToArray()), isOut); parameters.Add(parameter); } return parameters; }