Пример #1
0
 public object GetValue(string name, MethodDescription methodDescription, IServiceContainer serviceContainer)
 {
     var par = this.parameters.Where(p => p.name == name).FirstOrDefault();
     if (par == null)
         return null;
     var paraminfo = methodDescription.parameters.Where(p => p.name == name).FirstOrDefault();
     if (paraminfo == null)
     {
         throw new DomainServiceException(string.Format("Method: {0} has no parameter with a name: {1}", methodDescription.methodName, name));
     }
     return serviceContainer.DataHelper.ParseParameter(paraminfo.ParameterType, paraminfo, paraminfo.isArray, par.value);
 }
Пример #2
0
        /// <summary>
        /// Generates Data Services' method description which is convertable to JSON
        /// and can be consumed by clients
        /// </summary>
        /// <param name="methodInfo"></param>
        /// <param name="isQuery"></param>
        /// <param name="dataHelper"></param>
        /// <returns></returns>
        public static MethodDescription FromMethodInfo(MethodInfo methodInfo, MethodType methodType, IServiceContainer container)
        {
            Type returnType = methodInfo.ReturnType;
            bool isVoid = returnType == typeof(void);
            MethodDescription methDescription = new MethodDescription();
            methDescription.methodInfo = methodInfo;
            methDescription.methodName = methodInfo.Name;
            methDescription.isQuery = methodType == MethodType.Query;

            if (!isVoid)
                methDescription.methodResult = true;
            //else Result is Converted to JSON
            ParameterInfo[] paramsInfo = methodInfo.GetParameters();
            for (var i = 0; i < paramsInfo.Length; ++i) {
                ParamMetadata param = ParamMetadata.FromParamInfo(paramsInfo[i], container);
                param.ordinal = i;
                methDescription.parameters.Add(param);
            }
            return methDescription;
        }