Exemplo n.º 1
1
        public static MetadataPlainObjects.Fields Generate(MappingRule mappingRule, ApiDescription apiDescription, object originalObject)
        {
            var fromBodyParameterType = (from param in mappingRule.MethodExpression.Method.GetParameters()
                let fromBodyAttr = param.GetCustomAttribute<FromBodyAttribute>()
                where fromBodyAttr != null
                select param.ParameterType).FirstOrDefault();

            if (fromBodyParameterType == null)
                return GenerateFromGet(mappingRule, apiDescription, originalObject);

            var result = new MetadataPlainObjects.Fields();
            result.AddRange(from property in fromBodyParameterType.GetProperties()
                let fieldName = GetFieldName(property)
                let propVal = property.GetValue(originalObject)
                let jsonIgnore = property.GetCustomAttribute<JsonIgnoreAttribute>()
                where jsonIgnore == null
                select new MetadataPlainObjects.Field
                {
                    FieldName = fieldName,
                    FieldType = GetFieldType(property),
                    FieldValue = propVal == null ? null : propVal.ToString()
                });

            return result;
        }
Exemplo n.º 2
0
        private static MetadataPlainObjects.Fields GenerateFromGet(MappingRule mappingRule, ApiDescription apiDescription,
                                                                   object originalObject)
        {
            if (apiDescription.HttpMethod != HttpMethod.Get)
            {
                return(null);
            }

            var result = new MetadataPlainObjects.Fields();

            int argumentCounter = 0;

            result.AddRange(
                from parameter in mappingRule.MethodExpression.Method.GetParameters()
                let isMemberExpression = mappingRule.MethodExpression.Arguments[argumentCounter++] is MemberExpression
                                         where mappingRule.ParameterDelegates.ContainsKey(parameter.Name)
                                         let paramDelegate = mappingRule.ParameterDelegates.ContainsKey(parameter.Name) ? mappingRule.ParameterDelegates[parameter.Name] : null
                                                             select new MetadataPlainObjects.Field
            {
                FieldName  = parameter.Name,
                FieldValue = (isMemberExpression && paramDelegate != null) ? paramDelegate.DynamicInvoke(originalObject).ToString() : null
            });

            return(result);
        }
Exemplo n.º 3
0
        public static MetadataPlainObjects.Fields Generate(MappingRule mappingRule, ApiDescription apiDescription, object originalObject)
        {
            var fromBodyParameterType = (from param in mappingRule.MethodExpression.Method.GetParameters()
                                         let fromBodyAttr = param.GetCustomAttribute <FromBodyAttribute>()
                                                            where fromBodyAttr != null
                                                            select param.ParameterType).FirstOrDefault();

            if (fromBodyParameterType == null)
            {
                return(GenerateFromGet(mappingRule, apiDescription, originalObject));
            }

            var result = new MetadataPlainObjects.Fields();

            result.AddRange(from property in fromBodyParameterType.GetProperties()
                            let fieldName = GetFieldName(property)
                                            let propVal = property.GetValue(originalObject)
                                                          let jsonIgnore = property.GetCustomAttribute <JsonIgnoreAttribute>()
                                                                           where jsonIgnore == null
                                                                           select new MetadataPlainObjects.Field
            {
                FieldName  = fieldName,
                FieldType  = GetFieldType(property),
                FieldValue = propVal == null ? null : propVal.ToString()
            });


            return(result);
        }
Exemplo n.º 4
0
        private static MetadataPlainObjects.Fields GenerateFromGet(MappingRule mappingRule, ApiDescription apiDescription,
            object originalObject)
        {
            if (apiDescription.HttpMethod != HttpMethod.Get)
                return null;

            var result = new MetadataPlainObjects.Fields();

            int argumentCounter = 0;
            result.AddRange(
                from parameter in mappingRule.MethodExpression.Method.GetParameters()
                let isMemberExpression = mappingRule.MethodExpression.Arguments[argumentCounter++] is MemberExpression
                where mappingRule.ParameterDelegates.ContainsKey(parameter.Name)
                let paramDelegate = mappingRule.ParameterDelegates.ContainsKey(parameter.Name) ? mappingRule.ParameterDelegates[parameter.Name] : null
                select new MetadataPlainObjects.Field
                {
                    FieldName = parameter.Name,
                    FieldValue = (isMemberExpression && paramDelegate != null) ? paramDelegate.DynamicInvoke(originalObject).ToString() : null
                });

            return result;
        }