private static ModelItem GetModelItemForObject(IPlatform platform, object obj) { IViewObject viewObject = platform.ViewObjectFactory.Instantiate(obj); IDesignModeValueProviderContext valueProviderContext = WeakReferenceHelper.Unwrap <IInstanceBuilderContext>(viewObject.GetCurrentValue(platform.Metadata.ResolveProperty(DesignTimeProperties.InstanceBuilderContextProperty))) as IDesignModeValueProviderContext; if (valueProviderContext != null) { return(valueProviderContext.GetModelItemForViewObject(viewObject)); } return((ModelItem)null); }
public static string AsString(object result, EListDisplayMode listDisplayMode) { if (result == null) { return(""); } if (result is string) { return((string)result); } if (result is IEnumerable) { ICollection col = result as ICollection; IEnumerable enu = (IEnumerable)result; int count; if (col != null) { count = col.Count; } else { count = enu.CountAll(); } switch (listDisplayMode) { case EListDisplayMode.Smart: if (count == 1) { return(AsString(enu.FirstOrDefault2())); } else if (count == 0) { return(""); } else { return("(" + count.ToString() + ")"); } case EListDisplayMode.Count: return(count.ToString()); case EListDisplayMode.CountAndContent: return("(" + count.ToString() + ") " + StringHelper.ArrayToString(enu, AsString)); case EListDisplayMode.Content: return(StringHelper.ArrayToString(enu, AsString)); } } if (result is Visualisable) { Visualisable v = (Visualisable)result; return(v.DisplayName); } if (result is double) { double d = (double)result; if (double.IsNaN(d)) { return(""); } return(Maths.SignificantDigits(d)); } if (result is int) { if ((int)result == 0) { return(""); } else { return(result.ToString()); } } if (result is bool) { if ((bool)result) { return("☑"); } else { return("☐"); } } if (result is Type) { return(((Type)result).ToUiString()); } if (result is WeakReference) { object t = ((WeakReference)result).Target; if (t == null) { return("(Expired reference)"); } return("&" + AsString(t, listDisplayMode)); } if (ReflectionHelper.IsOfGenericType(result, typeof(WeakReference <>))) { object t = WeakReferenceHelper.GetUntypedTarget(result); if (t == null) { return("(Expired reference)"); } return("&" + AsString(t, listDisplayMode)); } return(result.ToString()); }