// fieldInfo - the field who's value we want // objNode - the member node corresponding to the field // out topLevelObject - the object that contains the highest level // struct. // s/b protected, stupid compiler internal static FieldInfo[] GetStructFields (IObjectNode objNode, out Object topLevelObject) { Stack structInfoStack = new Stack(); IObjectNode parentObjNode; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor: " + objNode.ObjectInfo.ToString() + " node: " + objNode.ToString()); } // Build up the structFields array, the fields between the // top level object and the object we want to change while (true) { parentObjNode = objNode.ParentObjectNode; if (parentObjNode == null) { throw new Exception("(bug) hit no parent when " + "looking for enclosing object " + "for a struct " + objNode); } // This is an enclosing struct, push the field // information of how to get to the child here FieldInfo fi = parentObjNode.ObjType.GetField (objNode.ObjectInfo.ObjMemberInfo.Name, ReflectionHelper.ALL_BINDINGS); if (fi == null) { throw new Exception("(bug) field " + objNode.ObjType.Name + " not found in " + parentObjNode); } structInfoStack.Push(fi); // Found the containing object, either not a value // type, or this is not a field which means it can't // be inline any more if (!parentObjNode.ObjType.IsValueType || !(parentObjNode.ObjectInfo.ObjMemberInfo is FieldInfo)) { break; } // Go up objNode = parentObjNode; } // Ok, at this point, parent is the ObjectInfo for the // object that contains the top-level struct topLevelObject = parentObjNode.Obj; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - top level obj: " + topLevelObject); } int count = structInfoStack.Count; FieldInfo[] structFields = new FieldInfo[structInfoStack.Count]; for (int i = 0; i < count; i++) { structFields[i] = (FieldInfo)structInfoStack.Pop(); } return(structFields); }
// fieldInfo - the field who's value we want // objNode - the member node corresponding to the field // out topLevelObject - the object that contains the highest level // struct. // s/b protected, stupid compiler internal static FieldInfo[] GetStructFields (IObjectNode objNode, out Object topLevelObject) { Stack structInfoStack = new Stack(); IObjectNode parentObjNode; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor: " + objNode.ObjectInfo.ToString() + " node: " + objNode.ToString()); } // Build up the structFields array, the fields between the // top level object and the object we want to change while (true) { parentObjNode = objNode.ParentObjectNode; if (parentObjNode == null) { throw new Exception("(bug) hit no parent when " + "looking for enclosing object " + "for a struct " + objNode); } // This is an enclosing struct, push the field // information of how to get to the child here FieldInfo fi = parentObjNode.ObjType.GetField (objNode.ObjectInfo.ObjMemberInfo.Name, ReflectionHelper.ALL_BINDINGS); if (fi == null) { throw new Exception("(bug) field " + objNode.ObjType.Name + " not found in " + parentObjNode); } structInfoStack.Push(fi); // Found the containing object, either not a value // type, or this is not a field which means it can't // be inline any more if (!parentObjNode.ObjType.IsValueType || !(parentObjNode.ObjectInfo.ObjMemberInfo is FieldInfo)) break; // Go up objNode = parentObjNode; } // Ok, at this point, parent is the ObjectInfo for the // object that contains the top-level struct topLevelObject = parentObjNode.Obj; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - top level obj: " + topLevelObject); } int count = structInfoStack.Count; FieldInfo[] structFields = new FieldInfo[structInfoStack.Count]; for (int i = 0; i < count; i++) structFields[i] = (FieldInfo)structInfoStack.Pop(); return structFields; }
// fieldInfo - the field who's value we want // objNode - the member node corresponding to the field // out topLevelObject - the object that contains the highest level // struct. // s/b protected, stupid compiler internal static StructAccessor GetAccessorObject (IObjectNode objNode, out Object topLevelObject) { Stack structInfoStack = new Stack(); IObjectNode parentObjNode; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor: " + objNode.ObjectInfo.ToString() + " node: " + objNode.ToString()); } // Build up the structFields array, the fields between the // top level object and the object we want to change while (true) { parentObjNode = objNode.ParentObjectNode; if (parentObjNode == null) { throw new Exception("(bug) hit no parent when " + "looking for enclosing object " + "for a struct " + objNode); } // This is an enclosing struct, push the field // information of how to get to the child here FieldInfo fi = parentObjNode.ObjType.GetField (objNode.ObjectInfo.ObjMemberInfo.Name, ReflectionHelper.ALL_BINDINGS); if (fi == null) { throw new Exception("(bug) field " + objNode.ObjType.Name + " not found in " + parentObjNode); } structInfoStack.Push(fi); // Found the containing object, either not a value // type, or this is not a field which means it can't // be inline any more // FIXME - double check the member thing here, is this // the right level to check? if (!parentObjNode.ObjType.IsValueType || !(parentObjNode.ObjectInfo.ObjMemberInfo is FieldInfo)) { break; } // Go up objNode = parentObjNode; } // Ok, at this point, parent is the ObjectInfo for the // object that contains the top-level struct Type objType = parentObjNode.ObjType; topLevelObject = parentObjNode.Obj; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - top level type/obj: " + objType + "/" + topLevelObject); } int count = structInfoStack.Count; FieldInfo[] structFields = new FieldInfo[structInfoStack.Count]; for (int i = 0; i < count; i++) { structFields[i] = (FieldInfo)structInfoStack.Pop(); } StructAccessor vtAccessor; StringBuilder keyBuilder = new StringBuilder(); String key; keyBuilder.Append(objType.FullName); keyBuilder.Append("."); foreach (FieldInfo fi in structFields) { keyBuilder.Append(fi.Name); keyBuilder.Append("."); } key = keyBuilder.ToString(); if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - key: " + key); } lock (typeof(StructAccessor)) { vtAccessor = (StructAccessor)_accessors[key]; if (vtAccessor != null) { return(vtAccessor); } vtAccessor = new StructAccessor(); vtAccessor.MakeAccessorClass(key, objType, structFields); _accessors.Add(key, vtAccessor); return(vtAccessor); } }
// fieldInfo - the field who's value we want // objNode - the member node corresponding to the field // out topLevelObject - the object that contains the highest level // struct. // s/b protected, stupid compiler internal static StructAccessor GetAccessorObject (IObjectNode objNode, out Object topLevelObject) { Stack structInfoStack = new Stack(); IObjectNode parentObjNode; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor: " + objNode.ObjectInfo.ToString() + " node: " + objNode.ToString()); } // Build up the structFields array, the fields between the // top level object and the object we want to change while (true) { parentObjNode = objNode.ParentObjectNode; if (parentObjNode == null) { throw new Exception("(bug) hit no parent when " + "looking for enclosing object " + "for a struct " + objNode); } // This is an enclosing struct, push the field // information of how to get to the child here FieldInfo fi = parentObjNode.ObjType.GetField (objNode.ObjectInfo.ObjMemberInfo.Name, ReflectionHelper.ALL_BINDINGS); if (fi == null) { throw new Exception("(bug) field " + objNode.ObjType.Name + " not found in " + parentObjNode); } structInfoStack.Push(fi); // Found the containing object, either not a value // type, or this is not a field which means it can't // be inline any more // FIXME - double check the member thing here, is this // the right level to check? if (!parentObjNode.ObjType.IsValueType || !(parentObjNode.ObjectInfo.ObjMemberInfo is FieldInfo)) break; // Go up objNode = parentObjNode; } // Ok, at this point, parent is the ObjectInfo for the // object that contains the top-level struct Type objType = parentObjNode.ObjType; topLevelObject = parentObjNode.Obj; if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - top level type/obj: " + objType + "/" + topLevelObject); } int count = structInfoStack.Count; FieldInfo[] structFields = new FieldInfo[structInfoStack.Count]; for (int i = 0; i < count; i++) structFields[i] = (FieldInfo)structInfoStack.Pop(); StructAccessor vtAccessor; StringBuilder keyBuilder = new StringBuilder(); String key; keyBuilder.Append(objType.FullName); keyBuilder.Append("."); foreach (FieldInfo fi in structFields) { keyBuilder.Append(fi.Name); keyBuilder.Append("."); } key = keyBuilder.ToString(); if (TraceUtil.If(typeof(StructAccessor), TraceLevel.Info)) { TraceUtil.WriteLineInfo (typeof(StructAccessor), "GetAccessor - key: " + key); } lock (typeof(StructAccessor)) { vtAccessor = (StructAccessor)_accessors[key]; if (vtAccessor != null) return vtAccessor; vtAccessor = new StructAccessor(); vtAccessor.MakeAccessorClass(key, objType, structFields); _accessors.Add(key, vtAccessor); return vtAccessor; } }