internal static IfcValue extractValue(XmlNode node) { string name = node.Name; if (name.EndsWith("-wrapper")) { name = name.Substring(0, name.Length - 8); return(ParserIfc.extractValue(name, node.InnerText)); } return(null); }
internal static IfcValue ParseValue(JObject obj) { JProperty token = (JProperty)obj.First; return(ParserIfc.extractValue(token.Name, token.Value.ToString())); }
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))) { return((T)(IBaseClassIfc)ParserIfc.extractValue(jtoken.Name, jtoken.Value.ToString())); } } 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) { 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) { result = Factory.XYPlanePlacement; common = true; } } } } token = obj.GetValue("id", StringComparison.InvariantCultureIgnoreCase); if (token != null) { string id = token.Value <string>(); if (!(result is IfcRoot)) { result.mGlobalId = 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); }
public T ParseJObject<T>(JObject obj) where T : IBaseClassIfc { if (obj == null) return default(T); Type type = typeof(T); BaseClassIfc result = null; JToken token = obj.GetValue("href", StringComparison.InvariantCultureIgnoreCase); if (token != null) { string hrefId = token.Value<string>(); if(mDictionary.TryGetValue(hrefId, out result) && obj.Count == 1) return (T)(IBaseClassIfc)result; } if (result == null) { if (type.IsAbstract) { JProperty jtoken = (JProperty)obj.First; Type valueType = BaseClassIfc.GetType(jtoken.Name); 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 { token = obj.GetValue("type", StringComparison.InvariantCultureIgnoreCase); if(token != null) { Type nominatedType = BaseClassIfc.GetType(token.Value<string>()); if (nominatedType != null) type = nominatedType; } string hrefId = ""; token = obj.GetValue("id", StringComparison.InvariantCultureIgnoreCase); if (token != null) hrefId = token.Value<string>(); if (string.IsNullOrEmpty(hrefId) || !mDictionary.TryGetValue(hrefId, out result)) { 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 (!string.IsNullOrEmpty(hrefId)) { if (!(result is IfcRoot)) result.setGlobalId(hrefId); mDictionary.TryAdd(hrefId, 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; }