예제 #1
0
        private static void SetPublicProperties(Type type, object obj, Dictionary <Type, object> createdObjectReferences)
        {
            PropertyInfo[]  properties      = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            ObjectGenerator objectGenerator = new ObjectGenerator();

            foreach (PropertyInfo property in properties)
            {
                if (property.CanWrite)
                {
                    //object propertyValue = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences);
                    //property.SetValue(obj, propertyValue, null);
                    if (property.PropertyType == typeof(String))
                    {
                        try
                        {
                            XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
                            object     propertyValue = documentation["example"].InnerText.Trim();
                            property.SetValue(obj, propertyValue, null);
                        }
                        catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
                    }
                    else if (property.PropertyType == typeof(int))
                    {
                        try
                        {
                            XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
                            object     propertyValue = int.Parse(documentation["example"].InnerText.Trim());
                            property.SetValue(obj, propertyValue, null);
                        }
                        catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
                    }
                    else if (property.PropertyType == typeof(long))
                    {
                        try
                        {
                            XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
                            object     propertyValue = long.Parse(documentation["example"].InnerText.Trim());
                            property.SetValue(obj, propertyValue, null);
                        }
                        catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
                    }
                    else if (property.PropertyType == typeof(DateTime))
                    {
                        try
                        {
                            XmlElement documentation = DocsByReflection.XMLFromMember(type.GetProperty(property.Name));
                            object     propertyValue = DateTime.Parse(documentation["example"].InnerText.Trim());
                            property.SetValue(obj, propertyValue, null);
                        }
                        catch (Exception ex) { property.SetValue(obj, objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences), null); }
                    }
                    else
                    {
                        object propertyValue = objectGenerator.GenerateObject(property.PropertyType, createdObjectReferences);
                        property.SetValue(obj, propertyValue, null);
                    }
                }
            }
        }
예제 #2
0
        ///----------------------------------------------------------------------------------------------
        ///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Method"))
            {
                var menu = new UnityEditor.GenericMenu();
                if (agent != null)
                {
                    foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector))
                    {
                        menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 10, false, false, menu);
                    }
                    menu.AddSeparator("/");
                }
                foreach (var t in TypePrefs.GetPreferedTypesList(typeof(object)))
                {
                    menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, false, menu);
                    if (typeof(UnityEngine.Component).IsAssignableFrom(t))
                    {
                        menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 10, false, false, menu);
                    }
                }
                menu.ShowAsBrowser("Select Method", this.GetType());
                Event.current.Use();
            }


            if (targetMethod != null)
            {
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Method", targetMethod.Name);
                UnityEditor.EditorGUILayout.LabelField("Returns", targetMethod.ReturnType.FriendlyName());
                UnityEditor.EditorGUILayout.HelpBox(DocsByReflection.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);

                if (targetMethod.ReturnType == typeof(IEnumerator))
                {
                    GUILayout.Label("<b>This will execute as a Coroutine!</b>");
                }

                GUILayout.EndVertical();

                var paramNames = targetMethod.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
                for (var i = 0; i < paramNames.Length; i++)
                {
                    NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], parameters[i]);
                }

                if (targetMethod.ReturnType != typeof(void) && targetMethod.ReturnType != typeof(IEnumerator))
                {
                    NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", returnValue, true);
                }
            }
        }
예제 #3
0
        protected string GetDescription(MethodInfo method)
        {
            var description = method.GetCustomAttribute <DescriptionAttribute>()?.Description;

            if (string.IsNullOrEmpty(description))
            {
                XmlElement documentation = DocsByReflection.XMLFromMember(method);
                description = documentation?["summary"]?.InnerText.Trim();
                if (string.IsNullOrEmpty(description))
                {
                    description = method.Name.ToFriendlyName().Replace(" Async", "");
                }
            }

            return(description);
        }
예제 #4
0
        protected string GetDescription(Type service)
        {
            var description = service.GetCustomAttribute <DescriptionAttribute>()?.Description;

            if (string.IsNullOrEmpty(description))
            {
                XmlElement documentation = DocsByReflection.XMLFromType(service);
                description = documentation?["summary"]?.InnerText.Trim();
                if (string.IsNullOrEmpty(description))
                {
                    description = service.Name.ToFriendlyName();
                }
            }

            return(description);
        }
