internal override void BuildConfiguration(ConfigurationBuildContext buildContext) { if ((null == this._baseToProxyConversionDelegate) && (null == this._proxyToBaseConversionDelegate)) { return; } var proxyProperty = new ProxyPropertyInfo { Attributes = this.Property.GetCustomAttributes().ToList(), PropertyName = this.Property.Name, BasePropertyInfo = this.Property, ConversionToProxyDelegate = this._baseToProxyConversionDelegate, ConversionFromProxyDelegate = this._proxyToBaseConversionDelegate, ExcludeFromProxy = false }; buildContext.ProxyProperties.Add(proxyProperty); }
public void TestProxyGenerator() { try { var moduleBuilder = ProxyModuleBuilder.GetInstance <XmlSerializerContextTests>(); var pg = ProxyTypeImplementer.GetInstance <PoLine>(moduleBuilder); var pi = new ProxyPropertyInfo { PropertyName = "Tax", BasePropertyInfo = typeof(PoLine).GetProperty("Tax"), ProxyPropertyType = typeof(string), ConversionToProxyDelegate = ((MethodCallExpression)((Expression <Func <decimal, string> >)(d => NullableDecimalToString(d))).Body).Method, ConversionFromProxyDelegate = ((MethodCallExpression)((Expression <Func <string, decimal?> >)(s => ParseToNullableDecimal(s))).Body).Method }; pg.AddPropertyInfo(pi); var t = pg.BuildProxyType(); var i = Activator.CreateInstance(t); var tp = t.GetProperty("Tax"); var ov = tp.GetValue(i); // tp.SetValue(i, new Nullable<decimal>(1107.0m)); tp.SetValue(i, "1107.0"); // var op0 = t.GetMethod("op_Explicit", new[] { t }); var op0 = t.GetMethod("op_Implicit", new[] { t }); // var x = op0.Invoke(null, new[] { i }); // var op1 = t.GetMethod("op_Explicit", new[] { typeof(PoLine) }); var op1 = t.GetMethod("op_Implicit", new[] { typeof(PoLine) }); var x = new PoLine { Tax = 33.0m }; var y = op1.Invoke(null, new[] { x }); var z = new PoLine[1]; var bi = (PoLine)i; } catch (Exception ex) { throw; } }