private void SetReferenceToProperty(CIMObject element, object something, string attValue, PropertyInfo prop, ConcreteModel model) { if (!string.IsNullOrEmpty(attValue)) { Type referencedType = prop.PropertyType; string referencedID = StringManipulationManager.ExtractAllAfterSeparator(attValue, StringManipulationManager.SeparatorSharp); object referencedObject = model.GetObjectByID(referencedID); if (referencedObject == null) { if (!(referencedType.GetProperty("Value") != null && referencedType.GetProperty("Multiplier") != null && referencedType.GetProperty("Unit") != null) && referencedType.Name != "AbsoluteDate") { OnMessage("Referenced object on property: " + prop.DeclaringType + "." + prop.Name + ", elements ID:" + element.ID + " not in model. Referenced: " + referencedType.ToString() + ", ID:" + referencedID , MessageLevel.WARNING); string propertyType = StringManipulationManager.ExtractAllAfterSeparator(referencedType.FullName, StringManipulationManager.SeparatorDot); } //otherwise its DataType and its already set } else { if (referencedObject.GetType().Equals(referencedType) || referencedObject.GetType().IsSubclassOf(referencedType)) { prop.SetValue(something, referencedObject, null); } else { string referencedObjectType = StringManipulationManager.ExtractAllAfterSeparator(referencedObject.GetType().FullName, StringManipulationManager.SeparatorDot); string propertyType = StringManipulationManager.ExtractAllAfterSeparator(referencedType.FullName, StringManipulationManager.SeparatorDot); } } } }
/// <summary> /// Method adds reference to list on property prop /// </summary> /// <param name="list">list that reference will be added to</param> /// <param name="att">attribute containing information about reference</param> /// <param name="prop">property containing list</param> private void AddReferenceToList(CIMObject element, ref IList list, string attValue, PropertyInfo prop, ConcreteModel model) { if (!string.IsNullOrEmpty(attValue)) { Type referencedType = prop.PropertyType; string referencedID = StringManipulationManager.ExtractAllAfterSeparator(attValue, StringManipulationManager.SeparatorSharp); string refType = referencedType.ToString(); if (referencedType.IsGenericType) { refType = referencedType.GetGenericArguments()[0].ToString(); } //DataTypes? what about them if in list - should be a way to determine object referencedObject = model.GetObjectByID(referencedID); if (referencedObject != null) { try { list.Add(referencedObject); } catch { OnMessage("Unsuccessful adding item to list on property: " + prop.DeclaringType + "." + prop.Name + ", elements ID:" + element.ID + " Referenced: " + refType + ", ID: " + referencedID , MessageLevel.ERROR); string referencedTypeWithoutPrefix = StringManipulationManager.ExtractAllAfterSeparator(refType, StringManipulationManager.SeparatorDot); } } else { OnMessage("Referenced object on property: " + prop.DeclaringType + "." + prop.Name + ", elements ID:" + element.ID + " not in model. Referenced: " + refType + ", ID:" + referencedID , MessageLevel.WARNING); string referencedTypeWithoutPrefix = StringManipulationManager.ExtractAllAfterSeparator(refType, StringManipulationManager.SeparatorDot); } } }