/// <summary>
 ///     Gets the value associated with the specified key.
 /// </summary>
 /// <typeparam name="T">The type of value.</typeparam>
 /// <param name="key">The specified key.</param>
 /// <returns>An instance of T.</returns>
 public T Get <T>(string key)
 {
     if (_firstContainer.IsContains(key))
     {
         return(_firstContainer.Get <T>(key));
     }
     if (_secondContainer.IsContains(key))
     {
         return(_secondContainer.Get <T>(key));
     }
     return(default(T));
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Creates an <see cref="IBuildInfoModel" /> for the specified <see cref="KeyValuePair{TKey,TValue}" />.
        /// </summary>
        /// <param name="htmlHelper">
        ///     The specified <see cref="HtmlHelper" />.
        /// </param>
        /// <param name="parameterContainer">
        ///     The specified <see cref="IParameterContainer" />.
        /// </param>
        /// <param name="captchaPair">
        ///     The specified <see cref="KeyValuePair{TKey,TValue}" />.
        /// </param>
        /// <param name="imgUrl">The specified image url.</param>
        /// <param name="refreshUrl">The specified refresh url.</param>
        /// <returns>
        ///     An instance of <see cref="IBuildInfoModel" />.
        /// </returns>
        protected virtual IBuildInfoModel CreateBuildInfo(HtmlHelper htmlHelper, IParameterContainer parameterContainer,
                                                          KeyValuePair <string, ICaptchaValue> captchaPair, string imgUrl,
                                                          string refreshUrl)
        {
            string requiredText = null;
            string refreshText;
            string inputText;

            parameterContainer.TryGet(RefreshTextAttribute, out refreshText, "Refresh");
            bool findInputText = parameterContainer.TryGet(InputTextAttribute, out inputText);
            bool isRequired    = parameterContainer.IsContains(IsRequiredAttribute);

            if (isRequired)
            {
                parameterContainer.TryGet(RequiredMessageAttribute, out requiredText, "This is a required field.");
            }

            IBuildInfoModel buildInfo;

            if (parameterContainer.IsContains(MathCaptchaAttribute))
            {
                buildInfo = new MathBuildInfoModel(parameterContainer, TokenParameterName, MathCaptchaAttribute, isRequired, requiredText,
                                                   refreshText, findInputText ? inputText : "The answer is", htmlHelper,
                                                   InputElementName, TokenElementName,
                                                   ImageElementName, imgUrl, refreshUrl, captchaPair.Key);
            }
            else
            {
                buildInfo = new DefaultBuildInfoModel(parameterContainer, TokenParameterName, requiredText, isRequired,
                                                      refreshText, findInputText ? inputText : "Input symbols",
                                                      htmlHelper,
                                                      InputElementName, ImageElementName, TokenElementName, refreshUrl,
                                                      imgUrl,
                                                      captchaPair.Key);
            }

            //If it a partial view.
            if (parameterContainer.IsContains(PartialViewNameAttribute))
            {
                ViewDataDictionary viewData;
                parameterContainer.TryGet(PartialViewDataAttribute, out viewData);
                string scriptPartialView;
                parameterContainer.TryGet(ScriptPartialViewNameAttribute, out scriptPartialView);

                return(new PartialBuildInfoModel(htmlHelper, buildInfo,
                                                 parameterContainer.Get <string>(PartialViewNameAttribute),
                                                 scriptPartialView, viewData));
            }
            return(buildInfo);
        }