LongAttribute

Namespace: Google.AdWords
We found 10 examples in language CSharp for this search. You will see 32 fragments of code.
        
        [Test()]
        public void LongComparisonNoMatch ()
        {
            var longAttribute = new SimpleDbAttributeValue ("4294967296", "4294967297").Every();
            Assert.IsFalse (longAttribute == 4294967296L);
            Assert.IsFalse (longAttribute == 4294967297L);
            Assert.IsFalse (longAttribute < 4294967297L);
            Assert.IsFalse (longAttribute > 4294967296L);
            Assert.IsFalse (longAttribute == 4294967298L);
        }

        [Test()]
        public void LongComparisonYesMatch ()
        {
            var longAttribute = new SimpleDbAttributeValue ("4294967296", "4294967297").Every();
            Assert.IsTrue (longAttribute <= 4294967297L);
            Assert.IsTrue (longAttribute >= 4294967296L);
        }

        [Test()]
        public void StringComparison ()
        {
            var stringAttribute = new SimpleDbAttributeValue ("hello", "world");
            Assert.IsTrue (stringAttribute == "hello");
            Assert.IsTrue (stringAttribute == "world");
            Assert.IsFalse (stringAttribute == "foo");
        }
        
        [Test()]
        public void IntComparison ()
        {
            var intAttribute = new SimpleDbAttributeValue ("1", "2");
            Assert.IsTrue (intAttribute == 1);
            Assert.IsTrue (intAttribute == 2);
            Assert.IsTrue (intAttribute < 2);
            Assert.IsTrue (intAttribute > 1);
            Assert.IsFalse (intAttribute == 3);
        }
        
        [Test()]
        public void LongComparison ()
        {
            var longAttribute = new SimpleDbAttributeValue ("4294967296", "4294967297");
            Assert.IsTrue (longAttribute == 4294967296L);
            Assert.IsTrue (longAttribute == 4294967297L);
            Assert.IsTrue (longAttribute < 4294967297L);
            Assert.IsTrue (longAttribute > 4294967296L);
            Assert.IsFalse (longAttribute == 4294967298L);
        }

        [Test()]
        public void FloatComparison ()
        {
            var floatAttribute = new SimpleDbAttributeValue ("3.5", "4.5");
            Assert.IsTrue (floatAttribute == 3.5F);
            Assert.IsTrue (floatAttribute == 4.5F);
            Assert.IsTrue (floatAttribute < 4.5F);
            Assert.IsTrue (floatAttribute > 3.5F);
            Assert.IsFalse (floatAttribute == 5.5F);
        }
        
        [Test()]
        public void DoubleComparison ()
        {
            var doubleAttribute = new SimpleDbAttributeValue ("4294967296.5", "4294967297.5");
            Assert.IsTrue (doubleAttribute == 4294967296.5D);
            Assert.IsTrue (doubleAttribute == 4294967297.5D);
            Assert.IsTrue (doubleAttribute < 4294967297.5D);
            Assert.IsTrue (doubleAttribute > 4294967296.5D);
            Assert.IsFalse (doubleAttribute == 4294967298.5D);
        }

        [Test()]
        public void DecimalComparison ()
        {
            var decimalAttribute = new SimpleDbAttributeValue ("300.5", "301.5");
            Assert.IsTrue (decimalAttribute == 300.5m);
            Assert.IsTrue (decimalAttribute == 301.5m);
            Assert.IsTrue (decimalAttribute < 301.5m);
            Assert.IsTrue (decimalAttribute > 300.5m);
            Assert.IsFalse (decimalAttribute == 302.5m);
        }

        public static bool Validate(this object oObject)
        {
            Type type = oObject.GetType();
            foreach (var prop in type.GetProperties())
            {
                if (prop.IsDefined(typeof(LongAttribute),true))
                {
                    LongAttribute attribute = (LongAttribute) prop.GetCustomAttribute(typeof(LongAttribute), true);

                    if (!attribute.Validate(prop.GetValue(oObject)))
                    {
                        return false;
                    }
                }
            }

            return true;
        }

        public bool Validate(object value)
        {
            if (value!=null&&!string.IsNullOrWhiteSpace(value.ToString()))
            {
                if (long.TryParse(value.ToString(),out long lResult))
                {
                    if (lResult>_Min&&lResult<_Max)
                    {
                        return true;
                    }
                }
            }

            return false;
        }

        public override bool Validate(object obj)
        {
            return obj != null && long.TryParse(obj.ToString(), out long lvalue) && lvalue > _min && lvalue < _max;
        }



        public override bool Validate(object value)//" "
        {
            if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
            {
                int length = value.ToString().Length;
                if (length > this._Min && length < this._Max)
                {
                    return true;
                }
            }
            return false;
        }


        public override bool Validate(object value)//" "
        {
            //可以改成一句话
            if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
            {
                if (long.TryParse(value.ToString(), out long lResult))
                {
                    if (lResult > this._Min && lResult < this._Max)
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        public override bool Validate(object oValue)
        {
            return oValue != null;
        }
        public override bool Validate(object oValue)
        {
            return oValue != null
                && Regex.IsMatch(oValue.ToString(), @"^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$");
        }
        public override bool Validate(object oValue)
        {
            if (oValue == null)
            {
                return false;
            }
            else
            {
                return Regex.IsMatch(oValue.ToString(), @"^[1]+[3,5]+\d{9}");
            }
        }

        public override bool Validate(object oValue)
        {
            if (oValue == null)
            {
                return false;
            }
            else
            {
                return Regex.IsMatch(oValue.ToString(), _RegexExpression);
            }
        }


        public override bool IsValid(object value)
        {
            if (value == null) throw new ParamsException(base.ErrorMessage);
            try
            {
                long @long = Convert.ToInt64(value);
                if (this.U && this.Zero && @long <= 0)
                {
                    throw new ParamsException(base.ErrorMessage);
                }
                else if (this.U && !this.Zero && @long < 0)
                {
                    throw new ParamsException(base.ErrorMessage);
                }
                else
                {
                    return true;
                }
            }
            catch (Exception)
            {
                throw new ParamsException(base.ErrorMessage);
            }
        }

        [TestMethod] // -----------------------------------------------------------------------
        public void TestMethod1()
        {
            TestObsolete.NewMethod();
            TestObsolete.OldMethod();
            // TestObsolete.ErrorMethod();
        }
        public static void NewMethod() { HLog.print("NewMethod"); }

        [System.Obsolete("OldMethod, pls use NewMethod instead of OldMethod!", false)]
        public static void OldMethod() { HLog.print("OldMethod"); }

        [System.Obsolete("ErrorMethod, you can't use ErrorMethod!", true)]
        public static void ErrorMethod() { HLog.print("ErrorMethod"); }
        public void Study() { HLog.print($"這裡是{this.Name}跟著老師學習"); }
        public string Answer(string name) { return $"This is {name}"; }


        /// <summary>
        /// Adds commands to the repository by finding exposed methods in the given
        /// <paramref name="assembly"/>.
        /// </summary>
        internal void AddFromExposedMethods(Assembly assembly)
        {
            // Get all types of the assembly
            var types = assembly.GetTypes();
            foreach (var type in types)
            {
                // Get the methods in the type
                var methods = type.GetMethods();
                foreach (var method in methods)
                {
                    // Check if the methods has a Command attribute
                    var attribute = method.GetCustomAttribute<Attributes.CommandAttribute>();
                    
                    if (attribute == null)
                    {
                        continue;
                    }

                    // If the identifier was not set manually, use the lowercase method's name
                    var id = attribute.Identifier ?? method.Name.ToLower();

                    // Throw if a command with the same id already exists
                    if (commands.Any(c => c.Identifier == id))
                    {
                        throw new Exception($"Duplicate command id: {id}");
                    }

                    var parameters = method.GetParameters();
                    var stateful = parameters.Length > 0 && parameters[0].Name == "state";

                    if (stateful)
                    {
                        parameters = parameters.Skip(1).ToArray();
                    }

                    // Build and add the command
                    var command = new Command(id, method, parameters.Select(p => BuildParameter(p)).ToArray(),
                        attribute.Description, attribute.Examples)
                    {
                        Stateful = stateful
                    };

                    commands.Add(command);
                }
            }
        }

        private static Parameter BuildParameter(ParameterInfo info)
        {
            var dict = new Dictionary<Type, Func<Parameter>>
            {
                { typeof(string), () => BuildFromString(info) },
                { typeof(bool), () => BuildFromBool(info) },
                { typeof(DateTime), () => BuildFromDateTime(info) },
                { typeof(int), () => BuildFromInt(info) },
                { typeof(long), () => BuildFromLong(info) },
                { typeof(string[]), () => BuildFromStringArray(info) },
            };

            // If it's one of the standard types
            if (dict.ContainsKey(info.ParameterType))
            {
                var param = dict[info.ParameterType].Invoke();
                param.Name = info.Name;
                return param;
            }

            // If it's an enum type
            if (info.ParameterType.IsEnum)
            {
                return BuildFromEnum(info);
            }

            throw new NotSupportedException($"Parameter {info.Name} has an unsupported type ({info.ParameterType})");
        }

        private static Parameter BuildFromString(ParameterInfo info)
        {
            // If it has the FileOrFolder attribute
            if (info.GetCustomAttribute<Attributes.FileOrFolderAttribute>() is not null)
            {
                var param = new FileOrFolderParameter();
                SetParameterInfo(info, param);

                if (info.HasDefaultValue)
                {
                    param.Default = (string)info.DefaultValue;
                }

                return param;
            }
            // Otherwise it's a normal string parameter
            else
            {
                var param = new StringParameter();
                SetParameterInfo(info, param);

                if (info.HasDefaultValue)
                {
                    param.Default = (string)info.DefaultValue;
                }

                var stringAttribute = info.GetCustomAttribute<Attributes.StringAttribute>();

                if (stringAttribute is not null)
                {
                    param.MinLength = stringAttribute.MinLength;
                    param.MaxLength = stringAttribute.MaxLength;
                    param.ForbiddenCharacters = stringAttribute.ForbiddenCharacters.ToCharArray();
                    param.AutoCompleteList = stringAttribute.AutoCompleteList;
                }

                return param;
            }
        }

        private static Parameter BuildFromBool(ParameterInfo info)
        {
            var param = new BoolParameter();
            SetParameterInfo(info, param);

            if (info.HasDefaultValue)
            {
                param.Default = (bool)info.DefaultValue;
            }

            return param;
        }

        private static Parameter BuildFromInt(ParameterInfo info)
        {
            var param = new IntParameter();
            SetParameterInfo(info, param);

            if (info.HasDefaultValue)
            {
                param.Default = (int)info.DefaultValue;
            }

            var intAttribute = info.GetCustomAttribute<Attributes.IntAttribute>();

            if (intAttribute is not null)
            {
                param.Min = intAttribute.Min;
                param.Max = intAttribute.Max;
            }

            return param;
        }

        private static Parameter BuildFromLong(ParameterInfo info)
        {
            var param = new LongParameter();
            SetParameterInfo(info, param);

            if (info.HasDefaultValue)
            {
                param.Default = (long)info.DefaultValue;
            }

            var longAttribute = info.GetCustomAttribute<Attributes.LongAttribute>();

            if (longAttribute is not null)
            {
                param.Min = longAttribute.Min;
                param.Max = longAttribute.Max;
            }

            return param;
        }


        public override bool Validate(object oValue)
        {
            if (oValue != null && oValue.ToString().Length >= _Min && oValue.ToString().Length <= _Max)
            {
                return true;
            }
            return false;
        }

using System;

namespace InteractiveCommandLine.Attributes
{
    /// <summary>
    /// Attribute used to decorate an long parameter.
    /// </summary>
    [AttributeUsage(AttributeTargets.Parameter)]
    public class LongAttribute : Attribute
    {
        /// <summary>
        /// The minimum accepted value.
        /// </summary>
        public long Min { get; set; } = 0;

        /// <summary>
        /// The maximum accepted value.
        /// </summary>
        public long Max { get; set; } = long.MaxValue;

        /// <summary>
        /// Configures an long parameter.
        /// </summary>
        /// <param name="min">The minimum accepted value.</param>
        /// <param name="max">The maximum accepted value.</param>
        public LongAttribute(long min = 0, long max = long.MaxValue)
        {
            Min = min;
            Max = max;
        }
    }
}

Google.Api.Ads.AdWords.v201809.LongAttribute : Attribute

Constructors :

public LongAttribute()

Methods :

public Int64 get_value()
public Void set_value(Int64 value = )
public Boolean get_valueSpecified()
public Void set_valueSpecified(Boolean value = )
public String get_AttributeType()
public Void set_AttributeType(String value = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()