abstractnamedentity.cs

来自「c#源代码」· CS 代码 · 共 83 行

CS
83
字号
// <file>
//     <copyright see="prj:///doc/copyright.txt"/>
//     <license see="prj:///doc/license.txt"/>
//     <owner name="?" email="?"/>
//     <version value="$version"/>
// </file>

using System;
using System.Collections;

namespace SharpDevelop.Internal.Parser
{
	[Serializable]
	public abstract class AbstractNamedEntity : AbstractDecoration
	{
		static char[] nameDelimiters = new char[] { '.', '+' };
//		public static Hashtable fullyQualifiedNames = new Hashtable();
		string fullyQualifiedName = null;
//		int nameHashCode = -1;
		
		public virtual string FullyQualifiedName {
			get {
				if (fullyQualifiedName == null) {
					return String.Empty;
				}
				
				return fullyQualifiedName;
//				return (string)fullyQualifiedNames[nameHashCode];
			}
			set {
				fullyQualifiedName = value;
//				nameHashCode = value.GetHashCode();
//				if (fullyQualifiedNames[nameHashCode] == null) {
//					fullyQualifiedNames[nameHashCode] = value;
//				}
			}
		}
		
		
		public virtual string Name {
			get {
				if (FullyQualifiedName != null) {
					int lastIndex;
					
					if (CanBeSubclass) {
						lastIndex = FullyQualifiedName.LastIndexOfAny(nameDelimiters);
					} else {
						lastIndex = FullyQualifiedName.LastIndexOf('.');
					}
					
					if (lastIndex < 0) {
						return FullyQualifiedName;
					} else {
						return FullyQualifiedName.Substring(lastIndex + 1);
					}
				}
				return null;
			}
		}

		public virtual string Namespace {
			get {
				if (FullyQualifiedName != null) {
					int lastIndex = FullyQualifiedName.LastIndexOf('.');
					
					if (lastIndex < 0) {
						return String.Empty;
					} else {
						return FullyQualifiedName.Substring(0, lastIndex);
					}
				}
				return null;
			}
		}
		
		protected virtual bool CanBeSubclass {
			get {
				return false;
			}
		}
	}
}

⌨️ 快捷键说明

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