protected override void AppendDefaultValueInstructions(List <Instruction> instructions, TypeDefinition type, PropertyDefinition property, Range instructionRange)
 {
     instructions.AppendDefaultValueInstructionsForAttachedProperty(type, property, instructionRange);
 }
        private void ConvertToAttachedProperty(TypeDefinition type, PropertyDefinition property, Range instructionRange, int startIndex)
        {
            string          fieldName = property.Name + "Property";
            FieldDefinition field     = new FieldDefinition(fieldName, FieldAttributes.Static | FieldAttributes.InitOnly | FieldAttributes.Public, DependencyPropertyType);

            type.Fields.Add(field);

            AddInitializationToStaticConstructor(type, property, field, instructionRange, startIndex);

            CreateGetMethod(type, property, field);
            CreateSetMethod(type, property, field);

            FieldDefinition backingField = type.GetBackingFieldForProperty(property);

            type.Methods.Remove(property.GetMethod);
            type.Methods.Remove(property.SetMethod);
            type.Properties.Remove(property);
            type.Fields.Remove(backingField);
        }
        private void AddInitializationToStaticConstructor(TypeDefinition type, PropertyDefinition property, FieldDefinition field, Range instructionRange, int startIndex)
        {
            MethodDefinition staticConstructor = type.GetStaticConstructor();

            List <Instruction> instructions = CreateInstructionsUpToRegistration(type, property, instructionRange, property.GetAttachedPropertyAttribute());

            instructions.Add(Instruction.Create(OpCodes.Call, _registerAttachedProperty));
            instructions.Add(Instruction.Create(OpCodes.Stsfld, field));

            instructions.Reverse();

            foreach (Instruction instruction in instructions)
            {
                staticConstructor.Body.Instructions.Insert(startIndex, instruction);
            }
        }