public static IEnumerable<Instruction> BuildBoundariesCheckInstructions(object parameterDefinitionOrFieldDefinition, CustomAttribute attribute) { foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition)) { yield return instruction; } foreach (var argument in attribute.ConstructorArguments) { object value = argument.Value; if (value is string) { yield return Instruction.Create(OpCodes.Ldstr, (string)value); } else if (value is int) { yield return Instruction.Create(OpCodes.Ldc_I4, (int)value); } else if (value is long) { foreach (var instruction in BuildLongInstructions(value)) { yield return instruction; } } else if (value is float) { yield return Instruction.Create(OpCodes.Ldc_R4, (float)value); } else if (value is double) { yield return Instruction.Create(OpCodes.Ldc_R8, (double)value); } } }
protected sealed override void BuildInstructions(ModuleDefinition module, TypeDefinition type, MethodDefinition method, FieldDefinition field, CustomAttribute attribute, List <Instruction> instructions) { instructions.AddRange(ArgumentInstructionSequenceBuilder.BuildBoundariesCheckInstructions(field, attribute)); }