当前位置: 首页>>代码示例>>C#>>正文


C# IHtmlElement.Attribute方法代码示例

本文整理汇总了C#中IHtmlElement.Attribute方法的典型用法代码示例。如果您正苦于以下问题:C# IHtmlElement.Attribute方法的具体用法?C# IHtmlElement.Attribute怎么用?C# IHtmlElement.Attribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHtmlElement的用法示例。


在下文中一共展示了IHtmlElement.Attribute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FormButtonGroupItem

    internal FormButtonGroupItem( FormButtonGroup groupControl, IHtmlElement element )
      : base( groupControl )
    {

      if ( groupControl == null )
        throw new ArgumentNullException( "groupControl" );

      if ( element == null )
        throw new ArgumentNullException( "element" );

      if ( !element.Name.EqualsIgnoreCase( "input" ) )
        throw new InvalidOperationException();

      if ( !element.Attribute( "name" ).Value().EqualsIgnoreCase( groupControl.Name ) )
        throw new InvalidOperationException();

      var type = element.Attribute( "type" ).Value();

      if ( type.EqualsIgnoreCase( "radio" ) )
        ButtonType = FormGroupButtonType.RadioButton;

      else if ( type.EqualsIgnoreCase( "checkbox" ) )
        ButtonType = FormGroupButtonType.RadioButton;

      else
        throw new InvalidOperationException();

      Element = element;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:29,代码来源:FormButtonGroupItem.cs

示例2: GetRouteValues

    internal RouteValueDictionary GetRouteValues( IHtmlElement element, bool clearRouteAttributes )
    {

      var routeValues = new RouteValueDictionary();

      var inherits = element.Attribute( "inherits" ).Value();

      if ( inherits != null )
      {

        var inheritsKeys = GetInheritsKeys( inherits );

        foreach ( var key in inheritsKeys )
          routeValues.Add( key, RequestContext.RouteData.Values[key] );

      }


      if ( !MvcEnvironment.Configuration.DisableUnderscorePrefix )
        CustomRouteValues( element, "_", routeValues, clearRouteAttributes );
      
      CustomRouteValues( element, "route-", routeValues, clearRouteAttributes );

      return routeValues;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:25,代码来源:JumonyUrlHelper.cs

示例3: BindElement

    /// <summary>
    /// 对元素进行数据绑定
    /// </summary>
    /// <param name="element">需要绑定数据的元素</param>
    /// <param name="context">绑定上下文</param>
    /// <returns>返回是否对元素进行了不可逆转的操作(例如移除),故而禁止后续的绑定操作</returns>
    public void BindElement( HtmlBindingContext context, IHtmlElement element )
    {

      if ( element.Attribute( "binding-visible" ) != null )
      {
        var visible = element.Attribute( "binding-visible" ).Value();
        if ( visible.EqualsIgnoreCase( "false" ) || visible.EqualsIgnoreCase( "hidden" ) || visible.EqualsIgnoreCase( "invisible" ) )
        {
          element.Remove();

          context.CancelChildsBinding = context.BindCompleted = true;
        }
      }





      {
        //处理样式类
        var classAttribute = element.Attribute( classAttributePrefix );
        if ( classAttribute != null )
        {
          if ( !string.IsNullOrWhiteSpace( classAttribute.AttributeValue ) )
          {

            var classes = Regulars.whiteSpaceSeparatorRegex.Split( classAttribute.AttributeValue ).Where( c => c != "" ).ToArray();
            if ( classes.Any() )
              element.Class( classes );
          }

          element.RemoveAttribute( classAttributePrefix );
        }

      }

      {
        var classAttributes = element.Attributes().Where( a => a.Name.StartsWith( classAttributePrefix ) ).ToArray();
        BindElementClasses( element, classAttributes );
      }

      //处理CSS样式
      var styleAttributes = element.Attributes().Where( a => a.Name.StartsWith( styleAttributePrefix ) ).ToArray();
      BindElementStyles( element, styleAttributes );
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:51,代码来源:StyleBinder.cs

示例4: HtmlInputText

        internal HtmlInputText( HtmlForm form, IHtmlElement element )
        {
            if ( !element.Name.EqualsIgnoreCase( "input" ) )
            throw new InvalidOperationException( "只有input元素才能转换为HtmlTextInput对象" );

              _type = element.Attribute( "type" ).Value();
              if ( !allowTypes.Contains( _type, StringComparer.OrdinalIgnoreCase ) )
            throw new InvalidOperationException( "只有type为text、password或hidden的input元素才能转换为HtmlTextInput对象" );

              _form = form;
              _element = element;
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:12,代码来源:HtmlInputText.cs

示例5: IsEligible

        /// <summary>
        /// 检查元素是否符合选择条件
        /// </summary>
        /// <param name="element">要检查的元素</param>
        /// <returns>是否符合条件</returns>
        public bool IsEligible( IHtmlElement element )
        {
            string _value = null;

              var attribute = element.Attribute( name );

              if ( comparison == null )//如果没有运算符,那么表示判断属性是否存在
            return attribute != null;

              if ( attribute != null )
            _value = attribute.AttributeValue;

              return matchers[comparison]( value, _value );
        }
开发者ID:kissstudio,项目名称:Topawes5,代码行数:19,代码来源:CssAttributeSelector.cs

示例6: Execute

        public string Execute( object handler, IHtmlElement partialElement )
        {
            object[] parameterValues = new object[_parameters.Length];

              foreach ( var parameter in _parameters )
              {
            var value = partialElement.Attribute( parameter.Name ).Value();
            if ( value != null )
              parameterValues[parameter.Position] = ConvertValue( value, parameter.ParameterType );
            else
              parameterValues[parameter.Position] = parameter.DefaultValue.IfNull( null );
              }

              return _executor( handler, parameterValues );
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:15,代码来源:PartialViewExecutor.cs

示例7: BindElement

    /// <summary>
    /// 绑定元素
    /// </summary>
    /// <param name="context">当前绑定上下文</param>
    /// <param name="element">要绑定的元素</param>
    /// <returns>永远返回 false,表示继续进行后面的绑定</returns>
    public void BindElement( HtmlBindingContext context, IHtmlElement element )
    {

      if ( !element.Document.HtmlSpecification.IsCDataElement( element.Name ) )
        return;

      if ( element.Attribute( "literal-binder" ) == null )
        return;

      lock ( element.SyncRoot )
      {

        var text = element.InnerHtml();

        text = LiteralBind( text );
      }
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:23,代码来源:LiteralBinder.cs

示例8: HtmlTextInput

        public HtmlTextInput( IHtmlElement element )
        {
            if ( string.Equals( element.Name, "input", StringComparison.InvariantCultureIgnoreCase ) )
              {
            var inputTypes = new[] { "text", "password", "hidden" };

            if ( !inputTypes.Contains( element.Attribute( "type" ).Value, StringComparer.InvariantCultureIgnoreCase ) )
              throw new InvalidOperationException( "只有type为text、password或hidden的input元素才能转换为HtmlTextInput对象" );

            _element = element;
            _valueAttributeName = "value";
              }
              else if ( string.Equals( element.Name, "textarea", StringComparison.InvariantCultureIgnoreCase ) )
              {
            _element = element;
            _valueAttributeName = ":text";
              }

              if ( _element == null )
            throw new InvalidOperationException( "只有input或textarea元素才能转换为HtmlTextInput对象" );
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:21,代码来源:HtmlTextInput.cs

示例9: ProcessActionLink

    /// <summary>
    /// 派生类重写此方法对拥有 Action URL 的元素进行处理
    /// </summary>
    /// <param name="element">要处理的元素</param>
    /// <returns>元素是否包含 Action URL 并已经进行处理。</returns>
    protected virtual bool ProcessActionLink( IHtmlElement element )
    {
      if ( element.Attribute( "action" ) == null )
        return false;

      string attributeName;

      if ( element.Name.EqualsIgnoreCase( "a" ) )
        attributeName = "href";

      else if ( element.Name.EqualsIgnoreCase( "img" ) || element.Name.EqualsIgnoreCase( "script" ) )
        attributeName = "src";

      else if ( element.Name.EqualsIgnoreCase( "form" ) && element.Attribute( "controller" ) != null )
        attributeName = "action";

      else
        return false;



      var action = element.Attribute( "action" ).Value() ?? RouteData.Values["action"].CastTo<string>();
      var controller = element.Attribute( "controller" ).Value() ?? RouteData.Values["controller"].CastTo<string>();


      var routeValues = UrlHelper.GetRouteValues( element );


      element.RemoveAttribute( "action" );
      element.RemoveAttribute( "controller" );
      element.RemoveAttribute( "inherits" );


      var url = UrlHelper.Action( action, controller, routeValues );

      if ( url == null )
        element.Attribute( attributeName ).Remove();

      else
        element.SetAttribute( attributeName, url );


      return true;
    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:49,代码来源:ActionUrlBinder.cs

示例10: RenderPartial

    /// <summary>
    /// 渲染部分视图(重写此方法以实现自定义输出 partial 元素)
    /// </summary>
    /// <param name="partialElement">partial 元素</param>
    /// <returns></returns>
    protected override string RenderPartial( IHtmlElement partialElement )
    {
      var action = partialElement.Attribute( "action" ).Value();
      var view = partialElement.Attribute( "view" ).Value();
      var path = partialElement.Attribute( "path" ).Value();
      var name = partialElement.Attribute( "name" ).Value();

      if ( name != null )
        return RenderNamedPartial( partialElement, name );

      var helper = MakeHelper();


      try
      {
        if ( action != null )//Action 部分视图
        {
          var routeValues = Url.GetRouteValues( partialElement );

          return RenderAction( partialElement, action, partialElement.Attribute( "controller" ).Value(), routeValues );
        }

        else if ( view != null )
        {
          return RenderPartial( partialElement, view );
        }

        else if ( path != null )
        {
          RenderVirtualPath( path );
        }
      }

      catch ( ThreadAbortException )
      {
        throw;//不应屏蔽异常
      }

      catch //若渲染时发生错误
      {
        if ( MvcEnvironment.Configuration.IgnorePartialRenderException || partialElement.Attribute( "ignoreError" ) != null )
          return "<!--parital view render failed-->";
        else
          throw;
      }

      throw new NotSupportedException( "无法处理的partial标签:" + ContentExtensions.GenerateTagHtml( partialElement, false ) );

    }
开发者ID:ajayumi,项目名称:Jumony,代码行数:54,代码来源:PartialViewAdapter.cs

示例11: GetElementName

        private static string GetElementName( IHtmlElement element )
        {
            switch ( element.Name.ToLowerInvariant() )
              {

            case "html":
            //case "head":
            case "body":
              return null;

            case "a":
              if ( element.Attribute( "name" ) != null )
            return "link";
              else
            return "anchor";

            case "li":
              return "item";

            case "ul":
            case "ol":
              return "list";

            case "h1":
            case "h2":
            case "h3":
            case "h4":
            case "h5":
            case "h6":
              return "header";

            default:
              return element.Name;

              }
        }
开发者ID:kissstudio,项目名称:Topawes5,代码行数:36,代码来源:DocumentExtensions.cs

示例12: RenderPartial

        /// <summary>
        /// 渲染部分视图(重写此方法以实现自定义输出 partial 元素)
        /// </summary>
        /// <param name="partialElement">partial 元素</param>
        /// <returns></returns>
        protected virtual string RenderPartial( IHtmlElement partialElement )
        {
            var action = partialElement.Attribute( "action" ).Value();
              var view = partialElement.Attribute( "view" ).Value();
              var path = partialElement.Attribute( "path" ).Value();
              var handler = partialElement.Attribute( "handler" ).Value();
              var name = partialElement.Attribute( "name" ).Value();

              if ( !_partialExecutors.IsNullOrEmpty() && name != null )
              {
            var executor = _partialExecutors.FirstOrDefault( e => e.Name.EqualsIgnoreCase( name ) );
            if ( executor != null )
            {
              var wrapper = ViewHandler as IHandlerWrapper;
              if ( wrapper != null )
            return executor.Execute( wrapper.Handler, partialElement );
              else
            return executor.Execute( ViewHandler, partialElement );
            }
              }

              var helper = MakeHelper();

              try
              {
            if ( action != null )//Action 部分视图
            {
              var routeValues = Url.GetRouteValues( partialElement );

              return RenderAction( partialElement, action, partialElement.Attribute( "controller" ).Value(), routeValues );
            }

            else if ( view != null )
            {
              return RenderPartial( partialElement, view );
            }

            else if ( path != null )
            {
              if ( !VirtualPathUtility.IsAppRelative( path ) )
            throw new FormatException( "path 只能使用应用程序根相对路径,即以 \"~/\" 开头的路径,调用 VirtualPathUtility.ToAppRelative 方法或使用 HttpRequest.AppRelativeCurrentExecutionFilePath 属性获取" );

              var content = HtmlProviders.LoadContent( path );
              if ( content != null )
            return content.Content;
            }

              }
              catch ( ThreadAbortException )
              {

              }
              catch //若渲染时发生错误
              {
            if ( MvcEnvironment.Configuration.IgnorePartialRenderException || partialElement.Attribute( "ignoreError" ) != null )
              return "<!--parital view render failed-->";
            else
              throw;
              }

              throw new NotSupportedException( "无法处理的partial标签:" + ContentExtensions.GenerateTagHtml( partialElement, false ) );
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:67,代码来源:PartialViewAdapter.cs

示例13: GetRouteUrl

        /// <summary>
        /// 从元素标签中获取路由的虚拟路径
        /// </summary>
        /// <param name="element">要获取分析路由虚拟路径的元素</param>
        /// <param name="clearRouteAttributes">是否清理路由属性设置</param>
        /// <returns>获取的虚拟路径</returns>
        internal string GetRouteUrl( IHtmlElement element, bool clearRouteAttributes )
        {
            if ( element == null )
            throw new ArgumentNullException( "element" );

              if ( element.Attribute( "action" ) == null )
            throw new InvalidOperationException();

              var action = element.Attribute( "action" ).Value() ?? RouteData.Values["action"].CastTo<string>();
              var controller = element.Attribute( "controller" ).Value() ?? RouteData.Values["controller"].CastTo<string>();

              var routeValues = GetRouteValues( element, clearRouteAttributes );

              if ( clearRouteAttributes )
              {
            element.RemoveAttribute( "action" );
            element.RemoveAttribute( "controller" );
            element.RemoveAttribute( "inherits" );
              }

              return Url.Action( action, controller, routeValues );
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:28,代码来源:JumonyUrlHelper.cs

示例14: BindElement

        /// <summary>
        /// 对元素进行数据绑定
        /// </summary>
        /// <param name="element">需要绑定数据的元素</param>
        /// <param name="context">绑定上下文</param>
        /// <param name="dataContext">数据上下文</param>
        /// <returns>是否进行了绑定</returns>
        public bool BindElement( IHtmlElement element, HtmlBindingContext context, out object dataContext )
        {
            dataContext = null;

              if ( element.Attribute( "binding-visible" ) != null )
              {
            var visible = element.Attribute( "binding-visible" ).Value();
            if ( visible.EqualsIgnoreCase( "false" ) || visible.EqualsIgnoreCase( "hidden" ) || visible.EqualsIgnoreCase( "invisible" ) )
              element.Remove();
            return true;
              }

              //处理样式类
              {
            var classAttribute = element.Attribute( classAttributeName );
            if ( classAttribute != null )
            {
              if ( !string.IsNullOrWhiteSpace( classAttribute.AttributeValue ) )
              {

            var classes = Regulars.whiteSpaceSeparatorRegex.Split( classAttribute.AttributeValue ).Where( c => c != "" ).ToArray();
            if ( classes.Any() )
              element.Class( classes );
              }

              element.RemoveAttribute( classAttributeName );
            }
              }

              //处理CSS样式
              var styleAttributes = element.Attributes().Where( a => a.Name.StartsWith( styleAttributePrefix ) ).ToArray();
              if ( styleAttributes.Any() )
            BindElementStyles( element, styleAttributes );

              if ( !element.Name.EqualsIgnoreCase( "view" ) && !element.Name.EqualsIgnoreCase( "binding" ) )
              {
            var dataContextExpression = AttributeExpression.ParseExpression( element.Attribute( "datacontext" ) );
            if ( dataContextExpression != null )
              dataContext = GetDataObject( dataContextExpression, context );

            return false;
              }

              var expression = new AttributeExpression( element );

              object dataObject = GetDataObject( expression, context );

              if ( dataObject == null )
            return false;

              var format = element.Attribute( "format" ).Value();

              //绑定到客户端脚本对象
              var variableName = element.Attribute( "var" ).Value() ?? element.Attribute( "variable" ).Value();
              if ( variableName != null )
              {

            if ( format != null )
              dataObject = string.Format( format, dataObject );

            var hostName = element.Attribute( "host" ).Value();

            var script = (string) null;

            if ( hostName == null )
              script = string.Format( "(function(){{ this['{0}'] = {1} }})();", variableName, ToJson( dataObject ) );

            else
              script = string.Format( "(function(){{ this['{0}'] = {1} }})();", variableName, ToJson( dataObject ) );

            element.ReplaceWith( string.Format( "<script type=\"text/javascript\">{0}</script>", script ) );
            return true;
              }

              //绑定为 HTML 文本
              var bindValue = string.Format( format ?? "{0}", dataObject );

              var attributeName = element.Attribute( "attribute" ).Value() ?? element.Attribute( "attr" ).Value();
              if ( attributeName != null )
              {
            var nextElement = element.NextElement();
            if ( nextElement == null )
              return false;

            nextElement.SetAttribute( attributeName, bindValue );
            return true;
              }

              element.ReplaceWith( bindValue );
              return true;
        }
开发者ID:neo2018,项目名称:Jumony,代码行数:98,代码来源:DefaultElementBinder.cs

示例15: HtmlInputItem

            public HtmlInputItem( HtmlButtonGroup group, IHtmlElement element )
            {
                _group = group;

                if ( !element.Name.EqualsIgnoreCase( "input" ) )
                  throw new InvalidOperationException();

                var type = element.Attribute( "type" ).Value();

                if ( type.EqualsIgnoreCase( "radio" ) )
                  radio = true;

                else if ( type.EqualsIgnoreCase( "checkbox" ) )
                  radio = false;

                else
                  throw new InvalidOperationException();

                if ( string.IsNullOrEmpty( element.Attribute( "name" ).Value() ) )
                  throw new InvalidOperationException();

                _element = element;
            }
开发者ID:neo2018,项目名称:Jumony,代码行数:23,代码来源:HtmlButtonGroup.cs


注:本文中的IHtmlElement.Attribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。