コード例 #1
0
        private void usc_CodeViewer_RenameButtonClicked(object sender, RenameButtonClickedEventArgs e)
        {
            ClassInfoTreeNode node = e.SelectedNode;

            if (node.JInfo is JArrayInfo)
            {
                return;
            }

            ClassInfoTreeNode parent = (ClassInfoTreeNode)node.Parent;

            InputBox inputBox = new InputBox();

            if (inputBox.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            string inputString = inputBox.InputString;

            node.JInfo.Type = inputString;

            if (parent != null)
            {
                SetParentClassCode(parent, inputString);
            }

            node.Text = node.JInfo.ToString();
            ClassCodeGenerator.GenerateClassCode((JClassInfo)node.JInfo, _declareOption, _formatString);
            node.ClassCode = ((JClassInfo)node.JInfo).ClassCode;


            usc_CodeViewer.SetCodeText(node.ClassCode);
        }
コード例 #2
0
        public void Build_CreatesClassWithCompleteContentType()
        {
            var classDefinition = new ClassDefinition("Complete content type");

            classDefinition.AddProperty(Property.FromContentType("text", "text"));
            classDefinition.AddProperty(Property.FromContentType("rich_text", "rich_text"));
            classDefinition.AddProperty(Property.FromContentType("rich_text_structured", "rich_text(structured)"));
            classDefinition.AddProperty(Property.FromContentType("number", "number"));
            classDefinition.AddProperty(Property.FromContentType("multiple_choice", "multiple_choice"));
            classDefinition.AddProperty(Property.FromContentType("date_time", "date_time"));
            classDefinition.AddProperty(Property.FromContentType("asset", "asset"));
            classDefinition.AddProperty(Property.FromContentType("modular_content", "modular_content"));
            classDefinition.AddProperty(Property.FromContentType("taxonomy", "taxonomy"));
            classDefinition.AddProperty(Property.FromContentType("url_slug", "url_slug"));

            classDefinition.AddSystemProperty();

            var classCodeGenerator = new ClassCodeGenerator(classDefinition, classDefinition.ClassName);

            string compiledCode = classCodeGenerator.GenerateCode();

            string executingPath = AppContext.BaseDirectory;
            string expectedCode  = File.ReadAllText(executingPath + "/Assets/CompleteContentType_CompiledCode.txt");

            Assert.Equal(expectedCode, compiledCode, ignoreWhiteSpaceDifferences: true, ignoreLineEndingDifferences: true);
        }
コード例 #3
0
        private void SetNode(ClassInfoTreeNode node)
        {
            #region
            if (node.JInfo is JClassInfo)
            {
                ClassCodeGenerator.GenerateClassCode((JClassInfo)node.JInfo, _declareOption, _formatString);
                node.ClassCode = ((JClassInfo)node.JInfo).ClassCode;

                foreach (JInfo item in ((JClassInfo)node.JInfo).Properties)
                {
                    if (item is JClassInfo || item is JArrayInfo)
                    {
                        ClassInfoTreeNode childNode = new ClassInfoTreeNode(item);

                        node.Nodes.Add(childNode);

                        SetNode(childNode);
                    }
                }
            }
            else if (node.JInfo is JArrayInfo)
            {
                foreach (JClassInfo item in ((JArrayInfo)node.JInfo).ClassTypes)
                {
                    ClassInfoTreeNode childNode = new ClassInfoTreeNode(item);
                    node.Nodes.Add(childNode);

                    SetNode(childNode);
                }
            }
            #endregion
        }
コード例 #4
0
 private static void AssertClassCodeGenerator <T>(ClassCodeGenerator result, string classDefinitionCodename, string classFileName, string @namespace)
 {
     Assert.IsType <T>(result);
     Assert.Equal(classDefinitionCodename, result.ClassDefinition.Codename);
     Assert.Equal(classFileName, result.ClassFilename);
     Assert.Equal(@namespace, result.Namespace);
 }
コード例 #5
0
        public void Constructor_ReplacesNullNamespaceWithDefault()
        {
            var classDefinition    = new ClassDefinition("codename");
            var classCodeGenerator = new ClassCodeGenerator(classDefinition, null);

            Assert.Equal("KenticoCloudModels", classCodeGenerator.Namespace);
        }
コード例 #6
0
        public void IntegrationTest_GeneratedCodeCompilesWithoutErrors()
        {
            var definition = new ClassDefinition("Complete content type");

            definition.AddProperty(Property.FromContentType("text", "text"));
            definition.AddProperty(Property.FromContentType("rich_text", "rich_text"));
            definition.AddProperty(Property.FromContentType("rich_text_structured", "rich_text(structured)"));
            definition.AddProperty(Property.FromContentType("number", "number"));
            definition.AddProperty(Property.FromContentType("multiple_choice", "multiple_choice"));
            definition.AddProperty(Property.FromContentType("date_time", "date_time"));
            definition.AddProperty(Property.FromContentType("asset", "asset"));
            definition.AddProperty(Property.FromContentType("modular_content", "modular_content"));
            definition.AddProperty(Property.FromContentType("taxonomy", "taxonomy"));
            definition.AddProperty(Property.FromContentType("custom", "custom"));

            var    classCodeGenerator = new ClassCodeGenerator(definition, definition.ClassName);
            string compiledCode       = classCodeGenerator.GenerateCode();

            CSharpCompilation compilation = CSharpCompilation.Create(
                assemblyName: Path.GetRandomFileName(),
                syntaxTrees: new[] { CSharpSyntaxTree.ParseText(compiledCode) },
                references: new[] {
                MetadataReference.CreateFromFile(typeof(Object).GetTypeInfo().Assembly.Location),
                MetadataReference.CreateFromFile(typeof(Delivery.DeliveryClientBuilder).GetTypeInfo().Assembly.Location)
            },
                options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary));

            using (var ms = new MemoryStream())
            {
                EmitResult result            = compilation.Emit(ms);
                string     compilationErrors = "Compilation errors:\n";

                if (!result.Success)
                {
                    IEnumerable <Diagnostic> failures = result.Diagnostics.Where(diagnostic =>
                                                                                 diagnostic.IsWarningAsError ||
                                                                                 diagnostic.Severity == DiagnosticSeverity.Error);

                    foreach (Diagnostic diagnostic in failures)
                    {
                        compilationErrors += String.Format("{0}: {1}\n", diagnostic.Id, diagnostic.GetMessage());
                    }
                }

                Assert.True(result.Success, compilationErrors);
            }
        }
