@@ -58,7 +58,8 @@ public byte[] BuildSwaggerJson()
5858 : null ;
5959
6060 doc . tags = handlers
61- . Select ( x => x . DeclaringType . Name )
61+ // MemberInfo.DeclaringType is null only if it is a member of a VB Module.
62+ . Select ( x => x . DeclaringType ! . Name )
6263 . Distinct ( )
6364 . Select ( x =>
6465 {
@@ -77,16 +78,19 @@ public byte[] BuildSwaggerJson()
7778
7879 foreach ( var item in handlers )
7980 {
81+ // MemberInfo.DeclaringType is null only if it is a member of a VB Module.
82+ string declaringTypeName = item . DeclaringType ! . Name ;
8083 XmlCommentStructure xmlComment = null ;
8184 if ( xDocLookup != null )
8285 {
83- xmlComment = xDocLookup [ Tuple . Create ( item . DeclaringType . Name , item . Name ) ] . FirstOrDefault ( ) ;
86+ // ParameterInfo.Name will be null only it is ReturnParameter.
87+ xmlComment = xDocLookup [ Tuple . Create ( declaringTypeName , item . Name ! ) ] . FirstOrDefault ( ) ;
8488 }
8589
8690 var parameters = BuildParameters ( doc . definitions , xmlComment , item ) ;
8791 var operation = new Operation
8892 {
89- tags = new [ ] { item . DeclaringType . Name } ,
93+ tags = new [ ] { declaringTypeName } ,
9094 summary = ( xmlComment != null ) ? xmlComment . Summary : "" ,
9195 description = ( xmlComment != null ) ? xmlComment . Remarks : "" ,
9296 parameters = parameters ,
@@ -96,7 +100,7 @@ public byte[] BuildSwaggerJson()
96100 }
97101 } ;
98102
99- doc . paths . Add ( "/" + item . DeclaringType . Name + "/" + item . Name , new PathItem { post = operation } ) ; // everything post.
103+ doc . paths . Add ( "/" + declaringTypeName + "/" + item . Name , new PathItem { post = operation } ) ; // everything post.
100104 }
101105
102106 using ( var ms = new MemoryStream ( ) )
@@ -128,7 +132,7 @@ Schemas.Parameter[] BuildParameters(IDictionary<string, Schema> definitions, Xml
128132 var parameterXmlComment = UnwrapTypeName ( x . ParameterType ) ;
129133 if ( xmlComment != null )
130134 {
131- xmlComment . Parameters . TryGetValue ( x . Name , out parameterXmlComment ) ;
135+ xmlComment . Parameters . TryGetValue ( x . Name , out parameterXmlComment ! ) ;
132136 parameterXmlComment = UnwrapTypeName ( x . ParameterType ) + " " + parameterXmlComment ;
133137 }
134138
@@ -147,7 +151,8 @@ Schemas.Parameter[] BuildParameters(IDictionary<string, Schema> definitions, Xml
147151 object [ ] enums = null ;
148152 if ( x . ParameterType . GetTypeInfo ( ) . IsEnum || ( collectionType != null && collectionType . GetTypeInfo ( ) . IsEnum ) )
149153 {
150- var enumType = ( x . ParameterType . GetTypeInfo ( ) . IsEnum ) ? x . ParameterType : collectionType ;
154+ // Compiler cannot understand collectionType is not null.
155+ var enumType = ( x . ParameterType . GetTypeInfo ( ) . IsEnum ) ? x . ParameterType : collectionType ! ;
151156
152157 var enumValues = Enum . GetNames ( enumType ) ;
153158
@@ -374,7 +379,8 @@ static string ToSwaggerDataType(Type type)
374379
375380 if ( type . IsNullable ( ) )
376381 {
377- type = Nullable . GetUnderlyingType ( type ) ;
382+ // if type is Nullable<T>, it has UnderlyingType T.
383+ type = Nullable . GetUnderlyingType ( type ) ! ;
378384 }
379385
380386 if ( type . GetTypeInfo ( ) . IsEnum || type == typeof ( DateTime ) || type == typeof ( DateTimeOffset ) )
@@ -462,13 +468,13 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
462468 enumerable = instance
463469 . GetType ( )
464470 . GetProperty ( member . Name )
465- . GetValue ( instance , null ) as IEnumerable ;
471+ ? . GetValue ( instance , null ) as IEnumerable ;
466472 break ;
467473 case MemberTypes . Field :
468474 enumerable = instance
469475 . GetType ( )
470476 . GetField ( member . Name )
471- . GetValue ( instance ) as IEnumerable ;
477+ ? . GetValue ( instance ) as IEnumerable ;
472478 break ;
473479 default :
474480 break ;
0 commit comments