protected void WeaveTypeInterface(TypeDefinition type) { var destinationEvent = type.GetEvent("PropertyChanged"); type = destinationEvent.DeclaringType; //can be base type var weaver = new TypeWeaver(originType, type); weaver.ProcessNestedTypes(); //TODO delete event generated field weaver.Merge(tNotifierEvent, destinationEvent); weaver.AddDefinition(tNotifierMethod); weaver.AddDefinition(tNotifierField); weaver.ProcessInstructions(); }
protected void WeaveTypeProperties(TypeDefinition type) { var properties = type.Properties.Where( p => p.CustomAttributes.Any( a => a.AttributeType.FullName == typeof (PropertyAttribute).FullName)); if(!properties.Any()) return; if(!type.HasInterface(typeof(IPropertyNotifier).FullName)) throw new Exception(string.Format("Type {0} has properties but does not implement {1}", type.FullName, typeof(IPropertyNotifier).FullName)); Console.WriteLine(type.FullName); var weaver = new TypeWeaver(originType, type); foreach(var property in properties) { weaver.NamePrefix = "<$" + property.Name + "$>"; var desNotifierMethod = type.GetMethod(tNotifierMethod.Name); weaver.Map(tNotifierMethod, desNotifierMethod); var propField = weaver.AddDefinition(tPropertyField); propField.FieldType = property.PropertyType; weaver.AddConstant(tPropertyNameC,property.Name); //TODO delete property generated field weaver.Merge(tPropertyProperty, property); weaver.ProcessInstructions(); } }