1
1
#region PDFsharp - A .NET library for processing PDF
2
+
2
3
//
3
4
// Authors:
4
5
// Stefan Lange
25
26
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26
27
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
28
// DEALINGS IN THE SOFTWARE.
29
+
28
30
#endregion
29
31
30
32
using System ;
35
37
using System . IO ;
36
38
using System . Text ;
37
39
38
- namespace PdfSharpCore . Pdf . Content . Objects // TODO: split into single files
40
+ namespace PdfSharpCore . Pdf . Content . Objects // TODO: split into single files
39
41
{
40
42
/// <summary>
41
43
/// Base class for all PDF content stream objects.
@@ -46,7 +48,8 @@ public abstract class CObject : ICloneable
46
48
/// Initializes a new instance of the <see cref="CObject"/> class.
47
49
/// </summary>
48
50
protected CObject ( )
49
- { }
51
+ {
52
+ }
50
53
51
54
/// <summary>
52
55
/// Creates a new object that is a copy of the current instance.
@@ -109,6 +112,7 @@ public string Text
109
112
get { return _text ; }
110
113
set { _text = value ; }
111
114
}
115
+
112
116
string _text ;
113
117
114
118
/// <summary>
@@ -129,7 +133,7 @@ internal override void WriteObject(ContentWriter writer)
129
133
/// Represents a sequence of objects in a PDF content stream.
130
134
/// </summary>
131
135
[ DebuggerDisplay ( "(count={Count})" ) ]
132
- public class CSequence : CObject , IList < CObject > // , ICollection<CObject>, IEnumerable<CObject>
136
+ public class CSequence : CObject , IList < CObject > // , ICollection<CObject>, IEnumerable<CObject>
133
137
{
134
138
/// <summary>
135
139
/// Creates a new object that is a copy of the current instance.
@@ -250,6 +254,7 @@ public CObject this[int index]
250
254
get { return ( CObject ) _items [ index ] ; }
251
255
set { _items [ index ] = value ; }
252
256
}
257
+
253
258
#endregion
254
259
255
260
#region ICollection Members
@@ -362,14 +367,8 @@ void IList<CObject>.RemoveAt(int index)
362
367
363
368
CObject IList < CObject > . this [ int index ]
364
369
{
365
- get
366
- {
367
- throw new NotImplementedException ( ) ;
368
- }
369
- set
370
- {
371
- throw new NotImplementedException ( ) ;
372
- }
370
+ get { throw new NotImplementedException ( ) ; }
371
+ set { throw new NotImplementedException ( ) ; }
373
372
}
374
373
375
374
#endregion
@@ -484,6 +483,7 @@ public int Value
484
483
get { return _value ; }
485
484
set { _value = value ; }
486
485
}
486
+
487
487
int _value ;
488
488
489
489
/// <summary>
@@ -531,6 +531,7 @@ public double Value
531
531
get { return _value ; }
532
532
set { _value = value ; }
533
533
}
534
+
534
535
double _value ;
535
536
536
537
/// <summary>
@@ -611,6 +612,7 @@ public string Value
611
612
get { return _value ; }
612
613
set { _value = value ; }
613
614
}
615
+
614
616
string _value ;
615
617
616
618
/// <summary>
@@ -621,6 +623,7 @@ public CStringType CStringType
621
623
get { return _cStringType ; }
622
624
set { _cStringType = value ; }
623
625
}
626
+
624
627
CStringType _cStringType ;
625
628
626
629
/// <summary>
@@ -687,6 +690,7 @@ public override string ToString()
687
690
break ;
688
691
}
689
692
}
693
+
690
694
s . Append ( ')' ) ;
691
695
break ;
692
696
@@ -710,6 +714,7 @@ public override string ToString()
710
714
default :
711
715
throw new ArgumentOutOfRangeException ( ) ;
712
716
}
717
+
713
718
return s . ToString ( ) ;
714
719
}
715
720
@@ -725,12 +730,14 @@ internal override void WriteObject(ContentWriter writer)
725
730
[ DebuggerDisplay ( "({Name})" ) ]
726
731
public class CName : CObject
727
732
{
733
+ private const string NamePrefix = "/" ;
734
+
728
735
/// <summary>
729
736
/// Initializes a new instance of the <see cref="CName"/> class.
730
737
/// </summary>
731
738
public CName ( )
732
739
{
733
- _name = "/" ;
740
+ _name = NamePrefix ;
734
741
}
735
742
736
743
/// <summary>
@@ -760,21 +767,24 @@ protected override CObject Copy()
760
767
}
761
768
762
769
/// <summary>
763
- /// Gets or sets the name. Names must start with a slash.
770
+ /// Gets or sets the content stream name. Names must start with a slash.
764
771
/// </summary>
772
+ /// <exception cref="ArgumentNullException"></exception>
773
+ /// <exception cref="ArgumentException">If <paramref name="value"/> does not start with a forward slash</exception>
765
774
public string Name
766
775
{
767
- get { return _name ; }
776
+ get => _name ;
768
777
set
769
778
{
770
- if ( String . IsNullOrEmpty ( _name ) )
771
- throw new ArgumentNullException ( "name" ) ;
772
- if ( _name [ 0 ] != '/' )
773
- throw new ArgumentException ( PSSR . NameMustStartWithSlash ) ;
779
+ if ( string . IsNullOrEmpty ( value ) )
780
+ throw new ArgumentNullException ( nameof ( value ) ) ;
781
+ if ( ! value . StartsWith ( NamePrefix ) )
782
+ throw new ArgumentException ( PSSR . NameMustStartWithSlash , nameof ( value ) ) ;
774
783
_name = value ;
775
784
}
776
785
}
777
- string _name ;
786
+
787
+ private string _name ;
778
788
779
789
/// <summary>
780
790
/// Returns a string that represents the current value.
@@ -837,7 +847,8 @@ public class COperator : CObject
837
847
/// Initializes a new instance of the <see cref="COperator"/> class.
838
848
/// </summary>
839
849
protected COperator ( )
840
- { }
850
+ {
851
+ }
841
852
842
853
internal COperator ( OpCode opcode )
843
854
{
@@ -878,6 +889,7 @@ public CSequence Operands
878
889
{
879
890
get { return _seqence ?? ( _seqence = new CSequence ( ) ) ; }
880
891
}
892
+
881
893
CSequence _seqence ;
882
894
883
895
/// <summary>
@@ -887,6 +899,7 @@ public OpCode OpCode
887
899
{
888
900
get { return _opcode ; }
889
901
}
902
+
890
903
readonly OpCode _opcode ;
891
904
892
905
@@ -903,13 +916,14 @@ public override string ToString()
903
916
904
917
internal override void WriteObject ( ContentWriter writer )
905
918
{
906
- int count = _seqence != null ? _seqence . Count : 0 ;
919
+ int count = _seqence ? . Count ?? 0 ;
907
920
for ( int idx = 0 ; idx < count ; idx ++ )
908
921
{
909
922
// ReSharper disable once PossibleNullReferenceException because the loop is not entered if _sequence is null
910
923
_seqence [ idx ] . WriteObject ( writer ) ;
911
924
}
925
+
912
926
writer . WriteLineRaw ( ToString ( ) ) ;
913
927
}
914
928
}
915
- }
929
+ }
0 commit comments