public void CreateContainer() { var info = new CodeGenerateContainerInfo { TypeName = typeof(TestTargetContainerExternal).AssemblyQualifiedName, Members = { new CodeGenerateContainerInfo.MemberInfo { Name = "Field" }, new CodeGenerateContainerInfo.MemberInfo { Active = false, Name = "Field2" }, new CodeGenerateContainerInfo.MemberInfo { Name = "Property" } } }; CodeGenerateContainer container = CodeGenerateContainerInfoEditorUtility.CreateContainer(info, m_validation); Assert.NotNull(container); Assert.AreEqual(2, container.Fields.Count); Assert.True(container.Fields.Exists(x => x.Name == "Field")); Assert.False(container.Fields.Exists(x => x.Name == "Field2")); Assert.True(container.Fields.Exists(x => x.Name == "Property")); }
public void CreateUnit() { CodeGenerateContainerInfo info = CodeGenerateContainerInfoEditorUtility.CreateInfo(typeof(Target), m_validation); Assert.NotNull(info); SyntaxNode unit = CodeGenerateContainerInfoEditorUtility.CreateUnit(info, m_validation); Assert.NotNull(unit); string result = unit.NormalizeWhitespace().ToFullString(); string expected = File.ReadAllText(m_target); Assert.AreEqual(expected, result); }
public void CreateInfo() { CodeGenerateContainerInfo info = CodeGenerateContainerInfoEditorUtility.CreateInfo(typeof(TestTargetContainerExternal), m_validation); Assert.NotNull(info); bool result1 = info.TryGetTargetType(out Type type); Assert.True(result1); Assert.NotNull(type); Assert.AreEqual(typeof(TestTargetContainerExternal), type); Assert.AreEqual(3, info.Members.Count); Assert.True(info.Members.Exists(x => x.Name == "Field")); Assert.True(info.Members.Exists(x => x.Name == "Field2")); Assert.True(info.Members.Exists(x => x.Name == "Property")); }
private static CodeGenerateContainerInfo CreateAssetInfo(Utf8JsonMathTypeGenerateInfo info) { if (info == null) { throw new ArgumentNullException(nameof(info)); } var assetInfo = new CodeGenerateContainerInfo { TypeName = info.Type.AssemblyQualifiedName }; for (int i = 0; i < info.Count; i++) { CodeGenerateContainerInfo.MemberInfo member = CreateMember(i, info.IsVector); assetInfo.Members.Add(member); } return(assetInfo); }
public static void GenerateFiles(List <Utf8JsonMathTypeGenerateInfo> infos, string folderPath) { if (infos == null) { throw new ArgumentNullException(nameof(infos)); } if (string.IsNullOrEmpty(folderPath)) { throw new ArgumentNullException(nameof(folderPath)); } Directory.CreateDirectory(folderPath); for (int i = 0; i < infos.Count; i++) { Utf8JsonMathTypeGenerateInfo info = infos[i]; CodeGenerateContainerInfo assetInfo = CreateAssetInfo(info); string path = $"{folderPath}/{info.Type.Name}.{Utf8JsonExternalTypeEditorUtility.EXTERNAL_TYPE_ASSET_EXTENSION_NAME}"; string content = EditorJsonUtility.ToJson(assetInfo, true); File.WriteAllText(path, content); } }