Пример #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, IValueConverter valueConverter)
        {
            MethodDescription methDescription = new MethodDescription(data);

            //else Result is Converted to JSON
            System.Reflection.ParameterInfo[] paramsInfo = data.MethodInfo.GetParameters();
            for (int i = 0; i < paramsInfo.Length; ++i)
            {
                ParamMetadata param = ParamMetadata.FromParamInfo(paramsInfo[i], valueConverter);
                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, IValueConverter valueConverter)
        {
            Type ptype = pinfo.ParameterType;

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

            ParamMetadata paramInfo = new ParamMetadata
            {
                isNullable = ptype.IsNullableType(),
                name       = pinfo.Name
            };

            paramInfo.SetParameterType(ptype);
            Type realType = paramInfo.isNullable ? Nullable.GetUnderlyingType(ptype) : ptype;

            IDateConversionData dateConvert = (IDateConversionData)pinfo.GetCustomAttributes(false).FirstOrDefault(a => a is IDateConversionData);

            if (dateConvert != null)
            {
                paramInfo.dateConversion = dateConvert.DateConversion;
            }

            paramInfo.isArray = realType.IsArrayType();
            try
            {
                paramInfo.dataType = valueConverter.DataTypeFromType(realType);
            }
            catch (UnsupportedTypeException)
            {
                paramInfo.dataType = DataType.None;
            }

            return(paramInfo);
        }
Пример #3
0
 public static Type GetParameterType(this ParamMetadata param)
 {
     return(param._ParameterType);
 }
Пример #4
0
 public static void SetParameterType(this ParamMetadata param, Type type)
 {
     param._ParameterType = type;
 }