コード例 #7
0
        private void SetParentClassCode(ClassInfoTreeNode parent, string inputString)
        {
            JInfo parentInfo = parent.JInfo;

            if (parentInfo is JArrayInfo)
            {
                if (((JArrayInfo)parentInfo).GenericType != SharpType.Object)
                {
                    ((JArrayInfo)parentInfo).GenericType = inputString;
                    ((JArrayInfo)parentInfo).SetType();
                }

                parent.Text = parentInfo.ToString();
                ClassCodeGenerator.GenerateClassCode((JClassInfo)((ClassInfoTreeNode)parent.Parent).JInfo, _declareOption, _formatString);
                parent.ClassCode = ((JClassInfo)((ClassInfoTreeNode)parent.Parent).JInfo).ClassCode;
            }
            else
            {
                ClassCodeGenerator.GenerateClassCode((JClassInfo)parentInfo, _declareOption, _formatString);
                parent.ClassCode = ((JClassInfo)parentInfo).ClassCode;
            }
        }
コード例 #8
0
        public global::EnvDTE.CodeFunction AddFunction(string name, global::EnvDTE.vsCMFunction kind, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic)
        {
            var codeGenerator = new ClassCodeGenerator(Class);

            return(codeGenerator.AddPublicMethod(name, (string)type));
        }
コード例 #9
0
 void CreateCodeGenerator()
 {
     codeGenerator = new ClassCodeGenerator(helper.Class, documentLoader);
 }
コード例 #10
0
		public CodeFunction AddFunction(string name, vsCMFunction kind, object type, object Position = null, vsCMAccess Access = vsCMAccess.vsCMAccessPublic)
		{
			var codeGenerator = new ClassCodeGenerator(Class);
			return codeGenerator.AddPublicMethod(name, (string)type);
		}
コード例 #11
0
        public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null)
        {
            var codeGenerator = new ClassCodeGenerator(Class);

            return(codeGenerator.AddPublicVariable(name, (string)type));
        }
コード例 #12
0
ファイル: CodeClass.cs プロジェクト: Netring/SharpDevelop
		public virtual global::EnvDTE.CodeVariable AddVariable(string name, object type, object Position = null, global::EnvDTE.vsCMAccess Access = global::EnvDTE.vsCMAccess.vsCMAccessPublic, object Location = null)
		{
			var codeGenerator = new ClassCodeGenerator(Class);
			return codeGenerator.AddPublicVariable(name, (string)type);
		}