Ejemplo n.º 1
0
        /// <summary>
        /// Sets the explicit construction method for the <see cref="TType"/>.
        /// </summary>
        /// <param name="constructor">The construction method.</param>
        /// <typeparam name="TType">The type to set the explicit construction method.</typeparam>
        /// <returns><see langword="true"/> if the constructor was set; otherwise, <see langword="false"/>.</returns>
        public static bool TrySetExplicitConstructionMethod <TType>(ConstructorMethod <TType> constructor)
        {
            if (TypeConstructionCache.HasExplicitConstruction <TType>())
            {
                return(false);
            }

            TypeConstructionCache.SetExplicitConstruction(constructor);
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Un-sets the explicit construction method for the <see cref="TType"/> type.
        /// </summary>
        /// <remarks>
        /// An explicit construction method can only be unset if it was previously set with the same instance.
        /// </remarks>
        /// <param name="constructor">The construction method.</param>
        /// <typeparam name="TType">The type to set the explicit construction method.</typeparam>
        /// <returns><see langword="true"/> if the constructor was unset; otherwise, <see langword="false"/>.</returns>
        public static bool TryUnsetExplicitConstructionMethod <TType>(ConstructorMethod <TType> constructor)
        {
            if (TypeConstructionCache.GetExplicitConstruction <TType>() != constructor)
            {
                return(false);
            }

            TypeConstructionCache.SetExplicitConstruction <TType>(null);
            return(true);
        }
Ejemplo n.º 3
0
 static void RegisterBuiltInConstructors()
 {
     TypeConstructionCache.SetExplicitConstruction(() => string.Empty);
 }