Beispiel #1
0
 /// <summary>
 /// disparador del evento que ocurre cuando se añade un tipo
 /// </summary>
 protected virtual void OnTypeAdded(string typeName, TigerType type)
 {
     if (TypeAdded != null)
     {
         var args = new TypeAddedEventArgs(typeName, type);
         TypeAdded(this, args);
     }
 }
Beispiel #2
0
        private static void OnAfterApplyDefaultBehaviour(object sender, TypeAddedEventArgs args)
        {
            if (GrpcServiceClient.IsRequestDto(args.Type))
            {
                // query DTO; we'll flatten the query *into* this type, shifting everything
                // by some reserved number per level, starting at the most base level

                // walk backwards up the tree; at each level, offset everything by 100
                // and copy over from the default model
                var  log     = LogManager.GetLogger(typeof(MetaTypeConfig <>).MakeGenericType(args.Type));
                Type current = args.Type.BaseType;
                var  mt      = args.MetaType;
                while (current != null && current != typeof(object))
                {
                    try
                    {
                        mt.ApplyFieldOffset(100);
                    }
                    catch (Exception e)
                    {
                        log.Error($"Error in CreateMetaType() for '{current.Name}' when 'ApplyFieldOffset(100)': {e.Message}", e);
                        throw;
                    }
                    var source = RuntimeTypeModel.Default[current]?.GetFields();
                    foreach (var field in source)
                    {
                        try
                        {
                            AddField(mt, field);
                        }
                        catch (Exception e)
                        {
                            log.Error($"Error in CreateMetaType() for '{current.Name}' when adding field '{field.Name}': {e.Message}", e);
                            throw;
                        }
                    }

                    // keep going down the hierarchy
                    current = current.BaseType;
                }
            }