Skip to content

Commit

Permalink
ReSharp 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
magicdict committed Apr 1, 2015
1 parent 9bfc905 commit 79ac343
Show file tree
Hide file tree
Showing 83 changed files with 6,875 additions and 6,878 deletions.
264 changes: 132 additions & 132 deletions Common/Logic/CloneMeunToolItem.cs
@@ -1,133 +1,133 @@
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;

namespace Common.Logic
{
public static class CloneMeunToolItem
{
/// <summary>
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsNumeric(this string str)
{
if (string.IsNullOrEmpty(str))
return false;
foreach (var c in str)
{
if (!char.IsNumber(c))
{
return false;
}
}
return true;
}

/// <summary>
/// 复制菜单项目
/// </summary>
/// <param name="orgMenuItem">原始的菜单</param>
/// <returns>克隆的菜单</returns>
public static ToolStripMenuItem Clone(this ToolStripMenuItem orgMenuItem)
{
var cloneMenuItem = new ToolStripMenuItem();
//!!!typeof的参数必须是ToolStripMenuItem的基类!!!如果使用Control则不能取到值!!!
//感谢CSDN网友beargo在帖子【如何获取事件已定制方法名?】里面的提示,网上的例子没有说明这个问题
//坑爹啊。。。。。。。。
var _List = GetObjectEventList(orgMenuItem, "EventClick", typeof (ToolStripItem));
// if (!SystemConfig.MonoMode)
// {
//悲催MONO不支持
if (_List != null && _List[0] != null)
{
try
{
cloneMenuItem.Click += (x, y) => _List[0].DynamicInvoke(x, y);
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex, cloneMenuItem.Text);
}
}
// }
cloneMenuItem.Text = orgMenuItem.Text;
cloneMenuItem.Enabled = orgMenuItem.Enabled;
cloneMenuItem.BackgroundImage = orgMenuItem.BackgroundImage;
cloneMenuItem.Image = orgMenuItem.Image;
//子菜单的复制
foreach (ToolStripMenuItem item in orgMenuItem.DropDownItems)
{
cloneMenuItem.DropDownItems.Add(item.Clone());
}
return cloneMenuItem;
}

/// <summary>
/// 复制菜单项目StripButton
/// </summary>
/// <param name="orgMenuItem">原始的菜单</param>
/// <returns>克隆的菜单StripButton</returns>
public static ToolStripButton CloneFromMenuItem(this ToolStripMenuItem orgMenuItem)
{
var cloneButton = new ToolStripButton();
//!!!typeof的参数必须是ToolStripMenuItem的基类!!!如果使用Control则不能取到值!!!
//感谢CSDN网友beargo在帖子【如何获取事件已定制方法名?】里面的提示,网上的例子没有说明这个问题
//坑爹啊。。。。。。。。
var _List = GetObjectEventList(orgMenuItem, "EventClick", typeof (ToolStripItem));
// if (!SystemConfig.MonoMode)
// {
//悲催MONO不支持
if (_List != null && _List[0] != null)
{
try
{
cloneButton.Click += (x, y) => _List[0].DynamicInvoke(x, y);
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex);
}
}
// }
cloneButton.Image = orgMenuItem.Image;
cloneButton.Enabled = orgMenuItem.Enabled;
cloneButton.Text = orgMenuItem.Text;
cloneButton.Checked = orgMenuItem.Checked;
cloneButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
return cloneButton;
}

/// <summary>
/// 获取控件事件 zgke@sina.com qq:116149
/// </summary>
/// <param name="obj">对象</param>
/// <param name="eventName">事件名 EventClick EventDoubleClick 这个需要看control.事件 是哪个类的名字是什么</param>
/// <param name="eventType">如果是WINFROM控件 使用typeof(Control)</param>
/// <returns>委托列</returns>
public static Delegate[] GetObjectEventList(object obj, string eventName, Type eventType)
{
var propertyInfo = obj.GetType()
.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
if (propertyInfo != null)
{
var eventList = propertyInfo.GetValue(obj, null);
var eventHandlerList = eventList as EventHandlerList;
if (eventHandlerList != null)
{
var list = eventHandlerList;
var fieldInfo = eventType.GetField(eventName,
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
if (fieldInfo == null)
{
return null;
}
var objDelegate = list[fieldInfo.GetValue(obj)];
return objDelegate == null ? null : objDelegate.GetInvocationList();
}
}
return null;
}
}
using System;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Forms;

