Beispiel #1
0
        public static byte[] GetServerModel(Type serverType, bool ModelValidation, out int Hash)
        {
            string[]        Ignore          = new string[] { "Equals", "GetHashCode", "GetType", "ToString" };
            SoupClientModel soupClientModel = new SoupClientModel(serverType.Name);

            foreach (MethodInfo method in serverType.GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                if (!Ignore.Contains(method.Name))
                {
                    CheckType(ref soupClientModel, method.ReturnType);
                    bool       Post       = method.GetCustomAttribute <Post>() != null;
                    bool       ReturnCode = method.GetCustomAttribute <ReturnCode>() != null;
                    SoupMethod Method     = new SoupMethod(method.Name, method.ReturnType.GetFriendlyName(), Post, ReturnCode);

                    foreach (ParameterInfo parameter in method.GetParameters())
                    {
                        CheckType(ref soupClientModel, parameter.ParameterType);
                        Method.MethodParameters.Add(new SoupParamProp(parameter.Name, parameter.ParameterType.GetFriendlyName()));
                    }

                    soupClientModel.Methods.Add(Method);
                }
            }
            Hash = soupClientModel.GetHashCode();
            soupClientModel.Hash = Hash;
            soupClientModel.HashParameterName = HashParameterName;
            soupClientModel.ModelValidation   = ModelValidation;
            return(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(soupClientModel)));
        }
Beispiel #2
0
 static void CheckType(ref SoupClientModel model, Type t)
 {
     if (!IsSystemType(t) && !model.Types.Any(x => x.Name == t.Name))
     {
         SoupType type = new SoupType(t.Name);
         foreach (PropertyInfo property in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
         {
             CheckType(ref model, property.PropertyType);
             type.Properties.Add(new SoupParamProp(property.Name, property.PropertyType.GetFriendlyName()));
         }
         model.Types.Add(type);
     }
 }