Exemple #1
0
        private static Type GetParentType(DocMethod rootMethod)
        {
            Type result = Type.GetType("StereoKit." + rootMethod.parent.name + ", StereoKit");

            if (result == null)
            {
                result = Type.GetType("StereoKit.Framework." + rootMethod.parent.name + ", StereoKit");
            }
            return(result);
        }
Exemple #2
0
        static void ReadMethod(string signature, XmlReader reader)
        {
            // Get names
            string[] segs           = signature.Split('(');
            string   nameSignature  = segs[0];
            string   paramSignature = segs.Length > 1?segs[1] :"";

            segs = nameSignature.Split('.');
            if (paramSignature.Length > 0)
            {
                paramSignature = paramSignature.Substring(0, paramSignature.Length - 1);
            }

            DocMethod method = methods.Find(a => a.name == segs[segs.Length - 1] && a.parent.name == segs[segs.Length - 2]);

            if (method == null)
            {
                method = new DocMethod(GetClass(segs[segs.Length - 2]), segs[segs.Length - 1]);
                methods.Add(method);
                items.Add(method);
            }

            DocMethodOverload variant = method.AddOverload(paramSignature);

            // Read properties
            while (reader.Read())
            {
                switch (reader.Name.ToLower())
                {
                case "summary": variant.summary = StringHelper.CleanMultiLine(reader.ReadElementContentAsString().Trim()); break;

                case "returns": variant.returns = StringHelper.CleanMultiLine(reader.ReadElementContentAsString().Trim()); break;

                case "param": {
                    DocParam p = new DocParam();
                    p.name    = reader.GetAttribute("name");
                    p.summary = reader.ReadElementContentAsString().Trim();
                    variant.parameters.Add(p);
                } break;

                case "inheritdoc": {
                    inheritMethods.Add(new DocInheritMethod(variant, reader.GetAttribute("cref")));
                } break;
                }
            }
        }
Exemple #3
0
        private static MethodBase GetMethodInfo(string signature, DocMethod rootMethod)
        {
            Type[] paramTypes = string.IsNullOrEmpty(signature) ? new Type[] { } : signature
            .Split(',')
            .AsEnumerable()
            .Select(a => {
                string cleanName = a.Replace("@", "");
                bool nullable    = a.Contains("System.Nullable");
                bool action      = a.Contains("System.Action{");
                bool array       = a.Contains("[]");
                if (nullable)
                {
                    int length = "System.Nullable{".Length;
                    cleanName  = cleanName.Substring(length, cleanName.Length - length - 1);
                }
                if (action)
                {
                    int length = "System.Action{".Length;
                    cleanName  = cleanName.Substring(length, cleanName.Length - length - 1);
                }
                if (array)
                {
                    cleanName = cleanName.Substring(0, cleanName.IndexOf("[]"));
                }

                Type t = Type.GetType(cleanName);
                if (t == null)
                {
                    t = Type.GetType(cleanName + ", StereoKit");
                }
                if (a.Contains("@"))
                {
                    t = t.MakeByRefType();
                }
                if (nullable)
                {
                    t = typeof(Nullable <>).MakeGenericType(t);
                }
                if (action)
                {
                    t = typeof(Action <>).MakeGenericType(t);
                }
                if (array)
                {
                    t = t.MakeArrayType();
                }

                return(t);
            })
            .ToArray();

            Type       parent = GetParentType(rootMethod);
            MethodBase result = rootMethod.name == "#ctor" ?
                                (MethodBase)parent.GetConstructor(paramTypes) :
                                (MethodBase)parent.GetMethod(rootMethod.name, paramTypes);

            if (result == null)
            {
                throw new Exception("Can't find info for method " + rootMethod.name);
            }
            return(result);
        }
Exemple #4
0
 public DocMethodOverload(DocMethod aRootMethod, string aSignature)
 {
     rootMethod = aRootMethod;
     signature  = aSignature;
     methodInfo = GetMethodInfo(signature, rootMethod);
 }
Exemple #5
0
 public DocMethodOverload(DocMethod aRootMethod, string aSignature)
 {
     rootMethod = aRootMethod;
     signature  = aSignature;
 }
        private static MethodBase GetMethodInfo(string signature, DocMethod rootMethod)
        {
            Type[] paramTypes = string.IsNullOrEmpty(signature) ? new Type[] { } : StringHelper.SeparateGroupedString(',', signature)
            .Select(a => {
                string cleanName = a.Replace("@", "");
                bool nullable    = a.Contains("System.Nullable");
                bool action      = a.Contains("System.Action{");
                bool array       = a.Contains("[]");
                bool generic     = a.Contains("`");
                if (nullable)
                {
                    int length = "System.Nullable{".Length;
                    cleanName  = cleanName.Substring(length, cleanName.Length - length - 1);
                }
                if (action)
                {
                    int length = "System.Action{".Length;
                    cleanName  = cleanName.Substring(length, cleanName.Length - length - 1);
                }
                if (array)
                {
                    cleanName = cleanName.Substring(0, cleanName.IndexOf("[]"));
                }

                int commas = cleanName.Count(c => c == ',');
                Type t     = null;
                if (t == null && action && commas == 0)
                {
                    t = typeof(Action <>).MakeGenericType(Type.GetType(cleanName));
                }
                if (t == null && action && commas == 1)
                {
                    t = typeof(Action <,>).MakeGenericType(cleanName.Split(',').Select(n => Type.GetType(n)).ToArray());
                }
                if (t == null && action && commas == 2)
                {
                    t = typeof(Action <, ,>).MakeGenericType(cleanName.Split(',').Select(n => Type.GetType(n)).ToArray());
                }
                if (t == null)
                {
                    t = Type.GetType(cleanName);
                }
                if (t == null)
                {
                    t = Type.GetType(cleanName + ", StereoKit");
                }
                if (t == null)
                {
                    t = Type.GetType(cleanName + ", " + typeof(System.Numerics.Vector3).Assembly.FullName);
                }
                if (t != null && nullable)
                {
                    t = typeof(Nullable <>).MakeGenericType(t);
                }
                if (t != null && array)
                {
                    t = t.MakeArrayType();
                }
                if (t != null && a.Contains("@"))
                {
                    t = t.MakeByRefType();
                }
                if (t == null && generic)
                {
                    t = typeof(object);
                }

                if (t == null)
                {
                    throw new Exception($"Can't find {rootMethod.Name}'s parameter type: {a}!");
                }
                return(t);
            })
            .ToArray();

            Type       parent = GetParentType(rootMethod);
            MethodBase result = rootMethod.name == "#ctor" ?
                                (MethodBase)parent.GetConstructor(paramTypes) :
                                (MethodBase)parent.GetMethod(rootMethod.name, paramTypes);

            // If it's generic, but there's no overloads, we can just return
            // the only method present
            if (result == null && rootMethod.name != "#ctor" && paramTypes.Contains(typeof(object)) && parent.GetMethods().Where(m => m.Name == rootMethod.name).Count() == 1)
            {
                result = parent.GetMethod(rootMethod.name);
            }

            if (result == null)
            {
                throw new Exception("Can't find info for method " + rootMethod.name);
            }
            return(result);
        }