예제 #5
0
파일: Program.cs 프로젝트: rmueller/kayak
        static XmlElement GetXmlForMember(MemberInfo member)
        {
            if (xmlDocument == null)
            {
                xmlDocument = DocsByReflection.XMLFromAssembly(member.DeclaringType.Assembly);
            }

            string fullName = null;

            if (member is MethodInfo)
            {
                fullName = Jolt.Convert.ToXmlDocCommentMember(member as MethodInfo);
            }
            if (member is ConstructorInfo)
            {
                fullName = Jolt.Convert.ToXmlDocCommentMember(member as ConstructorInfo);
            }
            if (member is PropertyInfo)
            {
                fullName = Jolt.Convert.ToXmlDocCommentMember(member as PropertyInfo);
            }
            if (member is FieldInfo)
            {
                fullName = Jolt.Convert.ToXmlDocCommentMember(member as FieldInfo);
            }

            return(xmlDocument["doc"]["members"].Cast <XmlElement>()
                   .FirstOrDefault(e => {
                var name = e.Attributes["name"].Value;

                if (name.Equals(fullName))
                {
                    return true;
                }

                // HACK for:
                // public static IObservable<T> AsCoroutine<T>(this IEnumerable<object> iteratorBlock)
                var tickSplit = name.Split('`');
                return fullName.Contains(tickSplit.First()) && fullName.Contains(tickSplit.Last().TrimStart("1234567890".ToCharArray()));
            }));
        }
        ////////////////////////////////////////
        ///////////GUI AND EDITOR STUFF/////////
        ////////////////////////////////////////
#if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Field"))
            {
                var menu = new UnityEditor.GenericMenu();
                if (agent != null)
                {
                    foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector))
                    {
                        menu = EditorUtils.GetInstanceFieldSelectionMenu(comp.GetType(), typeof(object), SetTargetField, menu);
                    }
                    menu.AddSeparator("/");
                }
                foreach (var t in TypePrefs.GetPreferedTypesList(typeof(object)))
                {
                    menu = EditorUtils.GetStaticFieldSelectionMenu(t, typeof(object), SetTargetField, menu);
                    if (typeof(Component).IsAssignableFrom(t))
                    {
                        menu = EditorUtils.GetInstanceFieldSelectionMenu(t, typeof(object), SetTargetField, menu);
                    }
                }
                menu.ShowAsBrowser("Select Field", this.GetType());
                Event.current.Use();
            }

            if (targetField != null)
            {
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", targetField.RTReflectedOrDeclaredType().FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Field", targetField.Name);
                UnityEditor.EditorGUILayout.LabelField("Field Type", targetField.FieldType.FriendlyName());
                UnityEditor.EditorGUILayout.HelpBox(DocsByReflection.GetMemberSummary(targetField), UnityEditor.MessageType.None);
                GUILayout.EndVertical();

                GUI.enabled = checkValue.varType == typeof(float) || checkValue.varType == typeof(int);
                comparison  = (CompareMethod)UnityEditor.EditorGUILayout.EnumPopup("Comparison", comparison);
                GUI.enabled = true;
                NodeCanvas.Editor.BBParameterEditor.ParameterField("Value", checkValue);
            }
        }
