public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { ClrObject fld = obj.GetRefFld(entriesTableFldName); List <Tuple <ClrObject, ClrObject> > values = ClrCollectionHelper.EnumerateHashtable(fld); var hashtable = new Hashtable(values.Count); foreach (var keyValuePair in values) { ClrObject val = keyValuePair.Item2; if (val.IsNullObj) { continue; } var key = val.GetStringFld("Key"); ClrObject value = val.GetRefFld("Value"); if (key == null || value.IsNullObj) { continue; } IClrObjMappingModel valModel = factory.BuildModel(value); hashtable.Add(key, valModel); } var hashTableMapping = new HashtableMappingModel(hashtable, obj); return(hashTableMapping); }
public static IClrObjMappingModel EnumerateList(ClrObject clrObject, ModelMapperFactory factory) { var result = new ArrayMappingModel { Obj = clrObject }; ClrObject fld = clrObject.GetRefFld("_items"); if (fld.Type == null) { return(result); } ClrType tp = fld.Type.ComponentType; if ((!tp.IsValueClass) && (!tp.IsString)) { // TODO: add support of reading strings. List <ClrObject> enumeration = ClrCollectionHelper.EnumerateListOfRefTypes(clrObject); foreach (ClrObject o in enumeration) { IClrObjMappingModel model = factory.BuildModel(o); result.Elements.Add(model); } } return(result); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { // TODO: remove the hack var fld = obj.GetRefFld("<Values>k__BackingField"); if (fld.IsNullObj) { return(null); } var values = factory.BuildModel(fld) as HashtableMappingModel; if (values == null) { return(null); } var rs = new SitecoreMVCRenderingPropertiesModel { Obj = obj, Cacheable = string.Equals(values[@"Cacheable"] as string, "1", StringComparison.OrdinalIgnoreCase), Cache_VaryByData = string.Equals(values[@"Cache_VaryByData"] as string, "1", StringComparison.OrdinalIgnoreCase), CacheKey = values[@"CacheKey"] as string ?? "[NoCacheKey]" }; ID.TryParse(values[@"RenderingItemPath"], out rs.RenderingItemPath); return(rs); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { var field = obj.GetRefFld("_data"); IClrObjMappingModel safeDictionary; if (!factory.CollectionEnumerator.TryProcessSpecialCollection(field, out safeDictionary)) { return(null); } var casted = safeDictionary as HashtableMappingModel; if (casted == null) { return(null); } var model = new ArrayMappingModel(); foreach (IClrObjMappingModel key in casted.Elements.Keys) { model.AddElement(key); } return(model); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { if (obj.IsNullObj) { return(null); } ClrObject keyClrObj = obj.GetRefFld("key"); ClrObject valClrObj = obj.GetRefFld("val"); if (keyClrObj.IsNullObj) { return(null); } IClrObjMappingModel keyObj = factory.BuildModel(keyClrObj); if (keyObj is EmptyClrObjectModel) { return(null); } IClrObjMappingModel valObj = factory.BuildModel(valClrObj); return(new DictionaryEntryModel(keyObj, valObj)); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { ClrObject target = GetTargetObject(obj); #if TRACE Trace.TraceInformation($"{obj.HexAddress} WeakRef points on {target.HexAddress} with {target.Type?.Name ?? "no"} type"); #endif return(factory.BuildModel(target)); }
public void ConfigureServices(IServiceCollection services) { services .AddScoped <PersonRepository>() .AddSingleton <IMapper>(_ => ModelMapperFactory.CreateMapperV1()) .AddVersioning() .AddContext(Configuration.GetConnectionString("DbContext")) .AddSwaggerDocumentation() .AddSecurity(Configuration[AuthenticationConfigurationKeys.AUTHORITY], Configuration[AuthenticationConfigurationKeys.AUDIENCE]) .AddControllers(options => options.Filters.Add(new CustomExceptionFilter())); }
public virtual IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { var res = new IDListMappingModel { Obj = obj }; IDList list = Read(obj); res.Collection = list; return(res); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { ClrObject hashtable = obj.GetRefFld("_hashtable"); if (hashtable.IsNullObj) { return(null); } return(this._hashtableReader.SupportTransformation(hashtable) ? this._hashtableReader.ReadEntity(hashtable, factory) : null); // TODO : change in future. }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { var keys = obj.GetRefFld("items"); if (keys.IsNullObj) { return(new ArrayMappingModel() { Obj = obj }); } return(GenericListReader.EnumerateList(keys, factory)); }
public CollectionEnumeratorProvider([CanBeNull] Type[] collectionEnumerators, [NotNull] ModelMapperFactory factory) { Assert.ArgumentNotNull(factory, " no factory provided."); if (collectionEnumerators == null) { collectionEnumerators = ReflectionHelper.GetNotAbstractClassTypesFromNamespace(TextConstants.CollectionEnumerationNamespace); } CollectionReaderBase[] readers = BuildEntityReaders(collectionEnumerators); CollectionEnumerators = new List <CollectionReaderBase>(readers); Factory = factory; }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { var rawElelments = ProcessReferenceConcurrentDictionary(obj); var model = new HashtableMappingModel(rawElelments.Count, obj); foreach (var pair in rawElelments) { model.Elements.Add(factory.BuildModel(pair.Key), factory.BuildModel(pair.Value)); } return(model); }
public override IClrObjMappingModel ReadEntity(ClrObject clrObject, ModelMapperFactory factory) { var _itemsRef = clrObject.GetRefFld("_items"); if (_itemsRef.Type == null) { return new ArrayMappingModel { Obj = clrObject } } ; return(base.ReadEntity(_itemsRef, factory)); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { Dictionary <ClrObject, ClrObject> clrDictionary = ReadClrObjects(obj); HashtableMappingModel model; if (clrDictionary == null) { return(new HashtableMappingModel(obj)); } model = new HashtableMappingModel(clrDictionary.Count, obj); foreach (var pair in clrDictionary) { model.Elements.Add(factory.BuildModel(pair.Key), factory.BuildModel(pair.Value)); } return(model); }
protected ArrayMappingModel ReadArray([ClrObjAndTypeNotEmpty] ClrObject clrObject, [NotNull] ModelMapperFactory factory) { var result = new ArrayMappingModel { Obj = clrObject }; ClrObject[] arrayContent = this.EnumerationHelper.DoEnumerateArrayType(clrObject); if (arrayContent != null) { foreach (ClrObject o in arrayContent) { o.ReEvaluateType(); IClrObjMappingModel nested = factory.BuildModel(o); result.Elements.Add(nested); } } return(result); }
public override IClrObjMappingModel ReadEntity(ClrObject set, ModelMapperFactory factory) { var heap = set.Type.Heap; ClrObject container = set.GetRefFld("container"); var m_bucketsArray = container.GetRefFld("m_tables").GetRefFld("m_buckets"); var totalElements = m_bucketsArray.Type.GetArrayLength(m_bucketsArray.Address); var result = new ArrayMappingModel { Obj = set }; for (int i = 0; i < totalElements; i++) { var nodeAddress = (ulong)m_bucketsArray.Type.GetArrayElementValue(m_bucketsArray.Address, i); if (nodeAddress == 0) { continue; } var type = heap.GetObjectType(nodeAddress); if (type == null) { continue; } var node = new ClrObject(nodeAddress, type); var key = node.GetRefFld("m_key"); if (!key.IsNullObj) { result.AddElement(factory.BuildModel(key)); } } return(result); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, [NotNull] ModelMapperFactory factory) { Assert.ArgumentNotNull(factory, "factory"); if (obj.IsNullObj) { return(EmptyClrObjectModel.Instance); } var result = new EventHandlerModel { Obj = obj, target = obj.GetRefFld("_target") }; ClrObject invocationList = obj.GetRefFld(@"_invocationList"); if (invocationList.IsNullObj) { // Not multicast delegate ClrMethod methodDescriptor; if (!TryReadMethodPtr(obj, out methodDescriptor)) { if (!TryResolveMethodFromTarget(obj, out methodDescriptor)) { return(result); } } result.Info = methodDescriptor; return(result); } // Multicast Delegate // TODO: Consider changing ArrayMapping result.InvokationList = factory.BuildModel(invocationList) as ArrayMappingModel; return(result); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { ClrObject tablesFld = obj.GetRefFld("m_tables"); ClrObject bucketsFld = tablesFld.GetRefFld("m_buckets"); ClrType type = bucketsFld.Type; ClrHeap heap = type.Heap; IEnumerable <ClrObject> values = ClrCollectionHelper.EnumerateArrayOfRefTypes(bucketsFld).Where(t => !t.IsNullObj); ClrInstanceField valueField = type.ComponentType.GetFieldByName("m_value"); ClrInstanceField keyField = type.ComponentType.GetFieldByName("m_key"); var hashtableModel = new HashtableMappingModel { Obj = obj }; foreach (ClrObject val in values) { ClrObject keyObj = val.GetRefFld("m_key"); if (keyObj.IsNullObj) { continue; } ClrObject valObj = val.GetRefFld("m_value"); hashtableModel.Elements.Add( key: factory.BuildModel(keyObj), value: factory.BuildModel(valObj)); } return(hashtableModel); }
// TODO: should this method output be marked as [NotNull]/[CanBeNull] ? public abstract IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory);
/// <summary> /// Reads the entity. /// </summary> /// <param name="clrObject">ClrObject points on <see cref="Array"/>.</param> /// <param name="factory">The factory.</param> /// <returns></returns> public override IClrObjMappingModel ReadEntity([ClrObjAndTypeNotEmpty] ClrObject clrObject, [NotNull] ModelMapperFactory factory) { return(this.ReadArray(clrObject, factory)); }
protected virtual ArrayMappingModel ReadTheOnlyArrayInsideType(ClrObject obj, ModelMapperFactory factory) { ClrAssert.ClrObjectNotNull(obj); var type = obj.Type; Assert.Required(type, "NoType"); var collectionFld = (from fld in type.Fields let fldType = fld.Type where fldType != null where fldType.IsArray select fld).FirstOrDefault(); Assert.Required(collectionFld, "no array type found"); var address = (ulong)collectionFld.GetValue(obj.Address); var arrayObj = new ClrObject(address, type.Heap); if ((arrayObj.Address == default(ulong)) || (arrayObj.Type == null)) { return(null); } return(ReadArray(arrayObj, factory)); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { ClrObject _items = obj.GetRefFld("_items"); return(_reader.SupportTransformation(_items) ? _reader.ReadEntity(_items, factory) : null); }
public override IClrObjMappingModel ReadEntity(ClrObject clrObject, ModelMapperFactory factory) { return(ReadTheOnlyArrayInsideType(clrObject, factory)); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { return(EnumerateList(obj, factory)); }
public override IClrObjMappingModel ReadEntity(ClrObject obj, ModelMapperFactory factory) { var hashtableModel = new HashtableMappingModel { Obj = obj }; ClrObject entriesField = obj.GetRefFld(entriesFldName); if (entriesField == null || entriesField.Type == null) { // Object contains this field, but value is null. // Most likely dictionary is either in the middle of construction, or destruction. // Anyway we can assume it is empty. return(hashtableModel); } ClrType type = entriesField.Type; ClrHeap heap = type.Heap; var componentType = type.ComponentType; if (componentType == null) { // TODO :Try reload type. return(null); } ClrInstanceField valueField = componentType.GetFieldByName("value"); ClrInstanceField keyField = componentType.GetFieldByName("key"); int len = type.GetArrayLength(entriesField.Address); ulong entriesFieldAddress = entriesField.Address; for (int i = 0; i < len; i++) { ulong addr = type.GetArrayElementAddress(entriesFieldAddress, i); if (addr == 0) { continue; } try { var key = keyField.GetValue(addr, true); if (!(key is ulong)) { continue; } var keyPointer = (ulong)key; if (keyPointer == 0) { continue; } var val = valueField.GetValue(addr, true); ulong valuePointer; if (val is ulong) { valuePointer = (ulong)val; } else { valuePointer = 0; } var keyObj = new ClrObject(keyPointer, heap); var valObj = new ClrObject(valuePointer, heap); hashtableModel.Elements.Add(factory.BuildModel(keyObj), factory.BuildModel(valObj)); } catch (Exception) { Trace.TraceError("Count not read {0} object", obj.HexAddress); // Do nothing for now } } return(hashtableModel); }