Example #1
0
 void model_DynamicTypeFormatting(object sender, TypeFormatEventArgs args)
 {
     if(args.Type == typeof(SqlCommand))
     {
         args.FormattedName = "abc";
     } else if (args.FormattedName == "abc")
     {
         args.Type = typeof (SqlCommand);
     }
 }
 static public int get_Type(IntPtr l)
 {
     try {
         ProtoBuf.Meta.TypeFormatEventArgs self = (ProtoBuf.Meta.TypeFormatEventArgs)checkSelf(l);
         pushValue(l, true);
         pushValue(l, self.Type);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static public int set_FormattedName(IntPtr l)
 {
     try {
         ProtoBuf.Meta.TypeFormatEventArgs self = (ProtoBuf.Meta.TypeFormatEventArgs)checkSelf(l);
         string v;
         checkType(l, 2, out v);
         self.FormattedName = v;
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Example #4
0
 internal static Type DeserializeType(TypeModel model, string value)
 {
     if (model != null)
     {
         TypeFormatEventHandler dynamicTypeFormatting = model.DynamicTypeFormatting;
         if (dynamicTypeFormatting != null)
         {
             TypeFormatEventArgs typeFormatEventArgs = new TypeFormatEventArgs(value);
             dynamicTypeFormatting(model, typeFormatEventArgs);
             if (typeFormatEventArgs.Type != null)
             {
                 return(typeFormatEventArgs.Type);
             }
         }
     }
     return(Type.GetType(value));
 }
Example #5
0
 internal static string SerializeType(TypeModel model, Type type)
 {
     if (model != null)
     {
         TypeFormatEventHandler dynamicTypeFormatting = model.DynamicTypeFormatting;
         if (dynamicTypeFormatting != null)
         {
             TypeFormatEventArgs typeFormatEventArgs = new TypeFormatEventArgs(type);
             dynamicTypeFormatting(model, typeFormatEventArgs);
             if (!Helpers.IsNullOrEmpty(typeFormatEventArgs.FormattedName))
             {
                 return(typeFormatEventArgs.FormattedName);
             }
         }
     }
     return(type.AssemblyQualifiedName);
 }
Example #6
0
        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);
                }
            }
        }