@@ -28,8 +28,6 @@ public class FileMakerClip
2828 /// <param name="data">Data containing the clip.</param>
2929 public FileMakerClip ( string name , string format , byte [ ] data )
3030 {
31- // pull in the name
32- Name = name ;
3331 // load the format
3432 ClipboardFormat = format ;
3533 // skip the first four bytes, as this is a length check
@@ -40,11 +38,10 @@ public FileMakerClip(string name, string format, byte[] data)
4038
4139 // try to show better "name" if possible
4240 var xdoc = XDocument . Load ( new StringReader ( XmlData ) ) ;
43- var containerName = xdoc . Element ( "fmxmlsnippet" ) ? . Descendants ( ) . First ( ) ? . Attribute ( "name" ) ? . Value ;
44- if ( ! string . IsNullOrEmpty ( containerName ) )
45- {
46- Name = containerName ;
47- }
41+ var containerName = xdoc . Element ( "fmxmlsnippet" ) ? . Descendants ( ) . First ( ) ? . Attribute ( "name" ) ? . Value ?? "" ;
42+
43+ // set the name from the xml data if possible and fall back to constructor parameter
44+ Name = containerName ?? name ?? "new-clip" ;
4845 }
4946
5047 /// <summary>
@@ -55,7 +52,7 @@ public FileMakerClip(string name, string format, byte[] data)
5552 /// <summary>
5653 /// Name of Clip
5754 /// </summary>
58- public string Name { get ; set ; }
55+ public string Name { get ; set ; } = string . Empty ;
5956
6057 /// <summary>
6158 /// Raw data that can be put back onto the Clipboard in FileMaker structure.
@@ -94,19 +91,19 @@ public IEnumerable<FileMakerField> Fields
9491 . Elements ( "Field" )
9592 . Select ( x => new FileMakerField
9693 {
97- FileMakerFieldId = int . Parse ( x . Attribute ( "id" ) . Value ) ,
98- Name = x . Attribute ( "name" ) . Value ,
99- DataType = x . Attribute ( "dataType" ) . Value ,
100- FieldType = x . Attribute ( "fieldType" ) . Value ,
101- NotEmpty = bool . Parse ( x . Element ( "Validation" ) ? . Element ( "NotEmpty" ) ? . Attribute ( "value" ) . Value ?? "false" ) ,
102- Unique = bool . Parse ( x . Element ( "Validation" ) ? . Element ( "Unique" ) ? . Attribute ( "value" ) . Value ?? "false" ) ,
94+ FileMakerFieldId = int . Parse ( x . Attribute ( "id" ) ? . Value ?? "" ) ,
95+ Name = x . Attribute ( "name" ) ? . Value ?? "" ,
96+ DataType = x . Attribute ( "dataType" ) ? . Value ?? "" ,
97+ FieldType = x . Attribute ( "fieldType" ) ? . Value ?? "" ,
98+ NotEmpty = bool . Parse ( x . Element ( "Validation" ) ? . Element ( "NotEmpty" ) ? . Attribute ( "value" ) ? . Value ?? "false" ) ,
99+ Unique = bool . Parse ( x . Element ( "Validation" ) ? . Element ( "Unique" ) ? . Attribute ( "value" ) ? . Value ?? "false" ) ,
103100 Comment = x . Element ( "Comment" ) ? . Value ,
104101 } ) ;
105102
106103 case "Layout" : // on a layout we only have the field name (TABLE::FIELD) to go on, so we do that.
107104 return xdoc
108105 . Descendants ( "Object" )
109- . Where ( x => x . Attribute ( "type" ) . Value == "Field" )
106+ . Where ( x => x . Attribute ( "type" ) ? . Value == "Field" )
110107 . Descendants ( "FieldObj" )
111108 . Elements ( "Name" )
112109 . Select ( x => new FileMakerField { Name = Regex . Split ( x . Value , "::" ) [ 1 ] } ) ;
0 commit comments