protected override IClrObjMappingModel GetModelByObjectType(ClrObject clrObject) { ClrType tp = clrObject.Type; if (tp == null) { return(new ClrObjNoType { Obj = clrObject }); } if ((this.prevModelType == null) || (!this.prevModelType.Item1.Equals(tp.Name, StringComparison.Ordinal))) { IClrObjMappingModel res = base.GetModelByObjectType(clrObject); this.prevModelType = new Tuple <string, Type>(tp.Name, res.GetType()); return(res); } Type modelType = this.prevModelType.Item2; var result = Activator.CreateInstance(modelType) as IClrObjMappingModel; return(Assert.ResultNotNull( result, $"Could not cast {modelType.FullName} type to {typeof(IClrObjMappingModel).FullName}")); }
/// <summary> /// Builds the model. Free of recursion. Caching layer is provided by base class as well as high-level exception handling /// </summary> /// <param name="obj">Obj is guaranteed to have type and have non-null pointer.</param> /// <returns> /// The <see cref="IClrObjMappingModel" />. /// </returns> protected override IClrObjMappingModel DoBuildModelWrapped([NotNull] ClrObject obj) { ClrAssert.ObjectNotNullTypeNotEmpty(obj); IClrObjMappingModel model = this.GetModelByObjectType(obj); if (model is NoConverterForType) { IClrObjMappingModel specialCollection; // Try to read special collections like hashtables, arrays, generic lists, weak references, return(this.CollectionEnumerator.TryProcessSpecialCollection(obj, out specialCollection) ? specialCollection : model); } #if TRACE Trace.TraceInformation("{0} model was picked for {1} obj {2}", model.GetType().Name, obj.Type.Name, obj.Address.ToString("x8")); #endif this.MapModelFields(ref model, obj); model.Compute(); return(model); }
public PriorityFallbackMatchTypeProvider AddOrUpdate([NotNull] IClrObjMappingModel entityModelCandidate) { Assert.ArgumentNotNull(entityModelCandidate, "entityModelCandidate"); return(AddOrUpdate(entityModelCandidate.GetType())); }
/// <summary> /// Invokes the subscribed recursions. /// </summary> /// <param name="value">The value.</param> /// <param name="clrObject">The color object.</param> protected virtual void InvokeSubscribedRecursions(IClrObjMappingModel value, ClrObject clrObject) { if (RecursionCheckerDisabler.IsActive || !this.recursionCallBacks.ContainsKey(clrObject.Address)) { return; } if (value != null) { Delegate[] invocationList = this.recursionCallBacks[clrObject.Address].GetInvocationList(); foreach (Delegate @delegate in invocationList) { try { @delegate.DynamicInvoke(value); } catch (Exception ex) { Trace.TraceError("{0} error during {1} setting for {2} object", ex.ToString(), value.GetType().Name, clrObject.Address.ToString("x8")); } } } this.recursionCallBacks.Remove(clrObject.Address); }