public List<IBaseClassIfc> ReadJSON(JObject ifcFile) { List<IBaseClassIfc> result = new List<IBaseClassIfc>(); JToken token = ifcFile.First; token = ifcFile["HEADER"]; token = ifcFile["DATA"]; JArray array = token as JArray; if (array != null) result = extractJArray<IBaseClassIfc>(array); else { IBaseClassIfc obj = ParseJObject<IBaseClassIfc>(ifcFile); if (obj != null) result.Add(obj); } return result; }
public T ParseJObject <T>(JObject obj) where T : IBaseClassIfc { if (obj == null) { return(default(T)); } BaseClassIfc result = null; JToken token = obj.GetValue("href", StringComparison.InvariantCultureIgnoreCase); if (token != null) { mDictionary.TryGetValue(token.Value <string>(), out result); if (result != null && obj.Count == 1) { return((T)(IBaseClassIfc)result); } } if (result == null) { Type type = null; token = obj.GetValue("type", StringComparison.InvariantCultureIgnoreCase); if (token != null) { string keyword = token.Value <string>(); type = Type.GetType("GeometryGym.Ifc." + keyword, false, true); } if (token == null) { type = typeof(T); } if (type != null) { if (type.IsAbstract) { JProperty jtoken = (JProperty)obj.First; Type valueType = Type.GetType("GeometryGym.Ifc." + jtoken.Name, false, true); if (valueType != null && valueType.IsSubclassOf(typeof(IfcValue))) { IBaseClassIfc val = ParserIfc.extractValue(jtoken.Name, jtoken.Value.ToString()) as IBaseClassIfc; if (val != null) { return((T)val); } return(default(T)); } } else { ConstructorInfo constructor = type.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (constructor != null) { bool common = false; result = constructor.Invoke(new object[] { }) as BaseClassIfc; if (result != null) { result.mDatabase = this; IfcCartesianPoint point = result as IfcCartesianPoint; if (point != null) { point.parseJObject(obj); if (point.isOrigin(Tolerance)) { if (point.is2D) { result = Factory.Origin2d; } else { result = Factory.Origin; } common = true; } } else { IfcDirection direction = result as IfcDirection; if (direction != null) { direction.parseJObject(obj); if (!direction.is2D) { common = true; if (direction.isXAxis) { result = Factory.XAxis; } else if (direction.isYAxis) { result = Factory.YAxis; } else if (direction.isZAxis) { result = Factory.ZAxis; } else if (direction.isXAxisNegative) { result = Factory.XAxisNegative; } else if (direction.isYAxisNegative) { result = Factory.YAxisNegative; } else if (direction.isZAxisNegative) { result = Factory.ZAxisNegative; } else { common = false; } } } else { IfcAxis2Placement3D placement = result as IfcAxis2Placement3D; if (placement != null) { placement.parseJObject(obj); if (placement.IsXYPlane(Tolerance)) { result = Factory.XYPlanePlacement; common = true; } } } } token = obj.GetValue("id", StringComparison.InvariantCultureIgnoreCase); if (token != null) { string id = token.Value <string>(); if (!(result is IfcRoot)) { result.setGlobalId(id); } mDictionary.TryAdd(id, result); } if (common) { return((T)(IBaseClassIfc)result); } int index = NextBlank(); this[index] = result; } } } } } if (result == null) { return(default(T)); } result.parseJObject(obj); parseBespoke(result, obj); IfcRoot root = result as IfcRoot; if (root != null) { mDictionary[root.GlobalId] = root; } return((T)(IBaseClassIfc)result); }