public void CreateMethodParameterTextTest()
        {
            var exp    = "(this System.Collections.Generic.Dictionary<K, V> dict, K key, V defaultValue)";
            var member = new Member()
            {
                Type           = MethodType.ExtensionMethod,
                ParameterTypes = new List <TypeInfo>
                {
                    new TypeInfo
                    {
                        Name      = "Dictionary<K, V>",
                        Namespace = "System.Collections.Generic"
                    },
                    new TypeInfo
                    {
                        Name = "K"
                    },
                    new TypeInfo
                    {
                        Name = "V"
                    }
                },
                ParameterNames = new Dictionary <string, string>
                {
                    { "dict", "" },
                    { "key", "" },
                    { "defaultValue", "" }
                }
            };

            var value = MethodParameterConverter.CreateMethodParameterText(member, true);

            Assert.AreEqual(exp, value);
        }
        public void ResolveGenericsTypeToHtmlTest()
        {
            var exp   = "System.Collections.Generic.Dictionary&lt;K, V&gt;";
            var value = MethodParameterConverter.ResolveGenericsTypeToHtml("System.Collections.Generic.Dictionary<K, V>");

            Assert.AreEqual(exp, value);
        }
Пример #3
0
        private string ConvertToDefinition(ClassInfo classInfo, bool isFullname)
        {
            var sb = new StringBuilder();

            if (classInfo.ClassType == ClassType.Method || classInfo.ClassType == ClassType.Constructor)
            {
                sb.AppendFormat("{0} ", classInfo.Accessibility.ToString().ToLower());

                if (classInfo.IsOverride)
                {
                    sb.Append("override ");
                }
                if (classInfo.IsVirtual)
                {
                    sb.Append("virtual ");
                }
                if (classInfo.IsStatic)
                {
                    sb.Append("static ");
                }
                if (classInfo.IsAsync)
                {
                    sb.Append("async ");
                }
                if (classInfo.IsExtern)
                {
                    sb.Append("extern ");
                }

                if (classInfo.ClassType == ClassType.Method)
                {
                    sb.AppendFormat("{0} ", classInfo.ReturnType.GetName(isFullname));
                }
                sb.AppendFormat("{0}", classInfo.Name);
                sb.AppendFormat("{0};", MethodParameterConverter.CreateMethodParameterText(this, isFullname));
            }
            else if (classInfo.ClassType == ClassType.Property)
            {
                sb.AppendFormat("{0} ", classInfo.Accessibility.ToString().ToLower());
                sb.AppendFormat("{0} ", classInfo.ReturnType.GetName(isFullname));
                sb.AppendFormat("{0} {{ ", classInfo.Name);

                foreach (var accessors in classInfo.Accessors)
                {
                    if (accessors.Accessibility == Accessibility.Public)
                    {
                        sb.AppendFormat("{0}; ", accessors.Name);
                    }
                    else if (accessors.Accessibility != Accessibility.Private)
                    {
                        sb.AppendFormat("{0} {1}; ", accessors.Accessibility.ToString().ToLower(), accessors.Name);
                    }
                }

                sb.AppendFormat("}}");
            }

            return(MethodParameterConverter.ResolveGenericsTypeToHtml(sb.ToString()));
        }