Exemple #1
0
            /// <summary>
            /// Inject initialization code to the given ctor
            /// </summary>
            private static void InjectInitializationCode(MethodDefinition ctor, IEnumerable <FieldDefinition> structFields)
            {
                // Create sequence
                var initSeq = StructFields.CreateInitializationCode(structFields, true);

                // Find location where to insert
                var body = ctor.Body;

                // Insert at start of method
                initSeq.InsertTo(0, body);
            }
Exemple #2
0
            /// <summary>
            /// Inject initialization code to the given ctor
            /// </summary>
            private static void InjectInitializationCode(MethodDefinition ctor, IEnumerable <FieldDefinition> structFields)
            {
                // Create sequence
                var initSeq = StructFields.CreateInitializationCode(structFields, false);

                // Find location where to insert
                var body         = ctor.Body;
                var baseCtorCall = body.Instructions.FirstOrDefault(x => IsBaseOrThisCtorCall(ctor, x));

                if (baseCtorCall != null)
                {
                    // Insert after call to base/this ctor
                    initSeq.InsertToAfter(baseCtorCall, body);
                }
                else
                {
                    // Insert at start of method
                    initSeq.InsertTo(0, body);
                }
            }