コード例 #1
0
ファイル: TreeDtoExtension.cs プロジェクト: NetUtil/Util
 public static TreeDto ToDto( this TreeEntity entity ) {
     entity.CheckNull( "entity" );
     return new TreeDto() {
         Id = entity.Id.ToString(),
         ParentId = entity.ParentId,
         Level = entity.Level,
         Path = entity.Path,
         SortId = entity.SortId,
         Version = entity.Version
     };
 }
コード例 #2
0
ファイル: Extensions.cs プロジェクト: devigned/autorest
        /// <summary>
        /// Return list of validations for composite type.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="name"></param>
        /// <param name="method"></param>
        /// <param name="ancestors"></param>
        /// <param name="isCompositeProperties"></param>
        /// <returns></returns>
        public static List<string> ValidateCompositeType(this IParameter p, string name, HttpMethod method, HashSet<string> ancestors,
            bool isCompositeProperties = false)
        {
            List<string> x = new List<string>();
            if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties)
            {
                foreach (var prop in ((CompositeType)p.Type).Properties)
                {
                    var primary = prop.Type as PrimaryType;
                    var sequence = prop.Type as SequenceType;
                    var map = prop.Type as MapType;
                    var composite = prop.Type as CompositeType;

                    if (primary != null || sequence != null || map != null)
                        x.AddRange(prop.ValidateType($"{name}.{prop.Name}", method, true));
                    else if (composite != null)
                    {
                        if (ancestors.Contains(composite.Name))
                        {
                            x.AddNullValidation($"{name}.{prop.Name}", p.IsRequired);
                        }
                        else
                        {
                            ancestors.Add(composite.Name);
                            x.AddRange(prop.ValidateCompositeType($"{name}.{prop.Name}", method, ancestors, true));
                            ancestors.Remove(composite.Name);
                        }  
                    }   
                }
            }

            x.AddRange(from prop in ((CompositeType)p.Type).Properties
                       where prop.IsReadOnly
                       select GetConstraint($"{name}.{prop.Name}", ReadOnlyConstraint, "true"));

            List<string> y = new List<string>();
            if (x.Count > 0)
            {
                if (p.CheckNull() || isCompositeProperties)
                    y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired));
                else
                    y.AddRange(x);
            }
            else
            {
                if (p.IsRequired && (p.CheckNull() || isCompositeProperties))
                    y.AddNullValidation(name, p.IsRequired);
            }
            return y;
        }
コード例 #3
0
ファイル: Extensions.cs プロジェクト: devigned/autorest
        /// <summary>
        /// Return list of validations for primary, map, sequence and rest of the types.
        /// </summary>
        /// <param name="p"></param>
        /// <param name="name"></param>
        /// <param name="method"></param>
        /// <param name="isCompositeProperties"></param>
        /// <returns></returns>
        public static List<string> ValidateType(this IParameter p, string name, HttpMethod method,
            bool isCompositeProperties = false)
        {
            List<string> x = new List<string>();
            if (method != HttpMethod.Patch || !p.IsBodyParameter() || isCompositeProperties)
            {
                x.AddRange(p.Constraints.Select(c => GetConstraint(name, c.Key.ToString(), c.Value)).ToList());
            }

            List<string> y = new List<string>();
            if (x.Count > 0)
            {
                if (p.CheckNull() || isCompositeProperties)
                    y.AddRange(x.AddChain(name, NullConstraint, p.IsRequired));
                else
                    y.AddRange(x);
            }
            else
            {
                if (p.IsRequired && (p.CheckNull() || isCompositeProperties))
                    y.AddNullValidation(name, p.IsRequired);
            }
            return y;
        }
コード例 #4
0
 /// <summary>
 /// Throws an <see cref="ArgumentNullException"/> is the object is null.
 /// </summary>
 /// <param name="o">The object to check.</param>
 public static void CheckNull(this object o)
 {
     o.CheckNull(null);
 }
コード例 #5
0
 /// <summary>
 /// Checks for and throws an <see cref="ArgumentNullException"/> if the object is null.
 /// </summary>
 /// <param name="param">The <see cref="object"/>.</param>
 /// <exception cref="ArgumentNullException"><b>parm</b> was null.</exception>
 public static void CheckNull(this object param)
 {
     param.CheckNull(null);
 }