Пример #1
0
        /// <summary>
        ///     Generates Data Services' method description which is convertable to JSON
        ///     and can be consumed by clients
        /// </summary>
        public static MethodDescription FromMethodInfo(MethodInfoData data, IServiceContainer container)
        {
            var methDescription = new MethodDescription(data);
            //else Result is Converted to JSON
            var paramsInfo = data.methodInfo.GetParameters();

            for (var i = 0; i < paramsInfo.Length; ++i)
            {
                var param = ParamMetadata.FromParamInfo(paramsInfo[i], container);
                param.ordinal = i;
                methDescription.parameters.Add(param);
            }
            return(methDescription);
        }
Пример #2
0
        /// <summary>
        ///     Extracts from ParameterInfo all information about method parameter
        /// </summary>
        /// <returns>ParamMetadataInfo</returns>
        public static ParamMetadata FromParamInfo(ParameterInfo pinfo, IServiceContainer container)
        {
            var ptype = pinfo.ParameterType;

            if (pinfo.IsOut)
            {
                throw new DomainServiceException("Out parameters are not supported in service methods");
            }
            var paramInfo = new ParamMetadata();

            paramInfo.isNullable    = container.ValueConverter.IsNullableType(ptype);
            paramInfo.name          = pinfo.Name;
            paramInfo.ParameterType = ptype;
            Type realType = null;

            if (!paramInfo.isNullable)
            {
                realType = ptype;
            }
            else
            {
                realType = Nullable.GetUnderlyingType(ptype);
            }
            var dtops = pinfo.GetCustomAttributes(typeof(DateOptionAttribute), false);

            if (dtops.Length > 0)
            {
                paramInfo.dateConversion = (dtops[0] as DateOptionAttribute).dateConversion;
            }
            var isArray = false;

            try
            {
                paramInfo.dataType = container.ValueConverter.DataTypeFromType(realType, out isArray);
            }
            catch (UnsupportedTypeException)
            {
                paramInfo.dataType = DataType.None;
            }
            paramInfo.isArray = isArray;
            return(paramInfo);
        }