@@ -42,10 +42,13 @@ public static object GetCurrentValidCulture()
4242 t . IsEnum && ! t . Name . EndsWith ( "Query" ) && ! t . Name . EndsWith ( "Message" ) )
4343 . ToDictionaryEx ( GetTypeName , "Types" ) ) ;
4444
45- public static void RegisterLike ( Type type )
45+ public static Dictionary < string , Func < bool > > OverrideIsNamespaceAllowed = new Dictionary < string , Func < bool > > ( ) ;
46+
47+ public static void RegisterLike ( Type type , Func < bool > allowed )
4648 {
4749 TypesByName . Reset ( ) ;
4850 EntityAssemblies . GetOrCreate ( type . Assembly ) . Add ( type . Namespace ! ) ;
51+ OverrideIsNamespaceAllowed [ type . Namespace ! ] = allowed ;
4952 }
5053
5154 internal static void Start ( )
@@ -64,54 +67,68 @@ internal static void Start()
6467 const BindingFlags instanceFlags = BindingFlags . Public | BindingFlags . Instance | BindingFlags . DeclaredOnly ;
6568 const BindingFlags staticFlags = BindingFlags . Public | BindingFlags . Static | BindingFlags . DeclaredOnly ;
6669
67- public static event Action < TypeInfoTS , Type > ? AddTypeExtension ;
68- static TypeInfoTS OnAddTypeExtension ( TypeInfoTS ti , Type t )
70+ public static event Func < TypeInfoTS , Type , TypeInfoTS ? > ? TypeExtension ;
71+ static TypeInfoTS ? OnTypeExtension ( TypeInfoTS ti , Type t )
6972 {
70- foreach ( var a in AddTypeExtension . GetInvocationListTyped ( ) )
71- a ( ti , t ) ;
73+ foreach ( var a in TypeExtension . GetInvocationListTyped ( ) )
74+ {
75+ ti = a ( ti , t ) ! ;
76+ if ( ti == null )
77+ return null ;
78+ }
7279
7380 return ti ;
7481 }
7582
76- public static event Action < MemberInfoTS , PropertyRoute > ? AddPropertyRouteExtension ;
77- static MemberInfoTS OnAddPropertyRouteExtension ( MemberInfoTS mi , PropertyRoute m )
83+ public static event Func < MemberInfoTS , PropertyRoute , MemberInfoTS ? > ? PropertyRouteExtension ;
84+ static MemberInfoTS ? OnPropertyRouteExtension ( MemberInfoTS mi , PropertyRoute m )
7885 {
79- if ( AddPropertyRouteExtension == null )
86+ if ( PropertyRouteExtension == null )
8087 return mi ;
8188
82- foreach ( var a in AddPropertyRouteExtension . GetInvocationListTyped ( ) )
83- a ( mi , m ) ;
89+ foreach ( var a in PropertyRouteExtension . GetInvocationListTyped ( ) )
90+ {
91+ mi = a ( mi , m ) ! ;
92+ if ( mi == null )
93+ return null ;
94+ }
8495
8596 return mi ;
8697 }
8798
8899
89- public static event Action < MemberInfoTS , FieldInfo > ? AddFieldInfoExtension ;
90- static MemberInfoTS OnAddFieldInfoExtension ( MemberInfoTS mi , FieldInfo m )
100+ public static event Func < MemberInfoTS , FieldInfo , MemberInfoTS ? > ? FieldInfoExtension ;
101+ static MemberInfoTS ? OnFieldInfoExtension ( MemberInfoTS mi , FieldInfo m )
91102 {
92- if ( AddFieldInfoExtension == null )
103+ if ( FieldInfoExtension == null )
93104 return mi ;
94105
95- foreach ( var a in AddFieldInfoExtension . GetInvocationListTyped ( ) )
96- a ( mi , m ) ;
106+ foreach ( var a in FieldInfoExtension . GetInvocationListTyped ( ) )
107+ {
108+ mi = a ( mi , m ) ! ;
109+ if ( mi == null )
110+ return null ;
111+ }
97112
98113 return mi ;
99114 }
100115
101- public static event Action < OperationInfoTS , OperationInfo , Type > ? AddOperationExtension ;
102- static OperationInfoTS OnAddOperationExtension ( OperationInfoTS oi , OperationInfo o , Type type )
116+ public static event Func < OperationInfoTS , OperationInfo , Type , OperationInfoTS ? > ? OperationExtension ;
117+ static OperationInfoTS ? OnOperationExtension ( OperationInfoTS oi , OperationInfo o , Type type )
103118 {
104- if ( AddOperationExtension == null )
119+ if ( OperationExtension == null )
105120 return oi ;
106121
107- foreach ( var a in AddOperationExtension . GetInvocationListTyped ( ) )
108- a ( oi , o , type ) ;
122+ foreach ( var a in OperationExtension . GetInvocationListTyped ( ) )
123+ {
124+ oi = a ( oi , o , type ) ! ;
125+ if ( oi == null )
126+ return null ;
127+ }
109128
110129 return oi ;
111130 }
112131
113-
114-
115132 public static HashSet < Type > ExcludeTypes = new HashSet < Type > ( ) ;
116133
117134 internal static Dictionary < string , TypeInfoTS > GetTypeInfoTS ( )
@@ -167,7 +184,7 @@ where typeof(ModelEntity).IsAssignableFrom(type) && !type.IsAbstract
167184 where ! type . IsEnumEntity ( ) && ! ReflectionServer . ExcludeTypes . Contains ( type )
168185 let descOptions = LocalizedAssembly . GetDescriptionOptions ( type )
169186 let allOperations = ! type . IsEntity ( ) ? null : OperationLogic . GetAllOperationInfos ( type )
170- select KeyValuePair . Create ( GetTypeName ( type ) , OnAddTypeExtension ( new TypeInfoTS
187+ select KeyValuePair . Create ( GetTypeName ( type ) , OnTypeExtension ( new TypeInfoTS
171188 {
172189 Kind = KindOfType . Entity ,
173190 FullName = type . FullName ! ,
@@ -182,7 +199,7 @@ select KeyValuePair.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS
182199 QueryDefined = queries . QueryDefined ( type ) ,
183200 Members = PropertyRoute . GenerateRoutes ( type )
184201 . Where ( pr => InTypeScript ( pr ) )
185- . ToDictionary ( p => p . PropertyString ( ) , p =>
202+ . Select ( p =>
186203 {
187204 var validators = Validator . TryGetPropertyValidator ( p ) ? . Validators ;
188205
@@ -196,19 +213,24 @@ select KeyValuePair.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS
196213 Unit = UnitAttribute . GetTranslation ( p . PropertyInfo ? . GetCustomAttribute < UnitAttribute > ( ) ? . UnitName ) ,
197214 Type = new TypeReferenceTS ( IsId ( p ) ? PrimaryKey . Type ( type ) . Nullify ( ) : p . PropertyInfo ! . PropertyType , p . Type . IsMList ( ) ? p . Add ( "Item" ) . TryGetImplementations ( ) : p . TryGetImplementations ( ) ) ,
198215 IsMultiline = validators ? . OfType < StringLengthValidatorAttribute > ( ) . FirstOrDefault ( ) ? . MultiLine ?? false ,
199- IsVirtualMList = p . IsVirtualMList ( ) ,
216+ IsVirtualMList = p . IsVirtualMList ( ) ,
200217 MaxLength = validators ? . OfType < StringLengthValidatorAttribute > ( ) . FirstOrDefault ( ) ? . Max . DefaultToNull ( - 1 ) ,
201218 PreserveOrder = settings . FieldAttributes ( p ) ? . OfType < PreserveOrderAttribute > ( ) . Any ( ) ?? false ,
202219 } ;
203220
204- return OnAddPropertyRouteExtension ( mi , p ) ;
205- } ) ,
221+ return KeyValuePair . Create ( p . PropertyString ( ) , OnPropertyRouteExtension ( mi , p ) ! ) ;
222+ } )
223+ . Where ( kvp => kvp . Value != null )
224+ . ToDictionaryEx ( "properties" ) ,
206225
207- Operations = allOperations == null ? null : allOperations . ToDictionary ( oi => oi . OperationSymbol . Key , oi => OnAddOperationExtension ( new OperationInfoTS ( oi ) , oi , type ) ) ,
226+ HasConstructorOperation = allOperations != null && allOperations . Any ( oi => oi . OperationType == OperationType . Constructor ) ,
227+ Operations = allOperations == null ? null : allOperations . Select ( oi => KeyValuePair . Create ( oi . OperationSymbol . Key , OnOperationExtension ( new OperationInfoTS ( oi ) , oi , type ) ! ) ) . Where ( kvp => kvp . Value != null ) . ToDictionaryEx ( "operations" ) ,
208228
209229 RequiresEntityPack = allOperations != null && allOperations . Any ( oi => oi . HasCanExecute != null ) ,
210230
211- } , type ) ) ) . ToDictionaryEx ( "entities" ) ;
231+ } , type ) ) )
232+ . Where ( kvp => kvp . Value != null )
233+ . ToDictionaryEx ( "entities" ) ;
212234
213235 return result ;
214236 }
@@ -248,19 +270,23 @@ where type.IsEnum
248270 where descOptions != DescriptionOptions . None
249271 let kind = type . Name . EndsWith ( "Query" ) ? KindOfType . Query :
250272 type . Name . EndsWith ( "Message" ) ? KindOfType . Message : KindOfType . Enum
251- select KeyValuePair . Create ( GetTypeName ( type ) , OnAddTypeExtension ( new TypeInfoTS
273+ select KeyValuePair . Create ( GetTypeName ( type ) , OnTypeExtension ( new TypeInfoTS
252274 {
253275 Kind = kind ,
254276 FullName = type . FullName ! ,
255277 NiceName = descOptions . HasFlag ( DescriptionOptions . Description ) ? type . NiceName ( ) : null ,
256278 Members = type . GetFields ( staticFlags )
257279 . Where ( fi => kind != KindOfType . Query || queries . QueryDefined ( fi . GetValue ( null ) ! ) )
258- . ToDictionary ( fi => fi . Name , fi => OnAddFieldInfoExtension ( new MemberInfoTS
280+ . Select ( fi => KeyValuePair . Create ( fi . Name , OnFieldInfoExtension ( new MemberInfoTS
259281 {
260282 NiceName = fi . NiceName ( ) ,
261283 IsIgnoredEnum = kind == KindOfType . Enum && fi . HasAttribute < IgnoreAttribute > ( )
262- } , fi ) ) ,
263- } , type ) ) ) . ToDictionaryEx ( "enums" ) ;
284+ } , fi ) ! ) )
285+ . Where ( a=> a . Value != null )
286+ . ToDictionaryEx ( "query" ) ,
287+ } , type ) ) )
288+ . Where ( a => a . Value != null )
289+ . ToDictionaryEx ( "enums" ) ;
264290
265291 return result ;
266292 }
@@ -271,7 +297,7 @@ public static Dictionary<string, TypeInfoTS> GetSymbolContainers(IEnumerable<Typ
271297
272298 var result = ( from type in allTypes
273299 where type . IsStaticClass ( ) && type . HasAttribute < AutoInitAttribute > ( )
274- select KeyValuePair . Create ( GetTypeName ( type ) , OnAddTypeExtension ( new TypeInfoTS
300+ select KeyValuePair . Create ( GetTypeName ( type ) , OnTypeExtension ( new TypeInfoTS
275301 {
276302 Kind = KindOfType . SymbolContainer ,
277303 FullName = type . FullName ! ,
@@ -280,13 +306,15 @@ select KeyValuePair.Create(GetTypeName(type), OnAddTypeExtension(new TypeInfoTS
280306 . Where ( s =>
281307 s . FieldInfo != null && /*Duplicated like in Dynamic*/
282308 s . IdOrNull . HasValue /*Not registered*/ )
283- . ToDictionary ( s => s . FieldInfo . Name , s => OnAddFieldInfoExtension ( new MemberInfoTS
309+ . Select ( s => KeyValuePair . Create ( s . FieldInfo . Name , OnFieldInfoExtension ( new MemberInfoTS
284310 {
285311 NiceName = s . FieldInfo . NiceName ( ) ,
286312 Id = s . IdOrNull ! . Value . Object
287- } , s . FieldInfo ) )
313+ } , s . FieldInfo ) ! ) )
314+ . Where ( a => a . Value != null )
315+ . ToDictionaryEx ( "fields" ) ,
288316 } , type ) ) )
289- . Where ( a => a . Value . Members . Any ( ) )
317+ . Where ( a => a . Value != null && a . Value . Members . Any ( ) )
290318 . ToDictionaryEx ( "symbols" ) ;
291319
292320 return result ;
@@ -340,9 +368,11 @@ public class TypeInfoTS
340368 [ JsonProperty ( NullValueHandling = NullValueHandling . Ignore , PropertyName = "toStringFunction" ) ]
341369 public string ? ToStringFunction { get ; set ; }
342370 [ JsonProperty ( DefaultValueHandling = DefaultValueHandling . Ignore , PropertyName = "queryDefined" ) ]
343- public bool QueryDefined { get ; internal set ; }
371+ public bool QueryDefined { get ; set ; }
344372 [ JsonProperty ( NullValueHandling = NullValueHandling . Ignore , PropertyName = "members" ) ]
345373 public Dictionary < string , MemberInfoTS > Members { get ; set ; } = null ! ;
374+ [ JsonProperty ( DefaultValueHandling = DefaultValueHandling . Ignore , PropertyName = "hasConstructorOperation" ) ]
375+ public bool HasConstructorOperation { get ; set ; }
346376 [ JsonProperty ( NullValueHandling = NullValueHandling . Ignore , PropertyName = "operations" ) ]
347377 public Dictionary < string , OperationInfoTS > ? Operations { get ; set ; }
348378 [ JsonProperty ( DefaultValueHandling = DefaultValueHandling . Ignore , PropertyName = "requiresEntityPack" ) ]
0 commit comments