Esempio n. 1
0
        public ScrapedGeneric(string type)
        {
            RawSwift = type;

            Name = ScrapeType(Helpers.ParseType(type.Split("<").First()));

            var insideOfTypes = type.Substring(type.IndexOf('<') + 1);

            insideOfTypes = insideOfTypes.Substring(0, insideOfTypes.Length - 1);
            var types = ScrapedParameter.ScrapeParameters(insideOfTypes);

            Types = new List <ScrapedType>();
            foreach (var genType in types)
            {
                Types.Add(ScrapeType(genType));
            }

            CSharpType = Name.CSharpType + "<" + string.Join(", ", Types.Select(genType => genType.CSharpType)) + ">";
            CSharpType = CSharpType.Replace("<void>", "");
        }
Esempio n. 2
0
        public ScrapedBlock(string type)
        {
            RawSwift = type;

            type = "(" + type.Trim(new[] { '(', ')', '!' }); //todo: lol this

            var returnType = type.Split("->").Last().Trim();

            if (returnType == "(")
            {
                CSharpType = "Action";
                Returns    = ScrapeType("void");
                Parameters = new List <ScrapedType>();
                return;
            }
            Returns = ScrapeType(returnType);

            var parameters = ScrapedParameter.ScrapeParameters(type.Split("->")[0].Trim().Trim('(', ')'));

            Parameters = new List <ScrapedType>();
            foreach (var param in parameters)
            {
                Parameters.Add(ScrapeType(param.Trim()));
            }

            if (returnType == "void" || Returns.CSharpType == "void")
            {
                if (Parameters.Count == 0)
                {
                    CSharpType = "Action";
                }
                else
                {
                    CSharpType = "Action<" + string.Join(", ", Parameters.Select(param => param.CSharpType)) + ">";
                }
            }
            else
            {
                CSharpType = "Func<" + string.Join(", ", Parameters.Select(param => param.CSharpType)) + ", " + Returns.CSharpType + ">";
            }
        }
Esempio n. 3
0
        public ScrapedMethod(ScrapedMember baseValues, HtmlNode node) : base(baseValues)
        {
            Description = node.SelectSingleNode("./div[@class='abstract']/p").RealInnerText();
            Deprecated  = Description.ToLower().Contains("deprecat");
            IsOptional  = Declaration.Contains("optional ");
            RawName     = Declaration.Split('(')[0].Split("func ").Last().Trim().Trim('`').Trim();
            CSharpName  = RawName.ToUpper()[0] + RawName.Substring(1);

            if (new[] { "object", "string", "delegate", "int", "uint", "float", "class", "this", "new", "event" }.Contains(CSharpName))
            {
                CSharpName = "@" + CSharpName;
            }

            if (Declaration.ToLower().Contains("init("))
            {
                CSharpName = "init";
            }


            var parameters = Declaration.Substring(Declaration.IndexOf('(') + 1);

            parameters = parameters.Substring(0, parameters.LastIndexOf(')'));

            var separatedParameters = ScrapedParameter.ScrapeParameters(parameters);

            Parameters = new List <ScrapedParameter>();
            foreach (var param in separatedParameters)
            {
                Parameters.Add(new ScrapedParameter(param));
            }

            var parameterTableRows = node.SelectNodes("./div[@class='parameters']/table/tbody/tr");

            if (parameterTableRows != null)
            {
                foreach (var row in parameterTableRows)
                {
                    var name       = row.SelectNodes("./td").First().RealInnerText().Trim();
                    var definition = row.SelectNodes("./td").Last().RealInnerText().Trim();
                    if (name != definition)
                    {
                        var matchingParameter = Parameters.FirstOrDefault(param => param.InternalName == name);
                        if (matchingParameter != null)
                        {
                            matchingParameter.Description = definition;
                        }
                    }
                }
            }

            var returns = node.SelectSingleNode("./result-description/p");

            if (returns != null)
            {
                ReturnDescription = returns.RealInnerText().Trim();
            }
            else
            {
                ReturnDescription = null;
            }

            if (Declaration.ToLower().Contains("allocwithzone"))
            {
                var m = 1;
            }

            if (Declaration.Contains("->"))
            {
                var returnType = Declaration.Split("->").Last();
                if (!returnType.EndsWith(")"))
                {
                    ReturnType = ScrapedType.ScrapeType(returnType);
                }
            }
            if (ReturnType == null || ReturnType.CSharpType.Trim() == "")
            {
                ReturnType = ScrapedType.ScrapeType("void");
            }

            var objCDeclaration =
                node.SelectSingleNode("./div[@class='declaration']/div[@class='Objective-C']/p[@class='para']").RealInnerText().Trim();

            if (objCDeclaration.StartsWith("-") || !Declaration.Contains("class "))
            {
                Static = false;
            }
            else
            {
                Static = true;
            }
            Public = true;
        }