⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ownerstatecondition.cs

📁 c#源代码
💻 CS
字号:
// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
//     <version value="$version"/>
// </file>

using System;
using System.Xml;

using ICSharpCode.Core.AddIns.Conditions;

namespace ICSharpCode.Core.AddIns
{
	public interface IOwnerState {
		System.Enum InternalState {
			get;
		}
	}
	
	[ConditionAttribute()]
	public class OwnerStateCondition : AbstractCondition
	{
		[XmlMemberAttribute("ownerstate", IsRequired = true)]
		string ownerstate;
		
		public string OwnerState {
			get {
				return ownerstate;
			}
			set {
				ownerstate = value;
			}
		}
		
		public override bool IsValid(object owner)
		{
			if (owner is IOwnerState) {
				try {
					System.Enum state = ((IOwnerState)owner).InternalState;
					System.Enum conditionEnum = (System.Enum)Enum.Parse(state.GetType(), ownerstate);
				
					int stateInt     = Int32.Parse(state.ToString("D"));
					int conditionInt = Int32.Parse(conditionEnum.ToString("D"));
					
					return (stateInt & conditionInt) > 0;
				} catch (Exception) {
					throw new ApplicationException("can't parse '" + ownerstate + "'. Not a valid value.");
				}
			}
			return false;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -