Exemple #1
0
        public PropertyObjectBuilder(Hashtable ht)
        {
            this.ht = ht;
            AppDomain    myDomain  = Thread.GetDomain();
            AssemblyName myAsmName = new AssemblyName();

            myAsmName.Name = "MyDynamicAssembly";

            AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(myAsmName,
                                                                          AssemblyBuilderAccess.Run);

            ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule("MyModule");

            TypeBuilder myTypeBuilder = myModBuilder.DefineType("CustomerData",
                                                                TypeAttributes.Public);


            //Add all properties
            foreach (string k in ht.Keys)
            {
                AddProperty(k, myTypeBuilder);
            }

            //Creat type and an Instance
            custDataType = myTypeBuilder.CreateType();
            instance     = Activator.CreateInstance(custDataType);

            foreach (string k in ht.Keys)
            {
                BaseChangeShort val = new BaseChangeShort((short)ht[k]);
                custDataType.InvokeMember(k, BindingFlags.SetProperty,
                                          null, instance, new object[] { val });
            }
        }
Exemple #2
0
        public override object ConvertTo(ITypeDescriptorContext context,
                                         CultureInfo culture,
                                         object value,
                                         System.Type destinationType)
        {
            if (destinationType == typeof(System.String) &&
                value is BaseChangeShort)
            {
                BaseChangeShort so = (BaseChangeShort)value;

                return(so.ToString());
            }
            return(base.ConvertTo(context, culture, value, destinationType));
        }
Exemple #3
0
 public override object ConvertFrom(ITypeDescriptorContext context,
                                    CultureInfo culture, object value)
 {
     if (value is string)
     {
         try
         {
             string s = (string)value;
             return(BaseChangeShort.Convert(s));
         }
         catch
         {
             throw new ArgumentException(
                       "Can not convert '" + (string)value + "'. This is not a valid " + BaseChangeShort.BaseName + " Number!");
         }
     }
     return(base.ConvertFrom(context, culture, value));
 }