Exemple #1
0
        internal static ValidationError ValidateNameProperty(string propName, IServiceProvider context, string identifier)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ValidationError error = null;

            if (identifier == null || identifier.Length == 0)
            {
                error = new ValidationError(SR.GetString(SR.Error_PropertyNotSet, propName), ErrorNumbers.Error_PropertyNotSet);
            }
            else
            {
                SupportedLanguages language = CompilerHelpers.GetSupportedLanguage(context);
                CodeDomProvider    provider = CompilerHelpers.GetCodeDomProvider(language);

                if (language == SupportedLanguages.CSharp && identifier.StartsWith("@", StringComparison.Ordinal) ||
                    language == SupportedLanguages.VB && identifier.StartsWith("[", StringComparison.Ordinal) && identifier.EndsWith("]", StringComparison.Ordinal) ||
                    !provider.IsValidIdentifier(provider.CreateEscapedIdentifier(identifier)))
                {
                    error = new ValidationError(SR.GetString(SR.Error_InvalidIdentifier, propName, SR.GetString(SR.Error_InvalidLanguageIdentifier, identifier)), ErrorNumbers.Error_InvalidIdentifier);
                }
            }
            if (error != null)
            {
                error.PropertyName = propName;
            }
            return(error);
        }
Exemple #2
0
        internal static void ValidateIdentifier(IServiceProvider serviceProvider, string identifier)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            SupportedLanguages language = CompilerHelpers.GetSupportedLanguage(serviceProvider);
            CodeDomProvider    provider = CompilerHelpers.GetCodeDomProvider(language);

            if (language == SupportedLanguages.CSharp && identifier.StartsWith("@", StringComparison.Ordinal) ||
                language == SupportedLanguages.VB && identifier.StartsWith("[", StringComparison.Ordinal) && identifier.EndsWith("]", StringComparison.Ordinal) ||
                !provider.IsValidIdentifier(identifier))
            {
                throw new Exception(SR.GetString(SR.Error_InvalidLanguageIdentifier, identifier));
            }
        }
Exemple #3
0
 internal static CodeDomProvider GetCodeDomProvider(SupportedLanguages language)
 {
     return(CompilerHelpers.GetCodeDomProvider(language, string.Empty));
 }