예제 #7
0
        public void RenderSitemap()
        {
            TemplatePlugin.current = new Template(Resources <Sitemap> .Read["handlers.Sitemap.html"]);

            foreach (var routeGroup in RouteTable.Routes.GroupBy(x => ((MethodInfo)((Route)x).DataTokens["methodInfo"]).DeclaringType.ToString()))
            {
                TemplatePlugin.current.Append("links", "<h3 style=\"margin-bottom:0; background:#eee; padding-bottom:0; padding-left:10px; \">" + routeGroup.Key + "</h3>");

                try
                {
                    XmlElement documentation = DocsByReflection.XMLFromType(((MethodInfo)((Route)routeGroup.FirstOrDefault()).DataTokens["methodInfo"]).DeclaringType);
                    TemplatePlugin.current.Append("links", " " + documentation["summary"] == null ? "" : documentation["summary"].InnerText.Trim() + "<br><br>");
                }
                catch (Exception e) {
                    TemplatePlugin.current.Append("links", "<br>");
                }


                foreach (Route route in routeGroup)
                {
                    var    methodInfo = ((MethodInfo)route.DataTokens["methodInfo"]);
                    string summary    = "";
                    try
                    {
                        XmlElement documentation = DocsByReflection.XMLFromMember(((MethodInfo)route.DataTokens["methodInfo"]));
                        summary = documentation["summary"] == null ? "" : documentation["summary"].InnerText.Trim();
                    }
                    catch (Exception e)
                    {
                        //summary = "no description found: " + e.Message;
                    }

                    TemplatePlugin.current.Append("links", "<div style=\"padding-left:10px; margin-left:10px; border-left:5px solid #ccc;\"><a href='./meta?url=" + route.Url.ToURL().Trim().Else("/") + "'>" + route.Url.Trim().Else("/") + "</a>\t\t" +
                                                  "<b>" + methodInfo.Name + "</b>(" +
                                                  string.Join(",", methodInfo.GetParameters().Select(x => "<i>" + x.ParameterType.ToString() + "</i> <b>" + x.Name + "</b>" + (x.IsOptional ? " = " + x.DefaultValue : "")).ToArray())
                                                  + ") returns <i>" + methodInfo.ReturnType.ToString() + "</i><p style=\"color:#999; font-size:smaller; margin-top:0;\">" + summary + "</p></div>");
                }
            }
        }
        ///----------------------------------------------------------------------------------------------
        ///---------------------------------------UNITY EDITOR-------------------------------------------
#if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Property"))
            {
                var menu = new UnityEditor.GenericMenu();
                if (agent != null)
                {
                    foreach (var comp in agent.GetComponents(typeof(Component)).Where(c => c.hideFlags != HideFlags.HideInInspector))
                    {
                        menu = EditorUtils.GetInstanceMethodSelectionMenu(comp.GetType(), typeof(object), typeof(object), SetMethod, 0, true, true, menu);
                    }
                    menu.AddSeparator("/");
                }
                foreach (var t in TypePrefs.GetPreferedTypesList(typeof(object)))
                {
                    menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu);
                    if (typeof(UnityEngine.Component).IsAssignableFrom(t))
                    {
                        menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 0, true, true, menu);
                    }
                }
                menu.ShowAsBrowser("Select Property", this.GetType());
                Event.current.Use();
            }

            if (targetMethod != null)
            {
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Property", targetMethod.Name);
                UnityEditor.EditorGUILayout.LabelField("Property Type", targetMethod.ReturnType.FriendlyName());
                UnityEditor.EditorGUILayout.HelpBox(DocsByReflection.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);
                GUILayout.EndVertical();

                NodeCanvas.Editor.BBParameterEditor.ParameterField("Save As", returnValue, true);
            }
        }
예제 #9
0
        ///----------------------------------------------------------------------------------------------
        ///---------------------------------------UNITY EDITOR-------------------------------------------
                #if UNITY_EDITOR
        protected override void OnTaskInspectorGUI()
        {
            if (!Application.isPlaying && GUILayout.Button("Select Method"))
            {
                var menu = new UnityEditor.GenericMenu();

                foreach (var t in TypePrefs.GetPreferedTypesList(typeof(T)))
                {
                    menu = EditorUtils.GetStaticMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, false, menu);
                    if (typeof(T).IsAssignableFrom(t))
                    {
                        menu = EditorUtils.GetInstanceMethodSelectionMenu(t, typeof(object), typeof(object), SetMethod, 6, false, false, menu);
                    }
                }
                if (menu.GetItemCount() <= 0)
                {
                    menu.AddItem(new GUIContent("No Functions"), false, null);
                }
                menu.ShowAsBrowser("Select Method", this.GetType());
                Event.current.Use();
            }

            var m = targetMethod;

            if (m != null)
            {
                if (!targetMethod.IsStatic)
                {
                    NodeCanvas.Editor.BBParameterEditor.ParameterField("Instance", target, true);
                }
                GUILayout.BeginVertical("box");
                UnityEditor.EditorGUILayout.LabelField("Type", targetMethod.RTReflectedOrDeclaredType().FriendlyName());
                UnityEditor.EditorGUILayout.LabelField("Method", m.Name);
                UnityEditor.EditorGUILayout.LabelField("Returns", m.ReturnType.FriendlyName());

                UnityEditor.EditorGUILayout.HelpBox(DocsByReflection.GetMemberSummary(targetMethod), UnityEditor.MessageType.None);

                if (m.ReturnType == typeof(IEnumerator))
                {
                    GUILayout.Label("<b>This will execute as a Coroutine!</b>");
                }

                GUILayout.EndVertical();

                var paramNames = m.GetParameters().Select(p => p.Name.SplitCamelCase()).ToArray();
                var variables  = functionWrapper.GetVariables();
                if (m.ReturnType == typeof(void))
                {
                    for (var i = 0; i < paramNames.Length; i++)
                    {
                        NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i]);
                    }
                }
                else
                {
                    for (var i = 0; i < paramNames.Length; i++)
                    {
                        NodeCanvas.Editor.BBParameterEditor.ParameterField(paramNames[i], variables[i + 1]);
                    }

                    if (m.ReturnType != typeof(IEnumerator))
                    {
                        NodeCanvas.Editor.BBParameterEditor.ParameterField("Save Return Value", variables[0], true);
                    }
                }
            }
        }
