예제 #1
0
 public ReferenceMapInfo GetReferencesMap(string referenceName)
 {
     if (ReferencesMap.ContainsKey(referenceName))
     {
         return(ReferencesMap[referenceName]);
     }
     if (_baseModelMap != null)
     {
         return(_baseModelMap.GetReferencesMap(referenceName));
     }
     return(null);
 }
예제 #2
0
        public static Dictionary <string, object> GetModelValues <TModel>(TModel model)
        {
            //TODO:Tratar exceções
            Type     modelType = model.GetType();
            ModelMap modelMap  = ModelMap.GetModelMap(modelType);
            Dictionary <string, object> modelValues = new Dictionary <string, object>();

            foreach (string propertyName in modelMap.GetPropertiesNamesList())
            {
                try
                {
                    object value = modelType.GetProperty(propertyName).GetValue(model, null);
                    if (value != null && modelMap.GetColumnMap(propertyName).DataType == DataAnnotations.ERBridge.DataType.Xml)
                    {
                        XmlDocument xml = new XmlDocument();
                        xml.InnerXml = Commons.Utilities.ClassToXML.SerializeObject(value, propertyName);
                        value        = xml.FirstChild.InnerXml;
                    }
                    else if (modelMap.GetColumnMap(propertyName).DataType == DataAnnotations.ERBridge.DataType.DateTime && DateTime.MinValue.Equals(value))
                    {
                        value = null;
                    }

                    ReferenceMapInfo referenceMap = modelMap.GetReferencesMap(propertyName);
                    if (value != null && referenceMap != null)
                    {
                        object keyValue = value.GetType().GetProperty(referenceMap.ReferenceKey).GetValue(value, null);
                        modelValues.Add(propertyName + "." + referenceMap.ReferenceKey, keyValue);
                    }
                    else
                    {
                        modelValues.Add(propertyName, value);
                    }
                }
                catch (Exception ex) {
                    Commons.Utilities.Logger.Error(ex);
                }
            }
            return(modelValues);
        }