Example #1
0
            public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
            {
                if (typeDeclaration.HasModifier(Modifiers.Shared))
                {
                    return;
                }
                var list = new List <Tuple <VariableInitializer, IVariable> >();

                fieldStack.Push(list);

                foreach (var fieldDeclaration in ConvertToConstantIssue.CollectFields(this, typeDeclaration))
                {
                    if (fieldDeclaration.HasModifier(Modifiers.Const))
                    {
                        continue;
                    }
                    if (fieldDeclaration.HasModifier(Modifiers.Public) || fieldDeclaration.HasModifier(Modifiers.Protected) || fieldDeclaration.HasModifier(Modifiers.Internal))
                    {
                        continue;
                    }
                    if (fieldDeclaration.Variables.Count() > 1)
                    {
                        continue;
                    }
                    var variable = fieldDeclaration.Variables.First();
                    if (!variable.Initializer.IsNull)
                    {
                        continue;
                    }
                    var rr = ctx.Resolve(fieldDeclaration.ReturnType);
                    if (rr.Type.IsReferenceType == false)
                    {
                        // Value type:
                        var def = rr.Type.GetDefinition();
                        if (def != null && def.KnownTypeCode == KnownTypeCode.None)
                        {
                            // user-defined value type -- might be mutable
                            continue;
                        }
                        else if (ctx.Resolve(variable.Initializer).IsCompileTimeConstant)
                        {
                            // handled by ConvertToConstantIssue
                            continue;
                        }
                    }

                    var mr = ctx.Resolve(variable) as MemberResolveResult;
                    if (mr == null || !(mr.Member is IVariable))
                    {
                        continue;
                    }
                    list.Add(Tuple.Create(variable, (IVariable)mr.Member));
                }
                base.VisitTypeDeclaration(typeDeclaration);
                Collect();
                fieldStack.Pop();
            }
Example #2
0
            public override void VisitTypeDeclaration(TypeDeclaration typeDeclaration)
            {
                if (typeDeclaration.HasModifier(Modifiers.Shared))
                {
                    return;
                }
                var list = new List <Tuple <VariableInitializer, IVariable> >();

                fieldStack.Push(list);
                foreach (var fieldDeclaration in ConvertToConstantIssue.CollectFields(this, typeDeclaration))
                {
                    if (!fieldDeclaration.HasModifier(Modifiers.Readonly))
                    {
                        continue;
                    }
//					var rr = ctx.Resolve(fieldDeclaration.ReturnType);

                    if (fieldDeclaration.Variables.Count() > 1)
                    {
                        continue;
                    }
                    if (!fieldDeclaration.Variables.First().Initializer.IsNull)
                    {
                        continue;
                    }
                    var variable = fieldDeclaration.Variables.First();
                    var mr       = ctx.Resolve(variable) as MemberResolveResult;
                    if (mr == null)
                    {
                        continue;
                    }
                    list.Add(Tuple.Create(variable, mr.Member as IVariable));
                }
                base.VisitTypeDeclaration(typeDeclaration);
                Collect();
                fieldStack.Pop();
            }