Beispiel #1
0
 static Environment CreateEnvironment(BuildConstants buildConstants)
 {
     return(new Environment(
                readText: fileName => File.ReadAllText(fileName),
                writeText: (fileName, text) => File.WriteAllText(fileName, text),
                buildConstants: buildConstants));
 }
Beispiel #2
0
        public static GeneratorResultCode Generate(
            ImmutableArray <string> files,
            BuildConstants buildConstants,
            Action <MetaError> reportError,
            Action <ImmutableArray <string> > reportOutputFiles)
        {
#if NETCORE
            System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += AssemblyResolving;
#else
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
#endif
            try {
                var result = Generator.Generate(files, CreateEnvironment(buildConstants));
                return(result.Match(
                           errors => {
                    foreach (var error in errors)
                    {
                        reportError(error);
                    }
                    return GeneratorResultCode.Error;
                },
                           outputFiles => {
                    reportOutputFiles(outputFiles);
                    return GeneratorResultCode.Success;
                }
                           ));
            } finally {
#if NETCORE
                AssemblyLoadContext.Default.Resolving -= AssemblyResolving;
#else
                AppDomain.CurrentDomain.AssemblyResolve -= CurrentDomain_AssemblyResolve;
#endif
            }
        }
Beispiel #3
0
 public Environment(
     Func <string, string> readText,
     Action <string, string> writeText,
     BuildConstants buildConstants)
 {
     ReadText       = readText;
     WriteText      = writeText;
     BuildConstants = buildConstants;
 }
Beispiel #4
0
        static string GetOutputDirectory(MetaLocation location, BuildConstants buildConstants)
        {
            switch (location)
            {
            case MetaLocation.IntermediateOutput:
                return(buildConstants.IntermediateOutputPath);

            case MetaLocation.Project:
                return(string.Empty);

            default:
                throw new InvalidOperationException();
            }
        }
Beispiel #5
0
 public MetaContext(
     string @namespace,
     IEnumerable <string> usings,
     BuildConstants constants,
     Func <string, MetaLocation?, OutputFileName> getOutputFileName,
     Func <string, string, MetaError> error,
     Func <IEnumerable <string>, IEnumerable <Attribute>, Either <IEnumerable <MetaError>, IEnumerable <Output> > > complete
     )
 {
     Namespace              = @namespace;
     Usings                 = usings;
     BuildConstants         = constants;
     this.getOutputFileName = getOutputFileName;
     this.error             = error;
     this.complete          = complete;
 }
Beispiel #6
0
        static string GetReferenceRelativePath(BuildConstants buildConsants, ReferenceRelativeLocation location)
        {
            switch (location)
            {
            case ReferenceRelativeLocation.Project:
                return(string.Empty);

            case ReferenceRelativeLocation.TargetPath:
                return(buildConsants.TargetPath);

            case ReferenceRelativeLocation.Framework:
                return(FrameworkPath);

            default:
                throw new InvalidOperationException();
            }
        }
Beispiel #7
0
 static ImmutableDictionary <string, string> GetMetaReferences(this CSharpCompilation compilation, BuildConstants buildConsants)
 {
     return(compilation
            .GetAttributeValues <MetaReferenceAttribute, Tuple <string, ReferenceRelativeLocation> >(values => values.ToValues <string, ReferenceRelativeLocation>())
            .Select(values => {
         var path = values.Item1;
         var location = values.Item2;
         var relativePath = GetReferenceRelativePath(buildConsants, location);
         return Path.Combine(relativePath, path);
     })
            .ToImmutableDictionary(x => Path.GetFileNameWithoutExtension(x), x => x));
 }