Example #1
0
 public void AddRootGroup(IRootGroup group)
 {
     if (group is RootGroup rootGroup && !rootGroups.Contains(rootGroup))
     {
         rootGroups.Add(rootGroup);
     }
 }
        private IDictionary <string, string> CreateOutputStrings(IRootGroup rootGroup, string outputRootDirectory)
        {
            var ret = new Dictionary <string, string>();
            // TODO: Allow filtering to limit the breadth of generation
            var templateMaps = MakeTemplateMaps();
            var distinct     = templateMaps
                               .Select(x => new
            {
                x.EntryPointType,
                x.MetadataLoader,
                childProperty = x.ChildProperty,
                childType     = x.ChildProperty == null
                                             ? null
                                             : x.ChildProperty.PropertyType.GenericTypeArguments.First(),
                x.AttributeIdentifier
            })
                               .Distinct()
                               .ToList();

            foreach (var set in distinct)
            {
                var newDict = ReflectionHelpers.InvokeGenericMethod(typeof(TemplateRunnerBase).GetTypeInfo(), "CreateOutputStringsCore",
                                                                    set.EntryPointType, this,
                                                                    rootGroup, outputRootDirectory, set.MetadataLoader, set.childProperty, set.childType, set.AttributeIdentifier, templateMaps)
                              as IDictionary <string, string>;
                foreach (var pair in newDict)
                {
                    ret.Add(pair.Key, pair.Value);
                }
            }
            return(ret);
        }
        private IDictionary <string, string> CreateOutputStringsCore <TLocal>(IRootGroup rootGroup, string outputRootDirectory,
                                                                              IMetadataLoader <TLocal> metadataLoader, PropertyInfo childProperty, Type childPropertyType, string attributeIdentifier, IEnumerable <TemplateMap> templateMaps)
            where TLocal : CodeFirstMetadata <TLocal>
        {
            var newDict      = new Dictionary <string, string>();
            var metadataList = GetMetadata(attributeIdentifier, metadataLoader, rootGroup.Roots);

            IEnumerable <CodeFirstMetadata> candidates;

            if (childPropertyType != null)
            {
                candidates = metadataList
                             .Where(x => x != null)
                             .SelectMany(x => (childProperty.GetValue(x) as IEnumerable <CodeFirstMetadata>)).ToList();
            }
            else
            {
                candidates = metadataList.Where(x => x.GetType().FullName == typeof(TLocal).FullName);
            }
            if (candidates.Any())
            {
                foreach (var candidate in candidates)
                {
                    var candidateMaps = templateMaps;
                    //.Where(x => x.EntryPointType == typeof(T));
                    foreach (var candidateMap in candidateMaps)
                    {
                        var firstNamespace = candidate
                                             .AncestorsAndSelf
                                             .OfType <ICodeFirstMetadataNamespace>()
                                             .FirstOrDefault();
                        var inFileName = firstNamespace == null
                                      ? null
                                      : firstNamespace.FilePath;
                        // TODO: This is wrong so I can test the rest of the system
                        var outFileName = Path.Combine(Path.GetDirectoryName(inFileName), Path.GetFileNameWithoutExtension(inFileName)) + ".g.cs";
                        var genericChildPropertyType = candidateMap.ChildProperty == null
                                                 ? null
                                                 : candidateMap.ChildProperty.PropertyType.GenericTypeArguments.FirstOrDefault();
                        var templateType = genericChildPropertyType != null
                                        ? genericChildPropertyType
                                        : candidateMap.EntryPointType;
                        var outText = ReflectionHelpers.InvokeGenericMethod(typeof(TemplateRunnerBase).GetTypeInfo(), "CreateOutputString",
                                                                            templateType, this,
                                                                            candidateMap.Template, candidate)
                                      as string;
                        newDict.Add(outFileName, outText);
                    }
                }
                //newDict = ReflectionHelpers.InvokeGenericMethod(this.GetType().GetTypeInfo(), "CreateOutputStringsGeneric",
                //                          typeof(TLocal), this,
                //                          candidates, templateMaps,metadataLoader, outputRootDirectory)
                //                       as Dictionary<string, string>;
            }
            return(newDict);
        }
Example #4
0
        public XDocument CreateStylesheet(IRootGroup rootGroup)
        {
            var configuration = new TransformBuilderConfiguration
            {
                OutputType       = rootGroup.OutputType,
                FormatXml        = true,
                IgnoreWhitespace = true
            };
            var builder = new TransformBuilder.TransformBuilder(configuration);

            CreateKeyElements(builder, rootGroup);
            CreateTemplateElements(builder, rootGroup);

            return(builder.Build());
        }
Example #5
0
 public abstract bool OutputToFiles(out string[] outputFiles, IRootGroup rootGroup, params string[] sources);
Example #6
0
 public IEnumerable <SyntaxTree> GetCompilation(IRootGroup rootGroup)
 {
     throw new NotImplementedException();
 }
 public IEnumerable<SyntaxTree> GetCompilation(IRootGroup rootGroup)
 {
     throw new NotImplementedException();
 }
 public abstract bool OutputToFiles(out string[] outputFiles, IRootGroup rootGroup, params string[] sources);