Пример #1
0
        private ParameterInfo FindParameterByName(MethodInfo methodInfo, string name, bool nameIsCaption)
        {
            BotDisplayNameAttribute nameAttribute = methodInfo.GetCustomAttribute <BotDisplayNameAttribute>();

            foreach (ParameterInfo item in methodInfo.GetParameters())
            {
                if (!nameIsCaption)
                {
                    if (item.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        return(item);
                    }
                }
                else
                {
                    string parameterName = "";
                    if (CurrentBotStructureInfo.InitializeServicesFromAttributes)
                    {
                        if (nameAttribute != null)
                        {
                            parameterName = nameAttribute.FindValue(item.Name);
                            //for take parameter attribute
                            if (parameterName == null)
                            {
                                nameAttribute = null;
                            }
                        }
                        //take attribute of parameter
                        if (nameAttribute == null)
                        {
                            nameAttribute = item.GetCustomAttribute <BotDisplayNameAttribute>();
                        }
                        if (nameAttribute == null)
                        {
                            continue;
                        }
                        //if parametername not found
                        if (string.IsNullOrEmpty(parameterName))
                        {
                            parameterName = nameAttribute.Content;
                        }
                    }
                    else
                    {
                        parameterName = item.Name;
                    }
                    if (parameterName.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        return(item);
                    }
                }
            }
            return(null);
        }
Пример #2
0
        private string GetParameterCaption(MethodInfo method, ParameterInfo parameter)
        {
            BotDisplayNameAttribute nameAttribute = method.GetCustomAttribute <BotDisplayNameAttribute>();
            string parameterName = "";

            if (CurrentBotStructureInfo.InitializeServicesFromAttributes)
            {
                if (nameAttribute != null)
                {
                    parameterName = nameAttribute.FindValue(parameter.Name);
                    //for take parameter attribute
                    if (parameterName == null)
                    {
                        nameAttribute = null;
                    }
                }
                //take attribute of parameter
                if (nameAttribute == null)
                {
                    nameAttribute = parameter.GetCustomAttribute <BotDisplayNameAttribute>();
                }
                if (nameAttribute == null)
                {
                    return("null");
                }
                //if parametername not found
                if (string.IsNullOrEmpty(parameterName))
                {
                    parameterName = nameAttribute.Content;
                }
            }
            else
            {
                parameterName = parameter.Name;
            }
            return(parameterName);
        }
Пример #3
0
        private List <List <BotButtonInfo> > GetMethodParametersButtons(MethodInfo method, TelegramClientInfo clientInfo)
        {
            List <BotButtonInfo> columns = new List <BotButtonInfo>();

            List <List <BotButtonInfo> > rows = new List <List <BotButtonInfo> >();

            int columnIndex = 0;

            List <ParameterInfo>    parameters    = method.GetParameters().ToList();
            BotDisplayNameAttribute nameAttribute = method.GetCustomAttribute <BotDisplayNameAttribute>();

            for (int i = 0; i < parameters.Count; i++)
            {
                ParameterInfo item          = parameters[i];
                string        parameterName = "";
                if (CurrentBotStructureInfo.InitializeServicesFromAttributes)
                {
                    if (nameAttribute != null)
                    {
                        parameterName = nameAttribute.FindValue(item.Name);
                        //for take parameter attribute
                        if (parameterName == null)
                        {
                            nameAttribute = null;
                        }
                    }
                    //take attribute of parameter
                    if (nameAttribute == null)
                    {
                        nameAttribute = item.GetCustomAttribute <BotDisplayNameAttribute>();
                    }
                    if (nameAttribute == null)
                    {
                        continue;
                    }
                    //if parametername not found
                    if (string.IsNullOrEmpty(parameterName))
                    {
                        parameterName = nameAttribute.Content;
                    }
                }
                else
                {
                    parameterName = item.Name;
                }
                if (columnIndex == 2)
                {
                    columnIndex = 0;
                    rows.Add(columns.ToList());
                    columns.Clear();
                }
                columns.Add(parameterName);
                columnIndex++;
            }
            if (rows.Count == 0)
            {
                rows.Add(columns);
            }
            rows.Add(new List <BotButtonInfo>()
            {
                new BotButtonInfo(CurrentBotStructureInfo.GetSendButtonText(clientInfo))
            });
            rows.Add(new List <BotButtonInfo>()
            {
                new BotButtonInfo(CurrentBotStructureInfo.GetCancelButtonText(clientInfo))
            });
            return(rows);
        }