public void TestLoad() { var resxdata = ResXData.FromFile(resxFile); Assert.IsNull(resxdata.ProjectFile); CheckEquality(resxdata); }
public void TestLoadFromProjectFile() { var pf = new Projects.ProjectFile(resxFile); var resxdata = ResXData.FromProjectFile(pf); Assert.AreSame(pf, resxdata.First().ProjectFile); CheckEquality(resxdata.First()); }
public void TestConvertToAndFromResXNode() { var resxdata = ResXData.FromFile(resxFile); foreach (var icon in resxdata.Nodes) { ResXDataNode node = icon; ResXNode icon2 = node; AreEqual(resxdata.GetValue(icon), resxdata.GetValue(icon2)); Assert.AreEqual(icon.Name, icon2.Name); Assert.AreEqual(icon.TypeName, icon2.TypeName); Assert.AreEqual(icon.Comment, icon2.Comment); } }
private void LoadFont() { if (File.Exists(VarGlobale.SkinFontPath)) { BtnChangeFont.Enabled = true; Dictionary <string, Font> Result = RessManager.LoadRess(VarGlobale.SkinFontPath); ResXData.Clear(); foreach (KeyValuePair <string, Font> item in Result) { ResXData.Add(item.Key.ToString(), item.Value); fontDialog1.Font = item.Value; LblFontChoice.Font = item.Value; LblFontChoice.Text = item.Value.ToString(); } } }
public void TestGetDrawingImage() { var resxdata = ResXData.FromFile(resxFile); var icon = resxdata.GetDrawingImage(resxdata.Nodes[0]); //Assert.AreEqual(System.Drawing.Imaging.ImageFormat.Icon, icon.RawFormat); Assert.AreEqual(32, icon.Width); Assert.AreEqual(32, icon.Height); var bitmap = resxdata.GetDrawingImage(resxdata.Nodes[1]); Assert.AreEqual(System.Drawing.Imaging.ImageFormat.Png, bitmap.RawFormat); Assert.AreEqual(392, bitmap.Width); Assert.AreEqual(243, bitmap.Height); }
public void TestCreateNode() { var resxdata = ResXData.FromFile(resxFile); var fileRef = (ResXFileRef)resxdata.Nodes[1].ObjectValue; Core.FilePath path = fileRef.FileName; var absolutePath = Path.GetFullPath(path.ToAbsolute(resxdata.Path)); var otherNode = (ResXDataNode)resxdata.CreateNode(absolutePath, typeof(System.Drawing.Bitmap)); Assert.AreEqual(fileRef.FileName, otherNode.FileRef.FileName); Assert.AreEqual(fileRef.TypeName, otherNode.FileRef.TypeName); Assert.AreEqual(fileRef.TextFileEncoding, otherNode.FileRef.TextFileEncoding); var value = (System.Drawing.Bitmap)resxdata.GetValue(resxdata.Nodes[0]); var otherValue = (System.Drawing.Bitmap)resxdata.GetValue(otherNode); Assert.AreEqual(value.Width, otherValue.Width); Assert.AreEqual(value.Height, otherValue.Height); }
public void TestModify() { string workFile = resxFile.Replace("Image", "Image2"); try { File.Copy(resxFile, workFile); var resxdata = ResXData.FromFile(workFile); resxdata.Nodes.Add(new ResXNode("string", "test", "", "System.String")); resxdata.WriteToFile(resxdata.Nodes); resxdata = ResXData.FromFile(workFile); Assert.AreEqual(3, resxdata.Nodes.Count); } finally { File.Delete(workFile); } }
static void CheckEquality(ResXData resxdata) { Assert.AreEqual(2, resxdata.Nodes.Count); var icon = resxdata.Nodes[0]; Assert.AreEqual("icon", icon.Name); Assert.AreEqual(typeof(System.Drawing.Icon).AssemblyQualifiedName, icon.TypeName); var iconValue = resxdata.GetValue <System.Drawing.Icon>(icon); Assert.AreEqual(32, iconValue.Width); Assert.AreEqual(32, iconValue.Height); var bitmap = resxdata.Nodes[1]; Assert.AreEqual("bitmap", bitmap.Name); Assert.AreEqual(typeof(System.Drawing.Bitmap).AssemblyQualifiedName, bitmap.TypeName); var bitmapValue = resxdata.GetValue <System.Drawing.Bitmap>(bitmap); Assert.AreEqual(392, bitmapValue.Width); Assert.AreEqual(243, bitmapValue.Height); }
/// <summary> /// Generates a sequence of <see cref="PropertyDeclarationSyntax"/> for the specified property dictionary. /// </summary> /// <param name="properties">The property dictionary for which to generate the code.</param> /// <returns>The sequence of generated <see cref="PropertyDeclarationSyntax"/>.</returns> private static IEnumerable <PropertyDeclarationSyntax> GenerateProperties(Dictionary <string, ResXData> properties) { ArgumentSyntax argument = SyntaxFactory.Argument(SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.ParseTypeName(Culture), SyntaxFactory.IdentifierName(Current))); foreach (KeyValuePair <string, ResXData> pair in properties.OrderBy(p => p.Key, StringComparer.InvariantCulture)) { string name = pair.Key; ResXData data = pair.Value; yield return(SyntaxFactory.PropertyDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.StringKeyword)), name).AddModifiers( SyntaxFactory.Token(SyntaxKind.InternalKeyword), SyntaxFactory.Token(SyntaxKind.StaticKeyword) ).AddAccessorListAccessors( SyntaxFactory.AccessorDeclaration(SyntaxKind.GetAccessorDeclaration).AddBodyStatements( SyntaxFactory.ReturnStatement( SyntaxFactory.InvocationExpression( SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, SyntaxFactory.IdentifierName(FieldName), SyntaxFactory.IdentifierName(nameof(ResourceManager.GetString))) ).AddArgumentListArguments(SyntaxFactory.Argument(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(data.Name))), argument) ) ) ).AddSummary(PropertySummary(SecurityElement.Escape(data.Value)))); } }
protected override void OnDataChanged(ResXData data) { base.OnDataChanged(data); container.Clear(); int row = 0; int col = 0; // smart resizing foreach (var node in data.Nodes) { names.Add(node.Name); if (SkipNode(node)) { continue; } var image = GetImage(node); if (image == null) { continue; } #if TABLE container.Add(CreateItem(node.Name, image), col++, row); if (col == 3) { col = 0; row++; } #else container.PackStart(CreateItem(node.Name, image)); #endif } }