Ejemplo n.º 1
0
        private static ExpressionSyntax GenerateFieldReference <T>(ITypeSymbol type, T value, IEnumerable <KeyValuePair <T, string> > constants)
        {
            foreach (var constant in constants)
            {
                if (constant.Key.Equals(value))
                {
                    var memberAccess = GenerateMemberAccess("System", typeof(T).Name);
                    if (type != null && !(type is IErrorTypeSymbol))
                    {
                        memberAccess = memberAccess.WithAdditionalAnnotations(SpecialTypeAnnotation.Create(type.SpecialType));
                    }

                    var result = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, memberAccess, SyntaxFactory.IdentifierName(constant.Value));
                    return(result.WithAdditionalAnnotations(Simplifier.Annotation));
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static ExpressionSyntax GenerateFieldReference(ITypeSymbol type, object value, IEnumerable <FieldInfo> constants)
        {
            foreach (var constant in constants)
            {
                if (constant.GetValue(null).Equals(value))
                {
                    var memberAccess = GenerateMemberAccess("System", constant.DeclaringType.Name);
                    if (type != null && !(type is IErrorTypeSymbol))
                    {
                        memberAccess = memberAccess.WithAdditionalAnnotations(SpecialTypeAnnotation.Create(type.SpecialType));
                    }

                    var result = SyntaxFactory.MemberAccessExpression(SyntaxKind.SimpleMemberAccessExpression, memberAccess, SyntaxFactory.IdentifierName(constant.Name));
                    return(result.WithAdditionalAnnotations(Simplifier.Annotation));
                }
            }

            return(null);
        }