Skip to content

Commit 630a352

Browse files
committed
Fix trim warnings
1 parent ccb3848 commit 630a352

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

QRCoder/Extensions/StringValueAttribute.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using System.Reflection;
56
using System.Text;
@@ -9,6 +10,7 @@ namespace QRCoder.Extensions
910
/// <summary>
1011
/// Used to represent a string value for a value in an enum
1112
/// </summary>
13+
[Obsolete("This attribute will be removed in a future version of QRCoder.")]
1214
public class StringValueAttribute : Attribute
1315
{
1416

@@ -31,13 +33,17 @@ public StringValueAttribute(string value)
3133
}
3234
}
3335

36+
[Obsolete("This class will be removed in a future version of QRCoder.")]
3437
public static class CustomExtensions
3538
{
3639
/// <summary>
3740
/// Will get the string value for a given enum's value
3841
/// </summary>
3942
/// <param name="value"></param>
4043
/// <returns></returns>
44+
#if NET6_0_OR_GREATER
45+
[RequiresUnreferencedCode("This method uses reflection to examine the provided enum value.")]
46+
#endif
4147
public static string GetStringValue(this Enum value)
4248
{
4349
#if NETSTANDARD1_3

QRCoder/PayloadGenerator.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Globalization;
55
using System.Text;
66
using System.Text.RegularExpressions;
7+
using System.Diagnostics.CodeAnalysis;
78
#if NETSTANDARD1_3
89
using System.Reflection;
910
#endif
@@ -2477,14 +2478,12 @@ public class RussiaPaymentOrder : Payload
24772478

24782479
//base
24792480
private CharacterSets characterSet;
2480-
private MandatoryFields mFields;
2481-
private OptionalFields oFields;
2481+
private readonly MandatoryFields mFields = new MandatoryFields();
2482+
private readonly OptionalFields oFields = new OptionalFields();
24822483
private string separator = "|";
24832484

24842485
private RussiaPaymentOrder()
24852486
{
2486-
mFields = new MandatoryFields();
2487-
oFields = new OptionalFields();
24882487
}
24892488

24902489
/// <summary>
@@ -2596,7 +2595,7 @@ private string DetermineSeparator()
25962595
private List<string> GetOptionalFieldsAsList()
25972596
{
25982597
#if NETSTANDARD1_3
2599-
return oFields.GetType().GetRuntimeProperties()
2598+
return typeof(OptionalFields).GetRuntimeProperties()
26002599
.Where(field => field.GetValue(oFields) != null)
26012600
.Select(field => {
26022601
var objValue = field.GetValue(oFields, null);
@@ -2605,7 +2604,7 @@ private List<string> GetOptionalFieldsAsList()
26052604
})
26062605
.ToList();
26072606
#else
2608-
return oFields.GetType().GetProperties()
2607+
return typeof(OptionalFields).GetProperties()
26092608
.Where(field => field.GetValue(oFields, null) != null)
26102609
.Select(field => {
26112610
var objValue = field.GetValue(oFields, null);
@@ -2624,7 +2623,7 @@ private List<string> GetOptionalFieldsAsList()
26242623
private List<string> GetMandatoryFieldsAsList()
26252624
{
26262625
#if NETSTANDARD1_3
2627-
return mFields.GetType().GetRuntimeFields()
2626+
return typeof(MandatoryFields).GetRuntimeFields()
26282627
.Where(field => field.GetValue(mFields) != null)
26292628
.Select(field => {
26302629
var objValue = field.GetValue(mFields);
@@ -2633,7 +2632,7 @@ private List<string> GetMandatoryFieldsAsList()
26332632
})
26342633
.ToList();
26352634
#else
2636-
return mFields.GetType().GetFields()
2635+
return typeof(MandatoryFields).GetFields()
26372636
.Where(field => field.GetValue(mFields) != null)
26382637
.Select(field => {
26392638
var objValue = field.GetValue(mFields);

QRCoder/SvgQRCode.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public MediaType GetMediaType()
362362
/// <returns></returns>
363363
public string GetDataUri()
364364
{
365-
return $"data:{_mediaType.GetStringValue()};base64,{_logoData}";
365+
return $"data:{GetMimeType(_mediaType)};base64,{_logoData}";
366366
}
367367

368368
/// <summary>
@@ -388,11 +388,29 @@ public bool FillLogoBackground()
388388
/// </summary>
389389
public enum MediaType : int
390390
{
391+
#pragma warning disable CS0618 // Type or member is obsolete
391392
[StringValue("image/png")]
392-
PNG = 0,
393+
#pragma warning restore CS0618 // Type or member is obsolete
394+
PNG = 0,
395+
#pragma warning disable CS0618 // Type or member is obsolete
393396
[StringValue("image/svg+xml")]
397+
#pragma warning restore CS0618 // Type or member is obsolete
394398
SVG = 1
395399
}
400+
401+
private string GetMimeType(MediaType type)
402+
{
403+
switch (type)
404+
{
405+
case MediaType.PNG:
406+
return "image/png";
407+
case MediaType.SVG:
408+
return "image/svg+xml";
409+
default:
410+
throw new ArgumentOutOfRangeException(nameof(type));
411+
}
412+
}
413+
396414
}
397415
}
398416

0 commit comments

Comments
 (0)