namespace Common.Logic
{
public static class CloneMeunToolItem
{
/// <summary>
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool IsNumeric(this string str)
{
if (string.IsNullOrEmpty(str))
return false;
foreach (var c in str)
{
if (!char.IsNumber(c))
{
return false;
}
}
return true;
}

/// <summary>
/// 复制菜单项目
/// </summary>
/// <param name="orgMenuItem">原始的菜单</param>
/// <returns>克隆的菜单</returns>
public static ToolStripMenuItem Clone(this ToolStripMenuItem orgMenuItem)
{
var cloneMenuItem = new ToolStripMenuItem();
//!!!typeof的参数必须是ToolStripMenuItem的基类!!!如果使用Control则不能取到值!!!
//感谢CSDN网友beargo在帖子【如何获取事件已定制方法名?】里面的提示,网上的例子没有说明这个问题
//坑爹啊。。。。。。。。
var _List = GetObjectEventList(orgMenuItem, "EventClick", typeof (ToolStripItem));
// if (!SystemConfig.MonoMode)
// {
//悲催MONO不支持
if (_List != null && _List[0] != null)
{
try
{
cloneMenuItem.Click += (x, y) => _List[0].DynamicInvoke(x, y);
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex, cloneMenuItem.Text);
}
}
// }
cloneMenuItem.Text = orgMenuItem.Text;
cloneMenuItem.Enabled = orgMenuItem.Enabled;
cloneMenuItem.BackgroundImage = orgMenuItem.BackgroundImage;
cloneMenuItem.Image = orgMenuItem.Image;
//子菜单的复制
foreach (ToolStripMenuItem item in orgMenuItem.DropDownItems)
{
cloneMenuItem.DropDownItems.Add(item.Clone());
}
return cloneMenuItem;
}

/// <summary>
/// 复制菜单项目StripButton
/// </summary>
/// <param name="orgMenuItem">原始的菜单</param>
/// <returns>克隆的菜单StripButton</returns>
public static ToolStripButton CloneFromMenuItem(this ToolStripMenuItem orgMenuItem)
{
var cloneButton = new ToolStripButton();
//!!!typeof的参数必须是ToolStripMenuItem的基类!!!如果使用Control则不能取到值!!!
//感谢CSDN网友beargo在帖子【如何获取事件已定制方法名?】里面的提示,网上的例子没有说明这个问题
//坑爹啊。。。。。。。。
var _List = GetObjectEventList(orgMenuItem, "EventClick", typeof (ToolStripItem));
// if (!SystemConfig.MonoMode)
// {
//悲催MONO不支持
if (_List != null && _List[0] != null)
{
try
{
cloneButton.Click += (x, y) => _List[0].DynamicInvoke(x, y);
}
catch (Exception ex)
{
Utility.ExceptionDeal(ex);
}
}
// }
cloneButton.Image = orgMenuItem.Image;
cloneButton.Enabled = orgMenuItem.Enabled;
cloneButton.Text = orgMenuItem.Text;
cloneButton.Checked = orgMenuItem.Checked;
cloneButton.DisplayStyle = ToolStripItemDisplayStyle.Image;
return cloneButton;
}

/// <summary>
/// 获取控件事件 zgke@sina.com qq:116149
/// </summary>
/// <param name="obj">对象</param>
/// <param name="eventName">事件名 EventClick EventDoubleClick 这个需要看control.事件 是哪个类的名字是什么</param>
/// <param name="eventType">如果是WINFROM控件 使用typeof(Control)</param>
/// <returns>委托列</returns>
public static Delegate[] GetObjectEventList(object obj, string eventName, Type eventType)
{
var propertyInfo = obj.GetType()
.GetProperty("Events", BindingFlags.Instance | BindingFlags.NonPublic);
if (propertyInfo != null)
{
var eventList = propertyInfo.GetValue(obj, null);
var eventHandlerList = eventList as EventHandlerList;
if (eventHandlerList != null)
{
var list = eventHandlerList;
var fieldInfo = eventType.GetField(eventName,
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.IgnoreCase);
if (fieldInfo == null)
{
return null;
}
var objDelegate = list[fieldInfo.GetValue(obj)];
return objDelegate == null ? null : objDelegate.GetInvocationList();
}
}
return null;
}
}
}
60 changes: 30 additions & 30 deletions Common/Logic/Model.cs
@@ -1,31 +1,31 @@
using System;

namespace Common.Logic
{
/// <summary>
/// 数据库记录
/// </summary>
[Serializable]
public class Model<T>
{
/// <summary>
/// 数据
/// </summary>
public T DataRec;

/// <summary>
/// 统一编号
/// </summary>
public string DBId;

/// <summary>
/// 删除标志
/// </summary>
public Boolean IsDel;

/// <summary>
/// 最后更新时间
/// </summary>
public DateTime LastUpdate;
}
using System;

namespace Common.Logic
{
/// <summary>
/// 数据库记录
/// </summary>
[Serializable]
public class Model<T>
{
/// <summary>
/// 数据
/// </summary>
public T DataRec;

/// <summary>
/// 统一编号
/// </summary>
public string DBId;

/// <summary>
/// 删除标志
/// </summary>
public Boolean IsDel;

/// <summary>
/// 最后更新时间
/// </summary>
public DateTime LastUpdate;
}
}

0 comments on commit 79ac343

Please sign in to comment.