예제 #1
0
        private ITaskItem GenerateCodeFile(ITaskItem item, ITypeParser typeParser, XamlItemType itemType)
        {
            XamlElement xamlElement = XamlParser.Parse(File.ReadAllText(item.GetMetadata("FullPath")));

            ClassDefinition classDefinition = XamlClassParser.Parse(xamlElement, typeParser);

            if (classDefinition == null)
            {
                return(null);
            }

            CodeTypeDeclaration classDeclaration = classDefinition.CreateClassDeclaration();

            classDeclaration.CustomAttributes.Add(new CodeAttributeDeclaration("Bridge.Reflectable",
                                                                               new CodeAttributeArgument(new CodeSnippetExpression("Bridge.MemberAccessibility.InstanceMethod")),
                                                                               new CodeAttributeArgument(new CodeSnippetExpression("Bridge.MemberAccessibility.InstanceField"))));

            string itemRelativePath = item.GetRelativePath().Replace("\\", "/");
            string resourceUri      = String.Format("pack://application:,,,/{0};component/{1}", TargetName, itemRelativePath);

            classDeclaration.Members.Add(CreateInitializeComponentMethod(resourceUri));

            if (itemType == XamlItemType.XamlApplicationDefinition)
            {
                classDeclaration.Members.Add(CreateEntryPointMethod(classDefinition.Name));
            }

            CodeNamespace classNamespace = new CodeNamespace(classDefinition.Namespace);

            classNamespace.Types.Add(classDeclaration);

            CodeCompileUnit classCompileUnit = new CodeCompileUnit();

            classCompileUnit.Namespaces.Add(classNamespace);

            string targetDirectory = Path.GetDirectoryName(Path.Combine(IntermediateOutputPath, item.GetMetadata("Link").DefaultIfNullOrEmpty(item.GetMetadata("Identity"))));

            Directory.CreateDirectory(targetDirectory);

            string targetFileName = String.Format("{0}.g{1}{2}", item.GetMetadata("Filename"), item.GetMetadata("Extension"), LanguageSourceExtension);

            return(GenerateCodeFile(classCompileUnit, Path.Combine(targetDirectory, targetFileName)));
        }
예제 #2
0
        private ITaskItem GenerateCodeFile(ITaskItem item, ITypeParser typeParser, XamlItemType itemType)
        {
            XamlElement xamlElement = XamlParser.Parse(File.ReadAllText(item.GetMetadata("FullPath")));

            ClassDefinition classDefinition = XamlClassParser.Parse(xamlElement, typeParser);

            if (classDefinition == null)
            {
                return(null);
            }

            CodeTypeDeclaration classDeclaration = classDefinition.CreateClassDeclaration();

            string itemRelativePath = item.GetRelativePath().Replace("\\", "/");
            string resourceUri      = String.Format("/{0};component/{1}", TargetName, itemRelativePath);

            classDeclaration.Members.Add(CreateInitializeComponentMethod(resourceUri));

            if (itemType == XamlItemType.XamlApplicationDefinition)
            {
                classDeclaration.Members.Add(CreateEntryPointMethod(classDefinition.Name));
            }

            CodeNamespace classNamespace = new CodeNamespace(classDefinition.Namespace);

            classNamespace.Types.Add(classDeclaration);

            CodeCompileUnit classCompileUnit = new CodeCompileUnit();

            classCompileUnit.Namespaces.Add(classNamespace);

            string targetDirectory = Path.Combine(IntermediateOutputPath, item.GetMetadata("RelativeDir"));

            Directory.CreateDirectory(targetDirectory);

            string targetFileName = String.Format("{0}.g{1}{2}", item.GetMetadata("Filename"), item.GetMetadata("Extension"), LanguageSourceExtension);

            return(GenerateCodeFile(classCompileUnit, Path.Combine(targetDirectory, targetFileName)));
        }