Exemplo n.º 1
0
        /// <summary>
        /// Registers type
        /// </summary>
        /// <param name="t"></param>
        /// <returns>registered type name</returns>
        public string RegisterType(Type t)
        {
            bool   isArray      = t.IsArray;
            bool   isEnumerable = false;
            bool   isEnum       = false;
            string result       = "any";

            try
            {
                if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                {
                    t            = t.GetGenericArguments().First();
                    isEnumerable = true;
                }
                else if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List <>))
                {
                    t            = t.GetGenericArguments().First();
                    isEnumerable = true;
                }
                else if (isArray)
                {
                    isEnumerable = true;
                    t            = t.GetElementType();
                }
                else if (t != typeof(string) && typeof(IEnumerable).IsAssignableFrom(t))
                {
                    isEnumerable = true;
                    return("any[]");
                }
                else if (t == typeof(object))
                {
                    return("any");
                }

                if (t.IsEnum)
                {
                    isEnum = true;
                }

                DataType dtype = _valueConverter.DataTypeFromType(t);
                result = DataTypeToTypeName(dtype);

                if (isArray || isEnumerable)
                {
                    result = string.Format("{0}[]", result);
                }

                return(result);
            }
            catch (UnsupportedTypeException)
            {
                //complex type
                return(RegisterComplexType(t, isArray, isEnumerable, isEnum));
            }
        }
Exemplo n.º 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);
        }