示例#1
0
        private void SetPropertiesName(HashSet <Type> types)
        {
            foreach (var type in types)
            {
                if (!EntitiesPropertiesElementName.TryGetValue(type, out Dictionary <string, string> propDic))
                {
                    propDic = new Dictionary <string, string>();
                    EntitiesPropertiesElementName[type] = propDic;
                }

                var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                EntitiesProperties[type] = properties;

                foreach (var prop in properties)
                {
                    var igonre = prop.GetCustomAttribute <BsonIgnoreAttribute>();
                    if (igonre != null)
                    {
                        continue;
                    }

                    var element = prop.GetCustomAttribute <BsonElementAttribute>();
                    if (element == null)
                    {
                        propDic[prop.Name] = prop.Name;
                        continue;
                    }
                    propDic[prop.Name] = element.ElementName;
                }
            }
        }
示例#2
0
 private string GetElementName(Type type, string propertyName)
 {
     if (EntitiesPropertiesElementName.TryGetValue(type, out Dictionary <string, string> properties))
     {
         if (properties.TryGetValue(propertyName, out string name))
         {
             return(name);
         }
     }
     return(null);
 }