Пример #1
0
    public static Expression Like(CaseMode caseMode, Expression lhs, Expression pattern)
    {
        Expression x = null;

        if (caseMode == CaseMode.Sensitive)
        {
            x = Expression.Call(ApplyLikeMethodInfo, lhs, pattern);
        }
        else
        {
            x = Expression.Call(ApplyLikeNoCaseMethodInfo, lhs, pattern);
        }

        return(x);
    }
Пример #2
0
        /// <summary>
        /// autocase the keyword according to the mode given
        /// </summary>
        public static string ConvertCase(this string keyword, CaseMode mode, string naturalCase = null)
        {
            switch (mode)
            {
            case CaseMode.UpperCase:
                return(keyword.ToUpper());

            case CaseMode.LowerCase:
                return(keyword.ToLower());

            case CaseMode.Camel:
                return(keyword.ToTitleCase());

            default:
                return(naturalCase ?? keyword);
            }
        }
Пример #3
0
 public TransformApplierParams(TextFeaturizingEstimator parent)
 {
     var host = parent._host;
     host.Check(Enum.IsDefined(typeof(Language), parent.OptionalSettings.Language));
     host.Check(Enum.IsDefined(typeof(CaseMode), parent.OptionalSettings.CaseMode));
     WordExtractorFactory = parent._wordFeatureExtractor?.CreateComponent(host, parent._dictionary);
     CharExtractorFactory = parent._charFeatureExtractor?.CreateComponent(host, parent._dictionary);
     Norm = parent.OptionalSettings.Norm;
     Language = parent.OptionalSettings.Language;
     UsePredefinedStopWordRemover = parent.OptionalSettings.UsePredefinedStopWordRemover;
     TextCase = parent.OptionalSettings.CaseMode;
     KeepDiacritics = parent.OptionalSettings.KeepDiacritics;
     KeepPunctuations = parent.OptionalSettings.KeepPunctuations;
     KeepNumbers = parent.OptionalSettings.KeepNumbers;
     OutputTextTokens = parent.OptionalSettings.OutputTokens;
     Dictionary = parent._dictionary;
 }
Пример #4
0
 public static string Format(string name, string casing, string allowChars, CaseMode mode)
 {
     casing.AssertIsNotNullOrEmpty(nameof(casing));
     if (mode == CaseMode.AspDotNetCompatible)
     {
         return(name?.ToAspDotNetCompatibleFirstLowerCase());
     }
     if (casing.Equals(Case.CamelCase, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.ToCamelCase(allowChars));
     }
     if (casing.Equals(Case.PascalCase, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.ToPascalCase(allowChars));
     }
     if (casing.Equals(Case.KebabCase, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.ToKebabCase(allowChars));
     }
     if (casing.Equals(Case.SnakeCase, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.ToSnakeCase(allowChars));
     }
     if (casing.Equals(Case.DarwinCase, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.ToDarwinCase(allowChars));
     }
     if (casing.Equals(Case.FirstCharToLower, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.FirstCharToLower());
     }
     if (casing.Equals(Case.FirstCharToUpper, StringComparison.CurrentCultureIgnoreCase))
     {
         return(name?.FirstCharToUpper());
     }
     throw new ArgumentOutOfRangeException(nameof(casing));
 }
Пример #5
0
        /// <summary>
        /// Populates the object with properties by searching a .NET type for fields.
        /// Should be called only once at startup.
        /// </summary>
        /// <param name="type"> The type to search for fields. </param>
        internal protected void PopulateFields(Type type, int staticMode)
        {
            if (type == null)
            {
                type = this.GetType();
            }

            // Get the js properties for the type:
            JSProperties typeAttribute = (JSProperties)Attribute.GetCustomAttribute(type, typeof(JSProperties));

            CaseMode typeCaseMode = CaseMode.Auto;

            if (typeAttribute != null)
            {
                typeCaseMode = typeAttribute.FirstFieldCharacter;
            }

            // Find all fields with [JsField]
            foreach (var field in type.GetFields())
            {
                var attribute = (JSProperties)Attribute.GetCustomAttribute(field, typeof(JSProperties));
                if (attribute != null && attribute.Hidden)
                {
                    continue;
                }

                CaseMode caseMode = CaseMode.Auto;

                if (attribute != null)
                {
                    // Got settings; apply case mode:
                    caseMode = attribute.FirstCharacter;
                }

                if (caseMode == CaseMode.Auto)
                {
                    caseMode = typeCaseMode;
                }

                string name;
                if (attribute != null && attribute.Name != null)
                {
                    name = attribute.Name;
                }
                else
                {
                    name = field.Name;
                }

                if (field.IsStatic)
                {
                    // If it's static then it's a constructor level function (if there is a constructor).

                    if (staticMode == 1)
                    {
                        // We only want non-static ones.
                        continue;
                    }
                }
                else if (staticMode == 2)
                {
                    // We only want static ones.
                    continue;
                }

                // auto == lowercase
                if (caseMode == CaseMode.Upper)
                {
                    name = char.ToUpper(name[0]) + name.Substring(1);
                }
                else if (caseMode == CaseMode.Lower || caseMode == CaseMode.Auto)
                {
                    name = char.ToLower(name[0]) + name.Substring(1);
                }

                if (field.IsLiteral && !field.IsInitOnly)
                {
                    AddProperty(name, field.GetValue(null), PropertyAttributes.FullAccess);
                }
                else
                {
                    AddProperty(name, field, PropertyAttributes.FullAccess);
                }
            }
        }
Пример #6
0
 public static string Format(string name, string casing, IOptions options, bool force = false, CaseMode mode = CaseMode.Fix)
 {
     if (options.FormatNames || force)
     {
         return(Format(name, casing, options.Formatting.AllowedSpecialCharacters, mode));
     }
     return(name);
 }
Пример #7
0
 public IFormattingFluentSyntax CaseMode(CaseMode mode)
 {
     this.options.CaseMode = mode;
     return(this);
 }