public GenerateImageClass() { // Classes _gTypeToCSharpDict.Add(GValue.SourceType, "Source"); _gTypeToCSharpDict.Add(GValue.TargetType, "Target"); // Enums _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsAccess"), "Enums.Access"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsAlign"), "Enums.Align"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsAngle"), "Enums.Angle"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsAngle45"), "Enums.Angle45"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsBandFormat"), "Enums.BandFormat"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsBlendMode"), "Enums.BlendMode"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsCoding"), "Enums.Coding"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsCombine"), "Enums.Combine"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsCombineMode"), "Enums.CombineMode"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsCompassDirection"), "Enums.CompassDirection"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsDemandStyle"), "Enums.DemandStyle"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsDirection"), "Enums.Direction"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsExtend"), "Enums.Extend"); _gTypeToCSharpDict.Add(FailOnType, "Enums.FailOn"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignDzContainer"), "Enums.ForeignDzContainer"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignDzDepth"), "Enums.ForeignDzDepth"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignDzLayout"), "Enums.ForeignDzLayout"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignHeifCompression"), "Enums.ForeignHeifCompression"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignPpmFormat"), "Enums.ForeignPpmFormat"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignSubsample"), "Enums.ForeignSubsample"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignTiffCompression"), "Enums.ForeignTiffCompression"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignTiffPredictor"), "Enums.ForeignTiffPredictor"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignTiffResunit"), "Enums.ForeignTiffResunit"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignWebpPreset"), "Enums.ForeignWebpPreset"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsIntent"), "Enums.Intent"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsInteresting"), "Enums.Interesting"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsInterpretation"), "Enums.Interpretation"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsKernel"), "Enums.Kernel"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationBoolean"), "Enums.OperationBoolean"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationComplex"), "Enums.OperationComplex"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationComplex2"), "Enums.OperationComplex2"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationComplexget"), "Enums.OperationComplexget"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationMath"), "Enums.OperationMath"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationMath2"), "Enums.OperationMath2"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationMorphology"), "Enums.OperationMorphology"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationRelational"), "Enums.OperationRelational"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsOperationRound"), "Enums.OperationRound"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsPCS"), "Enums.PCS"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsPrecision"), "Enums.Precision"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsRegionShrink"), "Enums.RegionShrink"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsSize"), "Enums.Size"); // Flags _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignFlags"), "Enums.ForeignFlags"); _gTypeToCSharpDict.Add(NetVips.TypeFromName("VipsForeignPngFilter"), "Enums.ForeignPngFilter"); }
public void TestFlags() { // the OperationFlags enum is created when the first op is made -- // make it ourselves in case we are run before that NetVips.VipsOperationFlagsGetType(); var operationflagsGtype = NetVips.TypeFromName("VipsOperationFlags"); var gv = new GValue(); gv.SetType(operationflagsGtype); gv.Set(12); var value = gv.Get(); Assert.Equal(12u, value); }
public void TestEnum() { // the Interpretation enum is created when the first image is made -- // make it ourselves in case we are run before the first image NetVips.VipsInterpretationGetType(); var interpretationGtype = NetVips.TypeFromName("VipsInterpretation"); var gv = new GValue(); gv.SetType(interpretationGtype); gv.Set("xyz"); var value = gv.Get(); Assert.Equal("xyz", value); }
public void TestFlags() { // the OperationFlags enum is created when the first op is made -- // make it ourselves in case we are run before that NetVips.VipsOperationFlagsGetType(); var gtype = NetVips.TypeFromName("VipsOperationFlags"); Enums.OperationFlags actual; using (var gv = new GValue()) { gv.SetType(gtype); gv.Set(Enums.OperationFlags.DEPRECATED); actual = (Enums.OperationFlags)gv.Get(); } Assert.Equal(Enums.OperationFlags.DEPRECATED, actual); }
public void TestEnum() { // the Interpretation enum is created when the first image is made -- // make it ourselves in case we are run before the first image NetVips.VipsInterpretationGetType(); var gtype = NetVips.TypeFromName("VipsInterpretation"); Enums.Interpretation actual; using (var gv = new GValue()) { gv.SetType(gtype); gv.Set(Enums.Interpretation.Xyz); actual = (Enums.Interpretation)gv.Get(); } Assert.Equal(Enums.Interpretation.Xyz, actual); }
/// <summary> /// Generate the `Enums.Generated.cs` file. /// </summary> /// <remarks> /// This is used to generate the `Enums.Generated.cs` file (<see cref="Enums"/>). /// </remarks> /// <returns>The `Enums.Generated.cs` as string.</returns> private string Generate() { // otherwise we're missing some enums SaveableGetType(); var _ = Image.Black(1, 1); var allEnums = NetVips.GetEnums(); const string preamble = @"//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // libvips version: {0} // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------"; var stringBuilder = new StringBuilder(string.Format(preamble, $"{NetVips.Version(0)}.{NetVips.Version(1)}.{NetVips.Version(2)}")); stringBuilder.AppendLine() .AppendLine() .AppendLine("namespace NetVips") .AppendLine("{") .AppendLine(" using System;") .AppendLine() .AppendLine(" public partial static class Enums") .AppendLine(" {") .AppendLine(" #region auto-generated enums") .AppendLine(); foreach (var name in allEnums) { if (name.StartsWith("Gsf")) { continue; } var gtype = NetVips.TypeFromName(name); var csharpName = RemovePrefix(name); stringBuilder.AppendLine(" /// <summary>") .AppendLine($" /// {csharpName}") .AppendLine(" /// </summary>") .AppendLine($" public static class {csharpName}") .AppendLine(" {"); var enumValues = NetVips.ValuesForEnum(gtype); for (var i = 0; i < enumValues.Count; i++) { var value = enumValues[i]; var csharpValue = value.Replace('-', '_').ToPascalCase(); stringBuilder.AppendLine($" /// <summary>{csharpValue}</summary>") .AppendLine($" public const string {csharpValue} = \"{value}\";"); if (i != enumValues.Count - 1) { stringBuilder.AppendLine(); } } stringBuilder.AppendLine(" }").AppendLine(); } stringBuilder.AppendLine(" #endregion") .AppendLine(" }") .AppendLine("}"); return(stringBuilder.ToString()); }