ownerstatecondition.cs

来自「全功能c#编译器」· CS 代码 · 共 55 行

CS
55
字号
// <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 + =
减小字号Ctrl + -
显示快捷键?