Пример #1
0
		// Remove any cast information
		internal static void RemoveCast(CastInfo castInfo)
		{
			// Not a remembered cast
			if (castInfo._memberSig == null)
				return;
			lock (_casts) {
				_casts.Remove(castInfo.Key);
				if (castInfo.Perm) {
					ComponentInspectorProperties.SavedCasts.Remove(castInfo.DeclaringType, castInfo.MemberSig);
				}
			}
		}
Пример #2
0
		static CastInfo()
		{
			SavedCastInfoCollection savedCasts = ComponentInspectorProperties.SavedCasts;
			for (int i = savedCasts.Count - 1; i >= 0; --i) {
				SavedCastInfo savedCastInfo = savedCasts[i];
				try {
					Type castType = ReflectionHelper.GetType(savedCastInfo.CastTypeName);
					if (castType == null) {
						throw new Exception ("Cast type: " + savedCastInfo.CastTypeName + " not found");
					}
					CastInfo ci = new CastInfo(savedCastInfo.MemberSignature,
											  savedCastInfo.TypeName,
											  castType,
											  true);
					_casts.Add(ci.Key, ci);
				} catch (Exception ex) {
					TraceUtil.WriteLineWarning(typeof(CastInfo),
						"Warning: Invalid cast information in "
						+ "registry for: " 
						+ savedCastInfo.TypeName + "/" + savedCastInfo.MemberSignature 
						+ " - deleting  Exception: " + ex);
					savedCasts.Remove(savedCastInfo);
				}
			}
		}
Пример #3
0
		// Adds cast information, if the memberInfo is null, this 
		// cast is not rememebered at all
		internal static CastInfo AddCast(MemberInfo memberInfo,
										Type castType,
										bool perm,
										Object currentObj)
		{
			CastInfo ci;
			if (memberInfo == null) {
				ci = new CastInfo(castType);
			} else {
				ci = new CastInfo(memberInfo.ToString(),
								 memberInfo.DeclaringType.FullName,
								 castType,
								 perm);
			}
			// Optionally make sure the cast will work for a 
			// specified object
			if (currentObj != null)
				ci.DoCast(currentObj);
			// We don't try to remember if if there is no memberInfo
			if (memberInfo == null)
				return ci;
			lock (_casts) {
				if (_casts[ci.Key] == null) {
					_casts.Add(ci.Key, ci);
				} else {
					// Get rid of the permanent key if it was there
					if (!perm) {
						ComponentInspectorProperties.SavedCasts.Remove(ci.DeclaringType, ci.MemberSig);
					}
				}
			}
			if (perm) {
				ComponentInspectorProperties.SavedCasts.Remove(memberInfo.DeclaringType.FullName, memberInfo.ToString());
				SavedCastInfo savedCast = new SavedCastInfo(memberInfo.DeclaringType.FullName, memberInfo.ToString(), castType.FullName);
				ComponentInspectorProperties.SavedCasts.Add(savedCast);
			}
			return ci;
		}