Exemplo n.º 1
0
        public override string ToString()
        {
            var sb = new StringBuilder();

            Type = VkMethodInfo.GetReturnType(Description);

            switch (Type)
            {
            case ReturnType.Bool:
                sb.Append("bool");
                break;

            case ReturnType.Collection:
                sb.Append("IEnumerable<>");
                break;

            case ReturnType.Void:
                sb.Append("void");
                break;

            case ReturnType.Long:
                if (Name == "count" || Name == "offset")
                {
                    sb.Append("int");
                }
                else
                {
                    sb.Append("long");
                }
                break;

            case ReturnType.String:
                sb.Append("string");
                break;

            case ReturnType.Double:
                sb.Append("double");
                break;

            default:
                sb.Append("long");     // if unknown make it long
                break;
            }

            if (!IsMandatory && Type != ReturnType.String)
            {
                sb.Append("?");
            }

            sb.Append(" ");

            sb.Append(CanonicalName);

            if (!IsMandatory)
            {
                sb.Append(" = null");
            }

            return(sb.ToString());
        }
Exemplo n.º 2
0
        public void GenerateMethod_Fave_GetUsers()
        {
            var method = new VkMethodInfo
            {
                Name = "fave.getUsers",
                Description = "Возвращает список пользователей",
                ReturnType = ReturnType.Collection,
                ReturnText = "После успешного выполнения возвращает список объектов пользователей."
            };

            method.Params.Add(new VkMethodParam
            {
                Name = "count",
                Description = "Количество пользователей, информацию о которых необходимо вернуть",
                Restrictions = VkParamRestrictions.PositiveDigit
            });
            method.Params.Add(new VkMethodParam
            {
                Name = "offset",
                Description = "Смещение",
                Restrictions = VkParamRestrictions.PositiveDigit
            });

            var gen = new VkApiGenerator();
            string result = gen.GenerateMethod(method);

            result.ShouldEqual(@"/// <summary>
/// Возвращает список пользователей
/// </summary>
/// <param name=""count"">Количество пользователей, информацию о которых необходимо вернуть</param>
/// <param name=""offset"">Смещение</param>
/// <returns>После успешного выполнения возвращает список объектов пользователей.</returns>
/// <remarks>
/// Страница документации ВКонтакте <see href=""http://vk.com/dev/fave.getUsers""/>.
/// </remarks>
public ReadOnlyCollection<> GetUsers(int? count = null, int? offset = null)
{
    VkErrors.ThrowIfNumberIsNegative(() => count);
    VkErrors.ThrowIfNumberIsNegative(() => offset);

    var parameters = new VkParameters
        {
            {""count"", count},
            {""offset"", offset}
        };

    VkResponseArray response = _vk.Call(""fave.getUsers"", parameters);

    return response.ToReadOnlyCollectionOf<>(x => x);
}");
        }
Exemplo n.º 3
0
        public static VkMethodInfo Parse(HtmlDocument html)
        {
            var info = new VkMethodInfo();

            info.Description = GetDesctiption(html);
            info.Params = GetParams(html);
            info.ReturnText = GetReturnText(html).TransformXmlDocCommentes();
            info.ReturnType = GetReturnType(info.ReturnText);

//            Debug.Assert(!string.IsNullOrEmpty(info.Description));
//            Debug.Assert(!string.IsNullOrEmpty(info.ReturnText));
//            Debug.Assert(info.ReturnType != ReturnType.Unknown);

            return info;
        }
Exemplo n.º 4
0
        public static VkMethodInfo Parse(HtmlDocument html)
        {
            var info = new VkMethodInfo();

            info.Description = GetDesctiption(html);
            info.Params      = GetParams(html);
            info.ReturnText  = GetReturnText(html).TransformXmlDocCommentes();
            info.ReturnType  = GetReturnType(info.ReturnText);

//            Debug.Assert(!string.IsNullOrEmpty(info.Description));
//            Debug.Assert(!string.IsNullOrEmpty(info.ReturnText));
//            Debug.Assert(info.ReturnType != ReturnType.Unknown);

            return(info);
        }
Exemplo n.º 5
0
        public VkMethodViewModel(VkMethodInfo method)
        {
            switch (method.ReturnType)
            {
            case Model.ReturnType.Bool:
                ReturnType = "bool";
                break;

            case Model.ReturnType.Collection:
                ReturnType = "ReadOnlyCollection<>";
                break;

            case Model.ReturnType.Void:
                ReturnType = "void";
                break;

            case Model.ReturnType.Long:
                ReturnType = "long";
                break;

            case Model.ReturnType.Unknown:
                ReturnType = "Unknown";
                break;

            case Model.ReturnType.String:
                ReturnType = "string";
                break;

            case Model.ReturnType.Double:
                ReturnType = "double";
                break;

            default:
                throw new ArgumentException("Unknown return type: " + method.ReturnType);
            }

            Name             = method.CanonicalName;
            Params           = method.Params.ToString();
            Check            = GetCheckBlock(method.Params);
            ParamsDefinition = GetParamsDefinitionnBlock(method.Params);
            Invoke           = GetInvokeBlock(method.ReturnType, method.Name, method.Params.Count);
            Return           = GetReturnBlock(method.ReturnType);
            XmlDoc           = GetXmlDoc(method.Name, method.Description, method.ReturnText, method.Params);
        }
Exemplo n.º 6
0
        public VkMethodViewModel(VkMethodInfo method)
        {
            switch (method.ReturnType)
            {
                case Model.ReturnType.Bool:
                    ReturnType = "bool";
                    break;

                case Model.ReturnType.Collection:
                    ReturnType = "ReadOnlyCollection<>";
                    break;

                case Model.ReturnType.Void:
                    ReturnType = "void";
                    break;

                case Model.ReturnType.Long:
                    ReturnType = "long";
                    break;

                case Model.ReturnType.Unknown:
                    ReturnType = "Unknown";
                    break;

                case Model.ReturnType.String:
                    ReturnType = "string";
                    break;

                case Model.ReturnType.Double:
                    ReturnType = "double";
                    break;

                default:
                    throw new ArgumentException("Unknown return type: " + method.ReturnType);
            }

            Name = method.CanonicalName;
            Params = method.Params.ToString();
            Check = GetCheckBlock(method.Params);
            ParamsDefinition = GetParamsDefinitionnBlock(method.Params);
            Invoke = GetInvokeBlock(method.ReturnType, method.Name, method.Params.Count);
            Return = GetReturnBlock(method.ReturnType);
            XmlDoc = GetXmlDoc(method.Name, method.Description, method.ReturnText, method.Params);
        }
Exemplo n.º 7
0
 public string GenerateMethod(VkMethodInfo method)
 {   
     var model = new VkMethodViewModel(method);
     return Razor.Parse(Template.Method, model);
 }
Exemplo n.º 8
0
 public void CanonicalName_EmptyName()
 {
     var method = new VkMethodInfo();
     method.CanonicalName.ShouldEqual(string.Empty);
 }
Exemplo n.º 9
0
 public void CanonicalName_NormalCase()
 {
     var method = new VkMethodInfo {Name = "fave.getPosts"};
     method.CanonicalName.ShouldEqual("GetPosts");
 }