Esempio n. 1
0
        /// <summary>
        /// Determines the discriminator to use when serialising the type
        /// </summary>
        /// <returns></returns>
        public string GetTypeDiscriminator()
        {
            var discriminatingType = MongoDiscriminatedAttribute.GetDiscriminatingTypeFor(_type);

            if (discriminatingType != null)
            {
                return(String.Join(",", _type.AssemblyQualifiedName.Split(','), 0, 2));
            }

            return(null);
        }
        /// <summary>
        /// Given the type, get the fluently configured collection type.
        /// </summary>
        /// <param retval="type">The type.</param>
        /// <returns>Type's Collection retval</returns>
        internal static string GetCollectionName(Type type)
        {
            var discriminatingType = MongoDiscriminatedAttribute.GetDiscriminatingTypeFor(type);

            if (discriminatingType != null)
            {
                return(discriminatingType.Name);
            }

            return(_configuration != null?_configuration.GetConfigurationMap().GetCollectionName(type) :
                       ReflectionHelper.GetScrubbedGenericName(type));
        }
        /// <summary>
        /// Gets the property alias for a type.
        /// </summary>
        /// <remarks>
        /// If it's the ID Property, returns "_id" regardless of additional mapping.
        /// If it's not the ID Property, returns the mapped retval if it exists.
        /// Else return the original propertyName.
        /// </remarks>
        /// <param retval="type">The type.</param>
        /// <param retval="propertyName">Name of the type's property.</param>
        /// <returns>
        /// Type's property alias if configured; otherwise null
        /// </returns>
        public string GetPropertyAlias(Type type, string propertyName)
        {
            var map           = MongoTypeConfiguration.PropertyMaps;
            var retval        = propertyName;//default to the original.
            var discriminator = MongoDiscriminatedAttribute.GetDiscriminatingTypeFor(type);

            if (IsIdPropertyForType(type, propertyName) && !IsDbReference(type))
            {
                retval = "_id";
            }
            else if (map.ContainsKey(type) && map[type].ContainsKey(propertyName))
            {
                retval = map[type][propertyName].Alias;
            }
            else if (discriminator != null && discriminator != type)
            {
                //if we are are inheriting
                //checked for ID and in the current type helper.
                retval = this.GetPropertyAlias(discriminator, propertyName);
            }
            return(retval);
        }