zoukankan      html  css  js  c++  java
  • ExtensionHelper扩展帮助类

    public static class ExtensionHelper{}

    字符串转换成指定类型的值

    using System.ComponentModel;
    /// <summary>
    /// 字符串转换成指定类型的值
    /// </summary>
    /// <typeparam name="T">指定类型</typeparam>
    /// <param name="input">字符串</param>
    /// <returns>类型的值</returns>
    public static T Value<T>(this string input)
    {
        try
        {
            return (T)TypeDescriptor.GetConverter(typeof(T)).ConvertFromString(input);
        }
        catch
        {
            return default;
        }
    }
    

    DataGrid扩展

    public static DataGridCell GetCell(this DataGrid grid, DataGridRow row, int column)
    {
        if (row != null)
        {
            var presenter = WSCommFunc.GetVisualChild<System.Windows.Controls.Primitives.DataGridCellsPresenter>(row);
            if (presenter == null)
            {
                grid.ScrollIntoView(row, grid.Columns[column]);
                presenter = WSCommFunc.GetVisualChild<System.Windows.Controls.Primitives.DataGridCellsPresenter>(row);
            }
            return (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
        }
        return null;
    }
    
    public static DataGridCell GetCell(this DataGrid grid, int row, int column)
    {
        DataGridRow rowContainer = grid.GetRow(row);
        return grid.GetCell(rowContainer, column);
    }
    public static DataGridRow GetRow(this DataGrid grid, int index)
    {
        if (index < 0)
        {
            return null;
        }
        var row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
        if (row == null)
        {
            // 可能已虚拟化,进入视图并重试
            grid.UpdateLayout();
            grid.ScrollIntoView(grid.Items[index]);
            row = (DataGridRow)grid.ItemContainerGenerator.ContainerFromIndex(index);
        }
        return row;
    }
    
    扩展方法 解释 入口
    TraceMessage Caller Information Attributes调用者信息特性 demo
    RemoveAll IList清空 demo
    OnUIThread 多线程更新GUI demo
    DeepCopy DeepCopyByExpressTree 利用表达式树实现深复制 demo
  • 相关阅读:
    基础数据类型:列表
    基础数据类型(数字、布尔值、字符串)
    深浅copy
    集合
    逻辑运算
    poj 2287 Tian Ji -- The Horse Racing(贪心)
    hdu 1547 Bubble Shooter(深搜)
    hdu 1242 Rescue
    hdu 1175 连连看(深搜)
    hdu 2298 Toxophily(数学题)
  • 原文地址:https://www.cnblogs.com/wesson2019-blog/p/14755599.html
Copyright © 2011-2022 走看看