public CodeRoot GetCodeRoot(string path) { if (File.Exists(path) == false) return null; CSharpParser formatter = new CSharpParser(); formatter.ParseCode(File.ReadAllText(path)); return (CodeRoot)formatter.CreatedCodeRoot; }
public static ParseResults ParseCSharpFiles(IEnumerable <string> csharpFiles) { var parser = new CSharpParser(); var parseResults = new ParseResults(); foreach (var file in csharpFiles) { if (File.Exists(file) == false) { continue; } parser.Reset(); parser.ParseCode(file, File.ReadAllText(file)); parseResults.AddParsedFile(file, parser.CreatedCodeRoot as CodeRoot); } return(parseResults); }
public void GenericClasses_WithConstraints() { const string code = @" public class Class1<T> : IComparer<T> where T : Class2 { } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Assert.That(clazz.Name, Is.EqualTo("Class1<T>")); Assert.That(clazz.BaseNames[0], Is.EqualTo("IComparer<T>")); Assert.That(clazz.GenericConstraintClause, Is.EqualTo("where T : Class2")); }
public void Test() { string codeText = File.ReadAllText("Resources\\BasicClass.txt"); var parser = new CSharpParser(); parser.ParseCode(codeText); var codeRoot = (CodeRoot)parser.CreatedCodeRoot; //Actions actions = Test2(codeRoot);//Test1(codeRoot); Actions actions = new Actions(); Entity entity = new EntityImpl("BasicClass"); entity.AddProperty(new PropertyImpl { Name = "Property5", Type = "Entity" }); Entity entity1 = new EntityImpl("Class1"); entity1.AddProperty(new PropertyImpl { Name = "Property5", Type = "Entity" }); entity.MappedClass = codeRoot.Namespaces[0].Classes[0]; entity1.MappedClass = codeRoot.Namespaces[0].Classes[1]; CheckEntity(entity, actions); codeText = actions.RunActions(codeText, codeRoot, true); actions = new Actions(); actions.AddAction(new AddAttributeToPropertyAction(entity.MappedClass.Properties[0], new Attribute(codeRoot.Controller) { Name = "Attr" })); CheckEntity(entity1, actions); var output = actions.RunActions(codeText, codeRoot, false); }
public void Test_Script_Base_Class() { string resourcePath = "Resources/CSharp/ScriptBase.cs".Replace('/', Path.DirectorySeparatorChar); string fileText = File.ReadAllText(resourcePath); CSharpParser parser = new CSharpParser(); parser.ParseCode(fileText); if (parser.ErrorOccurred) { Assert.Fail("Parsing failed"); } CodeRoot codeRoot = (CodeRoot)parser.CreatedCodeRoot; Namespace ns = codeRoot.Namespaces[0]; Class scriptBase = ns.Classes[0]; Assert.That(scriptBase.Functions.Count, Is.EqualTo(13)); }
public void Interface_Events() { const string code = @" public interface Interface1 { event Delegate1 Event1; } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Interface clazz = (Interface)codeRoot.WalkChildren()[0]; InterfaceEvent enu = (InterfaceEvent)clazz.WalkChildren()[0]; Assert.That(enu.Name, Is.EqualTo("Event1")); Assert.That(enu.DataType.ToString(), Is.EqualTo("Delegate1")); }
public void Structures_MultipleFields() { const string code = @" public class Class1 { public struct Structure1 { public int i; public int j; } } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Struct con = (Struct)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("Structure1")); Assert.That(con.Modifiers, Has.Count(1)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); Field f1 = con.Fields[0]; Assert.That(f1.Name, Is.EqualTo("i")); Assert.That(f1.Modifiers, Has.Count(1)); Assert.That(f1.Modifiers[0], Is.EqualTo("public")); Assert.That(f1.DataType.Name, Is.EqualTo("int")); Field f2 = con.Fields[1]; Assert.That(f2.Name, Is.EqualTo("j")); Assert.That(f2.Modifiers, Has.Count(1)); Assert.That(f2.Modifiers[0], Is.EqualTo("public")); Assert.That(f2.DataType.Name, Is.EqualTo("int")); }
public void TestFile(string filename, bool stripText, CSharpFormatSettings settings) { string fileText = File.ReadAllText(filename); CSharpParser formatter = new CSharpParser(); formatter.FormatSettings.SetFrom(settings); formatter.ParseCode(fileText); Assert.IsFalse(formatter.ErrorOccurred); string formattedText = formatter.CreatedCodeRoot.ToString(); formattedText = Slyce.Common.Utility.StandardizeLineBreaks(formattedText, Slyce.Common.Utility.LineBreaks.Windows); string strippedFileText = Diff.StripWhitespace(new[] { fileText }, stripText)[0].Replace("\t", " "); string strippedFormattedText = Diff.StripWhitespace(new[] { formattedText }, stripText)[0].Replace("\t", " "); Assert.That(strippedFormattedText, Is.EqualTo(strippedFileText)); }
public void Fields() { const string code = @" public class Class1 { public static int i = 0; public const float PI = 3.14159265358979323846; } "; CSharpParser parser = new CSharpParser(); parser.FormatSettings.ReorderBaseConstructs = false; parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Field con = (Field)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("i")); Assert.That(con.Modifiers, Has.Count(2)); Assert.That(con.DataType.Name, Is.EqualTo("int")); Assert.That(con.InitialValue, Is.EqualTo("0")); // Modifiers should be kept in order. Assert.That(con.Modifiers, Has.Count(2)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); Assert.That(con.Modifiers[1], Is.EqualTo("static")); con = (Field)clazz.WalkChildren()[1]; Assert.That(con.Name, Is.EqualTo("PI")); Assert.That(con.Modifiers, Has.Count(2)); Assert.That(con.DataType.Name, Is.EqualTo("float")); Assert.That(con.InitialValue, Is.EqualTo("3.14159265358979323846")); // Modifiers should be kept in order. Assert.That(con.Modifiers, Has.Count(2)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); Assert.That(con.Modifiers[1], Is.EqualTo("const")); }
public void Structures() { const string code = @" public class Class1 { public struct Structure1 { } } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Struct con = (Struct)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("Structure1")); Assert.That(con.Modifiers, Has.Count(1)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); }
private void TestFiles() { foreach (string file in _Files) { try { GC.Collect(); CSharpParser parser = new CSharpParser(); parser.ParseCode(file, File.ReadAllText(file)); if (parser.ErrorOccurred == false) { continue; } Assert.IsNull(parser.ExceptionThrown, parser.ExceptionThrown == null ? "" : parser.ExceptionThrown.ToString()); Assert.That(parser.SyntaxErrors.Count, Is.EqualTo(0), "There were syntax errors in file " + file); } catch (Exception e) { Assert.Fail(e.ToString()); } } }
public void Interfaces() { const string code = @" public class Class1 { public interface MarkerInterface { } } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Interface con = (Interface)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("MarkerInterface")); Assert.That(con.Modifiers, Has.Count(1)); Assert.That(con.Modifiers[0], Is.EqualTo("public")); }
internal static void AssertFilesAreSame(string original, string changed) { CodeRootMap codeRootMap = new CodeRootMap(); CSharpParser formatter = new CSharpParser(); formatter.FormatSettings.ReorderBaseConstructs = true; formatter.ParseCode(File.ReadAllText(original)); ICodeRoot codeRoot = formatter.CreatedCodeRoot; codeRootMap.AddCodeRoot(codeRoot, Version.NewGen); codeRootMap.AddCodeRoot(codeRoot, Version.PrevGen); formatter = new CSharpParser(); formatter.FormatSettings.ReorderBaseConstructs = true; formatter.ParseCode(File.ReadAllText(changed)); codeRoot = formatter.CreatedCodeRoot; codeRootMap.AddCodeRoot(codeRoot, Version.User); Assert.That(codeRootMap.Diff(), Is.EqualTo(TypeOfDiff.ExactCopy)); }
public static void TestBodyText(string methodBody, string expectedText, CSharpFormatSettings formatSettings) { string code = string.Format("public class Class1\r\n{0}\r\npublic void Method1(string param1)\r\n{0}\r\n{2}\r\n{1}\r\n{1}", '{', '}', methodBody); CSharpParser parser = new CSharpParser(); parser.FormatSettings.SetFrom(formatSettings); parser.ParseCode(code); Assert.That(parser.ErrorOccurred, Is.False, "Parser errors occurred:\n" + GetSyntaxErrors(parser)); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Function con = (Function)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("Method1")); Assert.That(con.BodyText, Is.EqualTo(expectedText)); }
public void Events() { const string code = @" public class Class1 { public event Delegate1 Event1; } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Event enu = (Event)clazz.WalkChildren()[0]; Assert.That(enu.Name, Is.EqualTo("Event1")); Assert.That(enu.Modifiers, Has.Count(1)); Assert.That(enu.Modifiers[0], Is.EqualTo("public")); Assert.That(enu.DataType.ToString(), Is.EqualTo("Delegate1")); }
public void Interface_Properties() { const string code = @" public interface Interface1 { string Property1 { get; set; } } "; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Interface clazz = (Interface)codeRoot.WalkChildren()[0]; InterfaceProperty inter = (InterfaceProperty)clazz.WalkChildren()[0]; Assert.That(inter.Name, Is.EqualTo("Property1")); Assert.That(inter.DataType.ToString(), Is.EqualTo("string")); Assert.That(inter.GetAccessor, Is.Not.Null); Assert.That(inter.SetAccessor, Is.Not.Null); }
public void testMultipleErrors() { CSharpParser parser = new CSharpParser(); parser.ParseCode(@"using System using NUnit.Framework; class Hahaha { publi TestMethod() { } }" ); Assert.That(parser.ErrorOccurred, Is.True); Assert.That(parser.SyntaxErrors, Has.Count(2)); Assert.That(parser.SyntaxErrors[0].LineNumber, Is.EqualTo(0)); Assert.That(parser.SyntaxErrors[1].LineNumber, Is.EqualTo(4)); parser = new CSharpParser(); parser.ParseCode(@"using System using NUnit.Framework; class Hahaha { publi TestMethod() { } public testOtherMethod( { } }" ); Assert.That(parser.ErrorOccurred, Is.True); Assert.That(parser.SyntaxErrors, Has.Count(3)); Assert.That(parser.SyntaxErrors[0].LineNumber, Is.EqualTo(0)); Assert.That(parser.SyntaxErrors[1].LineNumber, Is.EqualTo(4)); Assert.That(parser.SyntaxErrors[2].LineNumber, Is.EqualTo(8)); }
public void Enums() { const string code = @" public class Class1 { public enum Enumeration1 { One = 1, Two = 2 } }"; CSharpParser parser = new CSharpParser(); parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Enumeration enu = (Enumeration)clazz.WalkChildren()[0]; Assert.That(enu.Name, Is.EqualTo("Enumeration1")); Assert.That(enu.Modifiers, Has.Count(1)); Assert.That(enu.Modifiers[0], Is.EqualTo("public")); }
public void Attributes() { const string code = @" namespace n1 { [Serializable] [SomeAttribute(NamedParam = ""Nothing"")] public class Class1 { } [Positional(1, ""string"")] public class Class2 { } }"; CSharpParser parser = new CSharpParser(); parser.FormatSettings.ReorderBaseConstructs = false; parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Namespace n1 = (Namespace)codeRoot.WalkChildren()[0]; Class clazz = n1.Classes[0]; Assert.That(clazz.Attributes, Has.Count(2)); Assert.That(clazz.Attributes[0].ToString(), Is.EqualTo("Serializable")); Assert.That(clazz.Attributes[1].ToString(), Is.EqualTo("SomeAttribute(NamedParam = \"Nothing\")")); clazz = n1.Classes[1]; Assert.That(clazz.Attributes, Has.Count(1)); Assert.That(clazz.Attributes[0].ToString(), Is.EqualTo("Positional(1, \"string\")")); }
/// <summary> /// Performs an in depth diff by breaking code files into their constituent parts (functions, properties /// etc, so that these elements can be diffed without regard to their ordering. /// </summary> /// <remarks> /// I've put some Thread.Sleep(1) calls in here to ensure that this processing doesn't bring a single core machine /// to its knees. This should ensure that any GUI or other background threads can still get some CPU time, /// as there is not much in here that could cause a context switch. /// </remarks> public bool PerformSuperDiff() { SetupPerformDiff(); try { switch (IntelliMerge) { case IntelliMergeType.CSharp: CSharpParser formatter = new CSharpParser(); try { // Reset the DiffType CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy; if (diffCodeRootMap.PrevGenCodeRoot == null && PrevGenFile.HasContents || ReloadFiles) { formatter.Reset(); string filename = string.IsNullOrEmpty(PrevGenFile.FilePath) ? "Prev Gen File" : PrevGenFile.FilePath; formatter.ParseCode(filename, PrevGenFile.GetContents()); if (formatter.ErrorOccurred) { return(false); } diffCodeRootMap.AddCodeRoot(formatter.CreatedCodeRoot, Version.PrevGen); } // Force a context switch Thread.Sleep(1); if (diffCodeRootMap.NewGenCodeRoot == null && NewGenFile.HasContents || ReloadFiles) { formatter.Reset(); string filename = string.IsNullOrEmpty(NewGenFile.FilePath) ? "New Gen File" : NewGenFile.FilePath; formatter.ParseCode(filename, NewGenFile.GetContents()); if (formatter.ErrorOccurred) { return(false); } diffCodeRootMap.AddCodeRoot(formatter.CreatedCodeRoot, Version.NewGen); } // Force a context switch Thread.Sleep(1); if (diffCodeRootMap.UserCodeRoot == null && UserFile.HasContents || ReloadFiles) { formatter.Reset(); string filename = string.IsNullOrEmpty(UserFile.FilePath) ? "User File" : UserFile.FilePath; formatter.ParseCode(filename, UserFile.GetContents()); if (formatter.ErrorOccurred) { return(false); } diffCodeRootMap.AddCodeRoot(formatter.CreatedCodeRoot, Version.User); } // Force a context switch Thread.Sleep(1); // Set this back to false. If it was true, we have reloaded the files, if it was already false this // does nothing. ReloadFiles = false; } catch (Exception ex) { CurrentDiffResult.ParserWarningDescription = ex.Message; return(false); } finally { if (formatter.ErrorOccurred) { CurrentDiffResult.ParserWarningDescription = formatter.GetFormattedErrors(); } } if (string.IsNullOrEmpty(temporaryManifestFile) == false && manifestFileApplied == false) { CodeRootMapMatchProcessor processor = new CodeRootMapMatchProcessor(); processor.LoadCustomMappings(ManifestConstants.LoadManifestDocument(temporaryManifestFile), diffCodeRootMap, Path.GetFileName(RelativeFilePath)); manifestFileApplied = true; } CurrentDiffResult.DiffType = diffCodeRootMap.Diff(); if (CurrentDiffResult.DiffType != TypeOfDiff.Conflict && CurrentDiffResult.DiffType != TypeOfDiff.Warning) { //mergedFile = new TextFile(CodeRootMap.GetMergedCodeRoot().ToString()); // Slyce.Common.Utility.WriteToFile(newFile, userFile.GetContents()); } break; default: // No SuperDiff available for this type of file (no parser created yet). break; } } catch (Exception ex) { throw new DiffException(ex); } return(true); }
/// <summary> /// Performs the diff between the 3 files, even if some of them do not exist. /// </summary> protected override bool PerformDiffInternal() { ////////////////////////// MergedFile = NewGenFile; if (!UserFile.IsFileOnDisk) { CurrentDiffResult.DiffType = TypeOfDiff.NewFile; } else if (UserFile.HexStringMD5() == NewGenFile.HexStringMD5()) { CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy; } else { CurrentDiffResult.DiffType = TypeOfDiff.TemplateChangeOnly; } return(true); /////////////////////////// if (IntelliMerge == IntelliMergeType.Overwrite) { CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy; MergedFile = NewGenFile; return(true); } if (IntelliMerge == IntelliMergeType.CreateOnly) { CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy; MergedFile = UserFile.HasContents ? UserFile : NewGenFile; return(true); } if (UserFile.HasContents == false && PrevGenFile.HasContents == false && NewGenFile.HasContents == false) { throw new InvalidOperationException("Cannot perform a diff if there are no files!"); } if (MergedFileExists) { CurrentDiffResult.DiffPerformedSuccessfully = true; CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy; CurrentDiffResult.DiffWarningDescription = CurrentDiffResult.ParserWarningDescription = ""; return(true); } if (PrevGenFile.HasContents && UserFile.HasContents && NewGenFile.HasContents) { // Perform 3-way diff string fileBodyParent = PrevGenFile.GetContents(); string fileBodyUser = UserFile.GetContents(); // Template code is not formatted until it is needed. Do the formatting here. string fileBodyGenerated; string mergedText; SlyceMergeResult slyceMerge; if (IntelliMerge == IntelliMergeType.CSharp) { if (NewGenFile.GetContents().Trim() == string.Empty) { fileBodyGenerated = ""; } else { CSharpParser formatter = new CSharpParser(); formatter.ParseCode(NewGenFile.FilePath, NewGenFile.GetContents()); if (formatter.ErrorOccurred) { CurrentDiffResult.ParserWarningDescription = formatter.GetFormattedErrors(); return(false); } CodeRoot codeRoot = (CodeRoot)formatter.CreatedCodeRoot; fileBodyGenerated = codeRoot.ToString(); } slyceMerge = SlyceMerge.Perform3wayDiff(fileBodyUser, fileBodyParent, fileBodyGenerated, out mergedText, false); } else { fileBodyGenerated = NewGenFile.GetContents(); slyceMerge = SlyceMerge.Perform3wayDiff(fileBodyUser, fileBodyParent, fileBodyGenerated, out mergedText, true); MergedFile = new TextFile(mergedText); } CurrentDiffResult.DiffType = slyceMerge.DiffType; if (slyceMerge.DiffType == TypeOfDiff.Warning) { // TODO: What should be done here? throw new Exception( "There was a warning during the diff process when there shouldn't have been. Please report this to Slyce."); } if (slyceMerge.DiffType != TypeOfDiff.ExactCopy) { return(PerformSuperDiff()); } // File was exact copy - use user version MergedFile = new TextFile(fileBodyUser); } else if (PrevGenFile.HasContents && UserFile.HasContents == false && NewGenFile.HasContents) { // No user file, just use the template file CurrentDiffResult.DiffType = TypeOfDiff.Warning; CurrentDiffResult.DiffWarningDescription = "The User's version of this file has been deleted or renamed, but the Template and previous version of this file still exist."; MergedFile = new TextFile(NewGenFile.GetContents()); } else if (PrevGenFile.HasContents == false && UserFile.HasContents && NewGenFile.HasContents) { //CurrentDiffResult.DiffType = TypeOfDiff.Warning; //CurrentDiffResult.DiffWarningDescription = // "User version of a file clashes with a new file the template is trying to create."; // Perform 2-way diff string fileBodyNewGen = NewGenFile.GetContents(); string fileBodyUser = UserFile.GetContents(); CurrentDiffResult.DiffType = SlyceMerge.PerformTwoWayDiff(fileBodyNewGen, fileBodyUser); if (CurrentDiffResult.DiffType != TypeOfDiff.ExactCopy) { // Also perform a super diff return(PerformSuperDiff()); } MergedFile = new TextFile(fileBodyUser); } else if (PrevGenFile.HasContents == false && UserFile.HasContents == false && NewGenFile.HasContents) { // The template has added a new file. CurrentDiffResult.DiffType = TypeOfDiff.ExactCopy; MergedFile = new TextFile(NewGenFile.GetContents()); } else { // Cases covered by this else: // * User and prevgen file exist, no template // * Prevgen, no user or template. // * User file, no template or prevgen // TODO: Shouldn't really be a warning... CurrentDiffResult.DiffType = TypeOfDiff.Warning; throw new Exception(string.Format("TODO: determine course of action, what should be copied to staging folder, because no file exists: \nparent file path:\"{0}\" : {1}\nuser file path:\"{2}\" : {3}\ntemplate file path:\"{4}\" : {5}", PrevGenFile.FilePath, PrevGenFile.HasContents, UserFile.FilePath, UserFile.HasContents, NewGenFile.FilePath, NewGenFile.HasContents)); } return(true); }
public void PrimitiveTypes_LongNames() { const string code = @"public class Class1 { public Int32 a = 0; public String b = """"; public Int16 c = 0; public Int64 d = 0; public Single e = 0; public Double f = 0; public Bool g = false; public Char h = 'c'; public Byte i = 0; public Object j = null; public Decimal k = 0.0m; }"; CSharpParser parser = new CSharpParser(); parser.FormatSettings.ReorderBaseConstructs = false; parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Field con = (Field)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("a")); Assert.That(con.DataType.Name, Is.EqualTo("Int32")); con = (Field)clazz.WalkChildren()[1]; Assert.That(con.Name, Is.EqualTo("b")); Assert.That(con.DataType.Name, Is.EqualTo("String")); con = (Field)clazz.WalkChildren()[2]; Assert.That(con.Name, Is.EqualTo("c")); Assert.That(con.DataType.Name, Is.EqualTo("Int16")); con = (Field)clazz.WalkChildren()[3]; Assert.That(con.Name, Is.EqualTo("d")); Assert.That(con.DataType.Name, Is.EqualTo("Int64")); con = (Field)clazz.WalkChildren()[4]; Assert.That(con.Name, Is.EqualTo("e")); Assert.That(con.DataType.Name, Is.EqualTo("Single")); con = (Field)clazz.WalkChildren()[5]; Assert.That(con.Name, Is.EqualTo("f")); Assert.That(con.DataType.Name, Is.EqualTo("Double")); con = (Field)clazz.WalkChildren()[6]; Assert.That(con.Name, Is.EqualTo("g")); Assert.That(con.DataType.Name, Is.EqualTo("Bool")); con = (Field)clazz.WalkChildren()[7]; Assert.That(con.Name, Is.EqualTo("h")); Assert.That(con.DataType.Name, Is.EqualTo("Char")); con = (Field)clazz.WalkChildren()[8]; Assert.That(con.Name, Is.EqualTo("i")); Assert.That(con.DataType.Name, Is.EqualTo("Byte")); con = (Field)clazz.WalkChildren()[9]; Assert.That(con.Name, Is.EqualTo("j")); Assert.That(con.DataType.Name, Is.EqualTo("Object")); con = (Field)clazz.WalkChildren()[10]; Assert.That(con.Name, Is.EqualTo("k")); Assert.That(con.DataType.Name, Is.EqualTo("Decimal")); }
public void PrimitiveTypes_ShortNames() { const string code = @"public class Class1 { public int a = 0; public string b = """"; public short c = 0; public long d = 0; public float e = 0; public double f = 0; public bool g = false; public char h = 'c'; public byte i = 0; public object j = null; public decimal k = 0m; }"; CSharpParser parser = new CSharpParser(); parser.FormatSettings.ReorderBaseConstructs = false; parser.ParseCode(code); ICodeRoot codeRoot = parser.CreatedCodeRoot; Class clazz = (Class)codeRoot.WalkChildren()[0]; Field con = (Field)clazz.WalkChildren()[0]; Assert.That(con.Name, Is.EqualTo("a")); Assert.That(con.DataType.Name, Is.EqualTo("int")); con = (Field)clazz.WalkChildren()[1]; Assert.That(con.Name, Is.EqualTo("b")); Assert.That(con.DataType.Name, Is.EqualTo("string")); con = (Field)clazz.WalkChildren()[2]; Assert.That(con.Name, Is.EqualTo("c")); Assert.That(con.DataType.Name, Is.EqualTo("short")); con = (Field)clazz.WalkChildren()[3]; Assert.That(con.Name, Is.EqualTo("d")); Assert.That(con.DataType.Name, Is.EqualTo("long")); con = (Field)clazz.WalkChildren()[4]; Assert.That(con.Name, Is.EqualTo("e")); Assert.That(con.DataType.Name, Is.EqualTo("float")); con = (Field)clazz.WalkChildren()[5]; Assert.That(con.Name, Is.EqualTo("f")); Assert.That(con.DataType.Name, Is.EqualTo("double")); con = (Field)clazz.WalkChildren()[6]; Assert.That(con.Name, Is.EqualTo("g")); Assert.That(con.DataType.Name, Is.EqualTo("bool")); con = (Field)clazz.WalkChildren()[7]; Assert.That(con.Name, Is.EqualTo("h")); Assert.That(con.DataType.Name, Is.EqualTo("char")); con = (Field)clazz.WalkChildren()[8]; Assert.That(con.Name, Is.EqualTo("i")); Assert.That(con.DataType.Name, Is.EqualTo("byte")); con = (Field)clazz.WalkChildren()[9]; Assert.That(con.Name, Is.EqualTo("j")); Assert.That(con.DataType.Name, Is.EqualTo("object")); con = (Field)clazz.WalkChildren()[10]; Assert.That(con.Name, Is.EqualTo("k")); Assert.That(con.DataType.Name, Is.EqualTo("decimal")); }