Exemplo n.º 1
0
        internal static int GetTypeRecursive(Type t)
        {
            JObject jo = new JObject();

            jo.Add("__name", t.Name.ToLower());
            if (isSimpleType(t))
            {
                return(SMD.AddType(jo));
            }

            var genArgs = t.GetGenericArguments();

            PropertyInfo[] properties = t.GetProperties();
            FieldInfo[]    fields     = t.GetFields();

            if (genArgs.Length > 0)
            {
                var ja = new JArray();
                foreach (var item in genArgs)
                {
                    if (item != t)
                    {
                        var jt = GetTypeRecursive(item);
                        ja.Add(jt);
                    }
                    else
                    {
                        // make a special case where -1 indicates this type
                        ja.Add(-1);
                    }
                }
                jo.Add("__genericArguments", ja);
            }

            foreach (var item in properties)
            {
                if (item.GetAccessors().Where(x => x.IsPublic).Count() > 0)
                {
                    if (item.PropertyType != t)
                    {
                        var jt = GetTypeRecursive(item.PropertyType);
                        jo.Add(item.Name, jt);
                    }
                    else
                    {
                        // make a special case where -1 indicates this type
                        jo.Add(item.Name, -1);
                    }
                }
            }

            foreach (var item in fields)
            {
                if (item.IsPublic)
                {
                    if (item.FieldType != t)
                    {
                        var jt = GetTypeRecursive(item.FieldType);
                        jo.Add(item.Name, jt);
                    }
                    else
                    {
                        // make a special case where -1 indicates this type
                        jo.Add(item.Name, -1);
                    }
                }
            }

            return(SMD.AddType(jo));
        }
Exemplo n.º 2
0
        internal static int GetTypeRecursive(Type t)
        {
            JObject jo = new JObject();

            jo.Add("__name", t.Name.ToLower());

            if (isSimpleType(t) || SMD.ContainsType(jo))
            {
                return(SMD.AddType(jo));
            }

            var retVal = SMD.AddType(jo);

            var genArgs = t.GetGenericArguments();

            PropertyInfo[] properties = t.GetProperties();
            FieldInfo[]    fields     = t.GetFields();

            if (genArgs.Length > 0)
            {
                var ja = new JArray();
                foreach (var item in genArgs)
                {
                    if (item != t)
                    {
                        var jt = GetTypeRecursive(item);
                        ja.Add(jt);
                    }
                    else
                    {
                        // make a special case where -1 indicates this type
                        ja.Add(-1);
                    }
                }
                jo.Add("__genericArguments", ja);
            }

            foreach (var item in properties)
            {
                if (item.GetAccessors().Where(x => x.IsPublic).Count() > 0)
                {
                    if (item.PropertyType != t)
                    {
                        var             jt             = GetTypeRecursive(item.PropertyType);
                        ParameterInfo[] parameterInfos = item.GetIndexParameters();
                        if (parameterInfos?.Length > 0)
                        {
                            string name = item.Name + "[";
                            for (int i = 0; i < parameterInfos.Length; i++)
                            {
                                name += parameterInfos[i].ParameterType.Name;
                                if (i != parameterInfos.Length - 1)
                                {
                                    name += ",";
                                }
                            }
                            name += "]";
                            jo.Add(name, jt);
                        }
                        else
                        {
                            jo.Add(item.Name, jt);
                        }
                    }
                    else
                    {
                        // make a special case where -1 indicates this type
                        jo.Add(item.Name, -1);
                    }
                }
            }

            foreach (var item in fields)
            {
                if (item.IsPublic)
                {
                    if (item.FieldType != t)
                    {
                        var jt = GetTypeRecursive(item.FieldType);
                        jo.Add(item.Name, jt);
                    }
                    else
                    {
                        // make a special case where -1 indicates this type
                        jo.Add(item.Name, -1);
                    }
                }
            }

            return(retVal);
        }