void model_DynamicTypeFormatting(object sender, TypeFormatEventArgs args)
        {
            if (args.Type != null)
            {
                if (args.Type == typeof(Derived))
                {
                    args.FormattedName = "Derived"; return;
                }
                if (args.Type == typeof(Base))
                {
                    args.FormattedName = "Base"; return;
                }
                throw new NotSupportedException(args.Type.Name);
            }
            else
            {
                switch (args.FormattedName)
                {
                case "Derived": args.Type = typeof(Derived); break;

                case "Base": args.Type = typeof(Base); break;

                default: throw new NotSupportedException(args.FormattedName);
                }
            }
        }
 void model_DynamicTypeFormatting(object sender, TypeFormatEventArgs args)
 {
     if (args.Type == typeof(SqlCommand))
     {
         args.FormattedName = "abc";
     }
     else if (args.FormattedName == "abc")
     {
         args.Type = typeof(SqlCommand);
     }
 }
Beispiel #3
0
 internal static Type DeserializeType(TypeModel model, string value)
 {
     if (model != null)
     {
         TypeFormatEventHandler handler = model.DynamicTypeFormatting;
         if (handler != null)
         {
             TypeFormatEventArgs args = new TypeFormatEventArgs(value);
             handler(model, args);
             if (args.Type != null)
             {
                 return(args.Type);
             }
         }
     }
     return(Type.GetType(value));
 }
Beispiel #4
0
 internal static string SerializeType(TypeModel model, Type type)
 {
     if (model != null)
     {
         TypeFormatEventHandler handler = model.DynamicTypeFormatting;
         if (handler != null)
         {
             TypeFormatEventArgs args = new TypeFormatEventArgs(type);
             handler(model, args);
             if (!Helpers.IsNullOrEmpty(args.FormattedName))
             {
                 return(args.FormattedName);
             }
         }
     }
     return(type.AssemblyQualifiedName);
 }
 void model_DynamicTypeFormatting(object sender, TypeFormatEventArgs args)
 {
     if (args.Type != null)
     {
         if (args.Type == typeof(Derived))
         {
             args.FormattedName = "Derived"; return;
         }
         if (args.Type == typeof(Base))
         {
             args.FormattedName = "Base"; return;
         }
         throw new NotSupportedException(args.Type.Name);
     }
     else
     {
         args.Type = args.FormattedName switch
         {
             "Derived" => typeof(Derived),
             "Base" => typeof(Base),
             _ => throw new NotSupportedException(args.FormattedName),
         };
     }
 }