首页 > 其他 > 详细

ExtensionHelper扩展帮助类

时间:2021-05-11 17:49:40      阅读:20      评论:0      收藏:0      [点我收藏+]

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

ExtensionHelper扩展帮助类

原文:https://www.cnblogs.com/wesson2019-blog/p/14755599.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!