예제 #10
0
        private void FillInfoPanel()
        {
            var types = new[]
            {
                new { Category = "Characters", Type = typeof(Mob) },
                new { Category = "Characters", Type = typeof(Npc) },
                new { Category = "Characters", Type = typeof(Pet) },
                new { Category = "Characters", Type = typeof(Player) },
                new { Category = "On ground", Type = typeof(Loot) },
                new { Category = "On ground", Type = typeof(Mine) },
                new { Category = "Other", Type = typeof(HostPlayer) },
                new { Category = "Other", Type = typeof(InventoryItem) },
                new { Category = "Other", Type = typeof(Skill) },
            };

            types = types.Concat(
                typeof(PwObject).Assembly.GetTypes()
                .Where(t => t.Namespace != null && t.Namespace.EndsWith("Objects") && t.IsEnum)
                .Select(t => new { Category = "Enums", Type = t }))
                    .ToArray();

            foreach (var category in types.GroupBy(t => t.Category))
            {
                var catItem = CreateTreeViewItem(category.Key, "folder.png");
                classesTree.Items.Add(catItem);

                foreach (var type in category.Select(t => t.Type).OrderBy(t => t.Name))
                {
                    var typeItem = CreateTreeViewItem(type.Name, "class.png");
                    catItem.Items.Add(typeItem);
                    var items = new List <TreeViewItem>();
                    typeItem.Tag = items;

                    var type1 = type;
                    typeItem.MouseDoubleClick += (s, e) => InsertText(type1.Name);

                    if (type.IsEnum)
                    {
                        foreach (string enumValue in type.GetEnumNames())
                        {
                            string fullVal = string.Format("{0}.{1}", type.Name, enumValue);

                            var item = CreateTreeViewItem(enumValue, "property.png");
                            item.MouseDoubleClick += (s, e) => InsertText(fullVal);

                            items.Add(item);
                        }
                    }
                    else
                    {
                        foreach (var property in type.GetProperties().OrderBy(p => p.Name))
                        {
                            var prop = property;

                            var item = CreateTreeViewItem(string.Format("{0}  ({1})", property.Name, property.PropertyType.Name), "property.png");
                            item.ToolTip = CommonUtils.Safe(() => DocsByReflection.XMLFromMember(prop)["summary"].InnerText.Trim());

                            item.MouseDoubleClick += (s, e) => InsertText(prop.Name);

                            items.Add(item);
                        }
                    }
                }
            }

            foreach (var property in typeof(PwInterface).GetProperties().OrderBy(p => p.Name))
            {
                string insertStr = property.Name + "()";
                var    propItem  = CreateTreeViewItem(property.Name, "property.png");
                propItem.MouseDoubleClick += (s, e) => InsertText(insertStr);

                var panel = new StackPanel();
                propItem.Tag = panel;

                var linkTb = new TextBlock();
                linkTb.Inlines.Add("[");
                var link = new Hyperlink(new Run("Insert"));
                link.Click += (s, e) => InsertText(insertStr);
                linkTb.Inlines.Add(link);
                linkTb.Inlines.Add("]");
                linkTb.Inlines.Add(new LineBreak());

                panel.Children.Add(linkTb);

                try
                {
                    var    xmlDoc      = DocsByReflection.XMLFromMember(property);
                    string summaryInfo = xmlDoc["summary"].InnerText.Trim();
                    string returnInfo  = CommonUtils.Safe(() => xmlDoc["returns"].InnerText.Trim());

                    var tb = new TextBlock {
                        TextWrapping = TextWrapping.Wrap
                    };

                    tb.Inlines.Add(new Bold(new Run("Summary")));
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(summaryInfo);
                    tb.Inlines.Add(new LineBreak());

                    panel.Children.Add(tb);
                }
                catch
                {
                    panel.Children.Add(new TextBlock(new Bold(new Italic(new Run("Sorry, no info")))));
                }

                methodsTree.Items.Add(propItem);
            }

            Func <ParameterInfo, string> parameterToString = p =>
            {
                if (Attribute.IsDefined(p, typeof(ParamArrayAttribute)))
                {
                    return(string.Format("[*{0}]", p.Name));
                }

                if (p.IsOptional)
                {
                    if (p.RawDefaultValue is string)
                    {
                        return(string.Format("[{0} = \"{1}\"]", p.Name, p.RawDefaultValue));
                    }

                    return(string.Format("[{0} = {1}]", p.Name, p.RawDefaultValue ?? "None"));
                }

                return(p.Name);
            };

            foreach (var method in typeof(PwInterface).GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly).Where(m => !m.IsSpecialName).OrderBy(m => m.Name))
            {
                string infoStr   = string.Format("{0}({1})", method.Name, method.GetParameters().Aggregate(parameterToString, ", "));
                string insertStr = string.Format("{0}()", method.Name);

                var methodItem = CreateTreeViewItem(infoStr, "method.png");
                methodItem.MouseDoubleClick += (s, e) => InsertText(insertStr);

                var panel = new StackPanel();
                methodItem.Tag = panel;

                var linkTb = new TextBlock();
                linkTb.Inlines.Add("[");
                var link = new Hyperlink(new Run("Insert"));
                link.Click += (s, e) => InsertText(insertStr);
                linkTb.Inlines.Add(link);
                linkTb.Inlines.Add("]");
                linkTb.Inlines.Add(new LineBreak());

                panel.Children.Add(linkTb);

                try
                {
                    var    xmlDoc      = DocsByReflection.XMLFromMember(method);
                    string summaryInfo = xmlDoc["summary"].InnerText.Trim();
                    string returnInfo  = CommonUtils.Safe(() => xmlDoc["returns"].InnerText.Trim());

                    var tb = new TextBlock {
                        TextWrapping = TextWrapping.Wrap
                    };

                    tb.Inlines.Add(new Bold(new Run("Summary")));
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(summaryInfo);
                    tb.Inlines.Add(new LineBreak());
                    tb.Inlines.Add(new LineBreak());
                    if (xmlDoc.ChildNodes.OfType <XmlElement>().Where(xel => xel.Name == "param").Any())
                    {
                        tb.Inlines.Add(new Bold(new Run("Parameters")));
                        tb.Inlines.Add(new LineBreak());
                        foreach (var param in xmlDoc.ChildNodes.OfType <XmlElement>().Where(xel => xel.Name == "param"))
                        {
                            tb.Inlines.Add(new Italic(new Run(param.GetAttribute("name") + ": ")));
                            tb.Inlines.Add(new Run(param.InnerText.Trim()));
                            tb.Inlines.Add(new LineBreak());
                        }
                        tb.Inlines.Add(new LineBreak());
                    }
                    if (!returnInfo.IsNullOrWhiteSpace())
                    {
                        tb.Inlines.Add(new Bold(new Run("Return value")));
                        tb.Inlines.Add(new LineBreak());
                        tb.Inlines.Add(returnInfo);
                        tb.Inlines.Add(new LineBreak());
                    }

                    panel.Children.Add(tb);
                }
                catch
                {
                    panel.Children.Add(new TextBlock(new Bold(new Italic(new Run("Sorry, no info")))));
                }

                methodsTree.Items.Add(methodItem);
            }
        }