[ResourceConsumption(ResourceScope.Machine)] //For CheckArtifactExtension method call. But the path is not created in this method.
        internal static MetadataArtifactLoader Create(string path,
                                                      ExtensionCheck extensionCheck,
                                                      string validExtension,
                                                      ICollection <string> uriRegistry,
                                                      MetadataArtifactAssemblyResolver resolver)
        {
            Debug.Assert(path != null);
            Debug.Assert(resolver != null);

            // res:// -based artifacts
            //
            if (MetadataArtifactLoader.PathStartsWithResPrefix(path))
            {
                return(MetadataArtifactLoaderCompositeResource.CreateResourceLoader(path, extensionCheck, validExtension, uriRegistry, resolver));
            }

            // Files and Folders
            //
            string normalizedPath = MetadataArtifactLoader.NormalizeFilePaths(path);

            if (Directory.Exists(normalizedPath))
            {
                return(new MetadataArtifactLoaderCompositeFile(normalizedPath, uriRegistry));
            }
            else if (File.Exists(normalizedPath))
            {
                switch (extensionCheck)
                {
                case ExtensionCheck.Specific:
                    CheckArtifactExtension(normalizedPath, validExtension);
                    break;

                case ExtensionCheck.All:
                    if (!MetadataArtifactLoader.IsValidArtifact(normalizedPath))
                    {
                        throw EntityUtil.Metadata(Strings.InvalidMetadataPath);
                    }
                    break;
                }

                return(new MetadataArtifactLoaderFile(normalizedPath, uriRegistry));
            }

            throw EntityUtil.Metadata(Strings.InvalidMetadataPath);
        }
        private static void ValidateExtension(ExtensionCheck extensionCheck, string validExtension, string resourceName)
        {
            if (resourceName == null)
            {
                return;
            }

            // the supplied path represents a single resource
            //
            switch (extensionCheck)
            {
            case ExtensionCheck.Specific:
                MetadataArtifactLoader.CheckArtifactExtension(resourceName, validExtension);
                break;

            case ExtensionCheck.All:
                if (!MetadataArtifactLoader.IsValidArtifact(resourceName))
                {
                    throw EntityUtil.Metadata(Strings.InvalidMetadataPath);
                }
                break;
            }
        }