@@ -94,8 +94,7 @@ public static List<Type> AllMetadataTypes
9494
9595 public static string GetDisplayName ( Type metadataType )
9696 {
97- if ( metadataType == null )
98- return null ;
97+ if ( metadataType == null ) throw new NullReferenceException ( nameof ( metadataType ) ) ;
9998 EnsureInitialized ( ) ;
10099 if ( metadataNames . TryGetValue ( metadataType , out var value ) )
101100 return value . displayName ;
@@ -104,17 +103,19 @@ public static string GetDisplayName(Type metadataType)
104103
105104 public static string GetMenuName ( Type metadataType )
106105 {
107- if ( metadataType == null )
108- return null ;
106+ if ( metadataType == null ) throw new NullReferenceException ( nameof ( metadataType ) ) ;
109107 EnsureInitialized ( ) ;
110108 if ( metadataNames . TryGetValue ( metadataType , out var value ) )
111109 return value . menuPath ;
112110 return ObjectNames . NicifyVariableName ( metadataType . Name ) ;
113111 }
114112
115113 public static void GetAll ( UnityEngine . Object target , List < CustomAssetMetadata > metadata )
116- {
117- var assetPath = AssetDatabase . GetAssetPath ( target ) ;
114+ {
115+ if ( target == null || ReferenceEquals ( target , null ) ) throw new NullReferenceException ( nameof ( target ) ) ;
116+ if ( metadata == null ) throw new NullReferenceException ( nameof ( metadata ) ) ;
117+ EnsureInitialized ( ) ;
118+ var assetPath = AssetDatabase . GetAssetPath ( target ) ;
118119 if ( assetPath == null ||
119120 string . IsNullOrEmpty ( assetPath ) )
120121 return ;
@@ -130,8 +131,11 @@ public static void GetAll(UnityEngine.Object target, List<CustomAssetMetadata> m
130131 }
131132
132133 public static CustomAssetMetadata Add ( UnityEngine . Object target , Type type )
133- {
134- if ( ! CanAddMetadataType ( target , type ) )
134+ {
135+ if ( target == null || ReferenceEquals ( target , null ) ) throw new NullReferenceException ( nameof ( target ) ) ;
136+ if ( type == null ) throw new NullReferenceException ( nameof ( type ) ) ;
137+ EnsureInitialized ( ) ;
138+ if ( ! CanAddMetadataType ( target , type ) )
135139 return null ;
136140
137141 var assetPath = AssetDatabase . GetAssetPath ( target ) ;
@@ -161,9 +165,10 @@ public static CustomAssetMetadata Add(UnityEngine.Object target, Type type)
161165 }
162166
163167 public static bool CanAddMetadataType ( UnityEngine . Object target , Type type )
164- {
165- if ( ReferenceEquals ( target , null ) || target == null )
166- return false ;
168+ {
169+ if ( type == null ) throw new NullReferenceException ( nameof ( type ) ) ;
170+ if ( target == null || ReferenceEquals ( target , null ) ) throw new NullReferenceException ( nameof ( target ) ) ;
171+ EnsureInitialized ( ) ;
167172 if ( disallowMultipleMetadataLookup . Contains ( type ) )
168173 {
169174 if ( MetadataLookup . HasMetadataOfType ( target , type ) )
@@ -184,15 +189,17 @@ public static bool CanAddMetadataType(UnityEngine.Object target, Type type)
184189 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
185190 public static CustomAssetMetadata Add < Metadata > ( UnityEngine . Object target )
186191 where Metadata : CustomAssetMetadata
187- {
188- return Add ( target , typeof ( Metadata ) ) ;
192+ {
193+ if ( target == null || ReferenceEquals ( target , null ) ) throw new NullReferenceException ( nameof ( target ) ) ;
194+ EnsureInitialized ( ) ;
195+ return Add ( target , typeof ( Metadata ) ) ;
189196 }
190197
191198 public static void Destroy < Metadata > ( Metadata metadata )
192199 where Metadata : CustomAssetMetadata
193- {
194- if ( metadata == null )
195- return ;
200+ {
201+ if ( metadata == null || ReferenceEquals ( metadata , null ) ) throw new NullReferenceException ( nameof ( metadata ) ) ;
202+ EnsureInitialized ( ) ;
196203
197204 var assetPath = AssetDatabase . GetAssetPath ( metadata ) ;
198205 if ( assetPath == null )
0 commit comments