c# - Override IsUnicode using Generic Extension -


i'm trying make generic extension method on entitytypeconfiguration<t> allow me enumerate string properties on t , set isunicode(false) them. here have far, i'm stuck @ trying obtain stringpropertyconfiguration, constructor class internal, , don't know obtain instance of it.

public static void setstringstobenonunicode<t>(this entitytypeconfiguration<t> config) t : class {      propertyinfo[] properties = typeof (t).getproperties();     foreach (propertyinfo p in properties)     {         var parameter = expression.parameter(typeof(t));         var property = expression.property(parameter, p);         var functype = typeof(func<,>).makegenerictype(typeof(t), p.propertytype);         var lambda = expression.lambda(functype, property, parameter);         //this line need         stringpropertyconfiguration stringconfig =              new system.data.entity.modelconfiguration.configuration.stringpropertyconfiguration(config.property<system.data.entity.modelconfiguration.configuration.properties.primitive.stringpropertyconfiguration>((lambdaexpression) property));                             stringconfig.isunicode(false);      } } 

i know it's late if others need it:

((stringpropertyconfiguration)config.gettype().getmethod("property", new type[] { lambda.gettype() }).invoke((object)config, new object[] { lambda })).isunicode(false); 

Comments