void GetSavedCasts() { foreach (string cast in SavedCasts) { List.Add(SavedCastInfo.ConvertFromString(cast)); } }
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); } } }
public void Remove(SavedCastInfo castInfo) { int index = List.IndexOf(castInfo); if (index != -1) { RemoveAt(index); UpdateProperties(); } }
void UpdateProperties() { string[] items = new string[List.Count]; for (int i = 0; i < Count; ++i) { SavedCastInfo cast = (SavedCastInfo)List[i]; items[i] = cast.ConvertToString(); } SavedCasts = items; }
int IndexOf(string typeName, string memberSignature) { for (int i = 0; i < Count; ++i) { SavedCastInfo cast = (SavedCastInfo)List[i]; if (cast.TypeName == typeName && cast.MemberSignature == memberSignature) { return(i); } } return(-1); }
// 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); }
public void Add(SavedCastInfo cast) { List.Add(cast); UpdateProperties(); }
// 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; }