@@ -16,26 +16,25 @@ public Cref(string cref)
16
16
17
17
var lastIndexOf = cref . LastIndexOf ( '.' ) ;
18
18
19
- if ( Prefix is "T:" )
19
+ switch ( Prefix )
20
20
{
21
- Type = cref . Substring ( lastIndexOf + 1 , cref . Length - lastIndexOf - 1 ) ;
22
- Member = null ;
23
- }
24
- else if ( Prefix is "M:" or "P:" or "F:" )
25
- {
26
- Type = cref . Substring ( 2 , lastIndexOf - 2 ) ;
27
- Member = cref . Substring ( lastIndexOf + 1 , cref . Length - lastIndexOf - 1 ) ;
28
- }
29
- else
30
- {
31
- throw new ArgumentException ( $ "Invalid cref: { cref } ") ;
21
+ case "T:" :
22
+ Type = cref . Substring ( lastIndexOf + 1 , cref . Length - lastIndexOf - 1 ) ;
23
+ Member = null ;
24
+ break ;
25
+ case "M:" or "P:" or "F:" :
26
+ Type = cref . Substring ( 2 , lastIndexOf - 2 ) ;
27
+ Member = cref . Substring ( lastIndexOf + 1 , cref . Length - lastIndexOf - 1 ) ;
28
+ break ;
29
+ default :
30
+ throw new ArgumentException ( $ "Invalid cref: { cref } ") ;
32
31
}
33
32
34
33
var typeLastIndexOf = Type . LastIndexOf ( '.' ) ;
35
34
36
35
ShortType = Type . Substring ( typeLastIndexOf + 1 , Type . Length - typeLastIndexOf - 1 ) ;
37
36
}
38
-
37
+
39
38
/// <summary>
40
39
/// The prefix of the cref (e.g. "T:", "M:", "P:", "F:").
41
40
/// </summary>
@@ -64,4 +63,24 @@ public override string ToString()
64
63
{
65
64
return $ "{ Prefix } { Type } { ( Member != null ? "." + Member : string . Empty ) } ";
66
65
}
66
+
67
+ /// <summary>
68
+ ///
69
+ /// </summary>
70
+ /// <param name="value"></param>
71
+ /// <param name="cref"></param>
72
+ /// <returns></returns>
73
+ public static bool TryCreate ( string ? value , out Cref ? cref )
74
+ {
75
+ try
76
+ {
77
+ cref = new Cref ( value ! ) ;
78
+ }
79
+ catch
80
+ {
81
+ cref = null ;
82
+ }
83
+
84
+ return cref != null ;
85
+ }
67
86
}
0 commit comments