示例#1
0
            public static bool IsDeferringCtor(IMethodDefinition method, IBlockStatement body)
            {
                var fcc = new FindCtorCall(method.ContainingType);

                fcc.Traverse(body);
                return(fcc.isDeferringCtor);
            }
示例#2
0
        private static List <IStatement> InitializeFieldsInConstructor(IMethodDefinition method)
        {
            Contract.Ensures(Contract.Result <List <IStatement> >() != null);
            var inits = new List <IStatement>();

            if (method.IsConstructor || method.IsStaticConstructor)
            {
                var smb = method.Body as ISourceMethodBody;
                if (method.IsStaticConstructor || (smb != null && !FindCtorCall.IsDeferringCtor(method, smb.Block)))
                {
                    var thisExp = new ThisReference()
                    {
                        Type = method.ContainingTypeDefinition,
                    };
                    foreach (var f in method.ContainingTypeDefinition.Fields)
                    {
                        if (f.IsStatic == method.IsStatic)
                        {
                            var a = new Assignment()
                            {
                                Source = new DefaultValue()
                                {
                                    DefaultValueType = f.Type, Type = f.Type,
                                },
                                Target = new TargetExpression()
                                {
                                    Definition = f, Instance = method.IsConstructor ? thisExp : null, Type = f.Type
                                },
                                Type = f.Type,
                            };
                            inits.Add(new ExpressionStatement()
                            {
                                Expression = a,
                            });
                        }
                    }
                }
            }
            return(inits);
        }
 public static bool IsDeferringCtor(IMethodDefinition method, IBlockStatement body) {
   var fcc = new FindCtorCall(method.ContainingType);
   fcc.Traverse(body);
   return fcc.isDeferringCtor;
 }