Ejemplo n.º 1
0
        public ProxyType(Type type)
        {
            var envTypes = new List<Type>();
            var methods =
                (from method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public)
               .Where(method => Attribute.IsDefined(method, typeof(ServiceMethodAttribute)))
                 select new
                 {
                     MethodName = method.Name,
                     ServiceAttribute = (ServiceMethodAttribute)Attribute.GetCustomAttribute(method, typeof(ServiceMethodAttribute))
                 }).ToArray();

            var mappings = (from m in methods select new
                {
                  MethodName = m.MethodName,
                  Action = m.ServiceAttribute.Action,
                  ArgsTypeIndex = AddOrGetIndexOfExistingType(envTypes, m.ServiceAttribute.ArgType),
                  ResultsTypeIndex = AddOrGetIndexOfExistingType(envTypes, m.ServiceAttribute.ReturnType)
                }).ToArray();

            var xmlRoot = new XmlRootAttribute("Command");
            var envSerializers = envTypes.ConvertAll<XmlSerializer>(t => new XmlSerializer(t, xmlRoot));
            foreach (var m in mappings)
            {
                var svcMethod = new ServiceMethodInfo()
                {
                    MethodName = m.MethodName,
                    ServiceAction = m.Action,
                    ArgsSerializer = envSerializers[m.ArgsTypeIndex],
                    ResultsSerializer = envSerializers[m.ResultsTypeIndex]
                };
                _methods.Add(svcMethod.MethodName, svcMethod);
            }
        }
Ejemplo n.º 2
0
 public MessageSerializer(ServiceMethodInfo method)
 {
     if (method == null)
         throw new ArgumentNullException("method");
     _method = method;
 }