internal virtual BuildResult CreateBuildResult(CompilerResults results)
        {
            BuildResult result;

            if (this.flags[2])
            {
                return(null);
            }
            if (!BuildManagerHost.InClientBuildManager && (results != null))
            {
                Assembly compiledAssembly = results.CompiledAssembly;
            }
            Type generatedType = this.GetGeneratedType(results);

            if (generatedType != null)
            {
                BuildResultCompiledType type2 = this.CreateBuildResult(generatedType);
                if (!type2.IsDelayLoadType && ((results == null) || (generatedType.Assembly != results.CompiledAssembly)))
                {
                    type2.UsesExistingAssembly = true;
                }
                result = type2;
            }
            else
            {
                string customString = this.GetCustomString(results);
                if (customString != null)
                {
                    result = new BuildResultCustomString(this.flags[0x20] ? results.CompiledAssembly : null, customString);
                }
                else
                {
                    if (results == null)
                    {
                        return(null);
                    }
                    result = new BuildResultCompiledAssembly(results.CompiledAssembly);
                }
            }
            int resultFlags = (int)this.GetResultFlags(results);

            if (resultFlags != 0)
            {
                resultFlags  &= 0xffff;
                result.Flags |= resultFlags;
            }
            return(result);
        }
 internal virtual BuildResult CreateBuildResult(CompilerResults results)
 {
     BuildResult result;
     if (this.flags[2])
     {
         return null;
     }
     if (!BuildManagerHost.InClientBuildManager && (results != null))
     {
         Assembly compiledAssembly = results.CompiledAssembly;
     }
     Type generatedType = this.GetGeneratedType(results);
     if (generatedType != null)
     {
         BuildResultCompiledType type2 = this.CreateBuildResult(generatedType);
         if (!type2.IsDelayLoadType && ((results == null) || (generatedType.Assembly != results.CompiledAssembly)))
         {
             type2.UsesExistingAssembly = true;
         }
         result = type2;
     }
     else
     {
         string customString = this.GetCustomString(results);
         if (customString != null)
         {
             result = new BuildResultCustomString(this.flags[0x20] ? results.CompiledAssembly : null, customString);
         }
         else
         {
             if (results == null)
             {
                 return null;
             }
             result = new BuildResultCompiledAssembly(results.CompiledAssembly);
         }
     }
     int resultFlags = (int) this.GetResultFlags(results);
     if (resultFlags != 0)
     {
         resultFlags &= 0xffff;
         result.Flags |= resultFlags;
     }
     return result;
 }
        internal static BuildResult CreateBuildResultFromCode(BuildResultTypeCode code, System.Web.VirtualPath virtualPath)
        {
            BuildResult result = null;

            switch (code)
            {
            case BuildResultTypeCode.BuildResultCompiledAssembly:
                result = new BuildResultCompiledAssembly();
                break;

            case BuildResultTypeCode.BuildResultCompiledType:
                result = new BuildResultCompiledType();
                break;

            case BuildResultTypeCode.BuildResultCompiledTemplateType:
                result = new BuildResultCompiledTemplateType();
                break;

            case BuildResultTypeCode.BuildResultCustomString:
                result = new BuildResultCustomString();
                break;

            case BuildResultTypeCode.BuildResultMainCodeAssembly:
                result = new BuildResultMainCodeAssembly();
                break;

            case BuildResultTypeCode.BuildResultCodeCompileUnit:
                result = new BuildResultCodeCompileUnit();
                break;

            case BuildResultTypeCode.BuildResultCompiledGlobalAsaxType:
                result = new BuildResultCompiledGlobalAsaxType();
                break;

            case BuildResultTypeCode.BuildResultResourceAssembly:
                result = new BuildResultResourceAssembly();
                break;

            default:
                return(null);
            }
            result.VirtualPath        = virtualPath;
            result._nextUpToDateCheck = DateTime.MinValue;
            return(result);
        }
    #pragma warning restore 0649

    internal static BuildResult CreateBuildResultFromCode(BuildResultTypeCode code,
        VirtualPath virtualPath) {

        BuildResult ret = null;

        switch (code) {
            case BuildResultTypeCode.BuildResultCompiledAssembly:
                ret = new BuildResultCompiledAssembly();
                break;

            case BuildResultTypeCode.BuildResultCompiledType:
                ret = new BuildResultCompiledType();
                break;

            case BuildResultTypeCode.BuildResultCompiledTemplateType:
                ret = new BuildResultCompiledTemplateType();
                break;

            case BuildResultTypeCode.BuildResultCompiledGlobalAsaxType:
                ret = new BuildResultCompiledGlobalAsaxType();
                break;

            case BuildResultTypeCode.BuildResultCustomString:
                ret = new BuildResultCustomString();
                break;

            case BuildResultTypeCode.BuildResultMainCodeAssembly:
                ret = new BuildResultMainCodeAssembly();
                break;

            case BuildResultTypeCode.BuildResultResourceAssembly:
                ret = new BuildResultResourceAssembly();
                break;

            case BuildResultTypeCode.BuildResultCodeCompileUnit:
                ret = new BuildResultCodeCompileUnit();
                break;

            default:
                Debug.Assert(false, "code=" + code);
                return null;
        }

        ret.VirtualPath = virtualPath;

        // Set _nextUpToDateCheck to MinValue, to make sure the next call to IsUpToDate()
        // actually makes the check
        ret._nextUpToDateCheck = DateTime.MinValue;

        return ret;
    }
        internal virtual BuildResult CreateBuildResult(CompilerResults results)
        {
            // If the build provider is not supposed to have a build result, just return
            if (flags[noBuildResult])
            {
                return(null);
            }

            // Access the CompiledAssembly property to make sure the assembly gets loaded
            // Otherwise, the user code in GetGeneratedType() will fail to load it in medium trust since
            // they don't have access to the codegen folder
            if (!BuildManagerHost.InClientBuildManager && results != null)
            {
                // The ClientBuildManager runs in full trust, so we skip this statement
                // to avoid unnecessary loading of the assembly.
                var assembly = results.CompiledAssembly;
            }

            // Ask the build provider if it wants to persist a Type
            Type type = GetGeneratedType(results);

            BuildResult result;

            if (type != null)
            {
                // Create a BuildResult for it
                BuildResultCompiledType resultCompiledType = CreateBuildResult(type);

                if (!resultCompiledType.IsDelayLoadType)
                {
                    // If the returned type doesn't come from the generated assembly, set a flag
                    if (results == null || type.Assembly != results.CompiledAssembly)
                    {
                        resultCompiledType.UsesExistingAssembly = true;
                    }
                }

                result = resultCompiledType;
            }
            else
            {
                // Ask the build provider if it instead wants to persist a custom string
                string customString = GetCustomString(results);

                // If it does, persist it
                if (customString != null)
                {
                    // Only preserve an assembly if the BuildProvider has actually contributed code
                    // to the compilation.
                    result = new BuildResultCustomString(
                        flags[contributedCode] ? results.CompiledAssembly : null,
                        customString);
                }
                else
                {
                    // Nothing was built: nothing to persist
                    if (results == null)
                    {
                        return(null);
                    }

                    // Otherwise, just persist the assembly, if any
                    result = new BuildResultCompiledAssembly(results.CompiledAssembly);
                }
            }

            // Ask the provider it it wants to set some flags on the result
            int resultFlags = (int)GetResultFlags(results);

            if (resultFlags != 0)
            {
                // Make sure only the lower bits are set
                Debug.Assert((resultFlags & 0xFFFF0000) == 0);
                resultFlags &= 0x0000FFFF;

                result.Flags |= resultFlags;
            }

            return(result);
        }
    internal virtual BuildResult CreateBuildResult(CompilerResults results) {

        // If the build provider is not supposed to have a build result, just return
        if (flags[noBuildResult])
            return null;

        // Access the CompiledAssembly property to make sure the assembly gets loaded
        // Otherwise, the user code in GetGeneratedType() will fail to load it in medium trust since
        // they don't have access to the codegen folder
        if (!BuildManagerHost.InClientBuildManager && results != null) {
            // The ClientBuildManager runs in full trust, so we skip this statement 
            // to avoid unnecessary loading of the assembly.
            var assembly = results.CompiledAssembly;
        }

        // Ask the build provider if it wants to persist a Type
        Type type = GetGeneratedType(results);

        BuildResult result;

        if (type != null) {
            // Create a BuildResult for it
            BuildResultCompiledType resultCompiledType = CreateBuildResult(type);

            if (!resultCompiledType.IsDelayLoadType) {
                // If the returned type doesn't come from the generated assembly, set a flag
                if (results == null || type.Assembly != results.CompiledAssembly)
                    resultCompiledType.UsesExistingAssembly = true;
            }

            result = resultCompiledType;
        }
        else {
            // Ask the build provider if it instead wants to persist a custom string
            string customString = GetCustomString(results);

            // If it does, persist it
            if (customString != null) {
                // Only preserve an assembly if the BuildProvider has actually contributed code
                // to the compilation.
                result = new BuildResultCustomString(
                    flags[contributedCode] ? results.CompiledAssembly : null,
                    customString);
            }
            else {
                // Nothing was built: nothing to persist
                if (results == null)
                    return null;

                // Otherwise, just persist the assembly, if any
                result = new BuildResultCompiledAssembly(results.CompiledAssembly);
            }
        }

        // Ask the provider it it wants to set some flags on the result
        int resultFlags = (int) GetResultFlags(results);
        if (resultFlags != 0) {
            // Make sure only the lower bits are set
            Debug.Assert((resultFlags & 0xFFFF0000) == 0);
            resultFlags &= 0x0000FFFF;

            result.Flags |= resultFlags;
        }

        return result;
    }