Пример #1
0
        //private bool AnySecurityAttributeAdded(IDifferences differences, IReference target, IEnumerable<ISecurityAttribute> attribues1, IEnumerable<ISecurityAttribute> attributes2)
        //{
        //    return AnyAttributeAdded(differences, target, attribues1.SelectMany(a => a.Attributes), attributes2.SelectMany(a => a.Attributes));
        //}

        private void CheckAttributeDifferences(IDifferences differences, IReference target, IEnumerable<ICustomAttribute> implAttributes, IEnumerable<ICustomAttribute> contractAttributes)
        {
            AttributesMapping<IEnumerable<ICustomAttribute>> attributeMapping = new AttributesMapping<IEnumerable<ICustomAttribute>>(_settings);
            attributeMapping.AddMapping(0, contractAttributes);
            attributeMapping.AddMapping(1, implAttributes);

            foreach (var group in attributeMapping.Attributes)
            {
                switch (group.Difference)
                {
                    case DifferenceType.Added:
                        {
                            ITypeReference type = group.Representative.Attributes.First().Type;
                            string attribName = type.FullName();

                            if (FilterAttribute(attribName))
                                break;

                            AttributeAdded(target, attribName);

                            differences.AddIncompatibleDifference("CannotAddAttribute",
                                "Attribute '{0}' exists on '{1}' in the implementation but not the contract.",
                                attribName, target.FullName());

                            break;
                        }
                    case DifferenceType.Changed:

                        //TODO: Add some more logic to check the two lists of attributes which have the same type.
                        break;

                    case DifferenceType.Removed:
                        {
                            ITypeReference type = group.Representative.Attributes.First().Type;
                            string attribName = type.FullName();

                            if (s_IgnorableAttributes.Contains(attribName))
                                break;

                            differences.AddIncompatibleDifference("CannotRemoveAttribute",
                                "Attribute '{0}' exists on '{1}' in the contract but not the implementation.",
                                attribName, target.FullName());

                            break;
                        }
                }
            }
        }
Пример #2
0
        //private bool AnySecurityAttributeAdded(IDifferences differences, IReference target, IEnumerable<ISecurityAttribute> attribues1, IEnumerable<ISecurityAttribute> attributes2)
        //{
        //    return AnyAttributeAdded(differences, target, attribues1.SelectMany(a => a.Attributes), attributes2.SelectMany(a => a.Attributes));
        //}

        private DifferenceType CheckAttributeDifferences(IDifferences differences, IReference target, IEnumerable <ICustomAttribute> implAttributes, IEnumerable <ICustomAttribute> contractAttributes)
        {
            DifferenceType difference = DifferenceType.Unchanged;
            AttributesMapping <IEnumerable <ICustomAttribute> > attributeMapping = new AttributesMapping <IEnumerable <ICustomAttribute> >(_settings);
            AttributeComparer attributeComparer = new AttributeComparer();

            attributeMapping.AddMapping(0, contractAttributes.OrderBy(a => a, attributeComparer));
            attributeMapping.AddMapping(1, implAttributes.OrderBy(a => a, attributeComparer));

            foreach (var group in attributeMapping.Attributes)
            {
                switch (group.Difference)
                {
                case DifferenceType.Added:
                {
                    ITypeReference type = group.Representative.Attributes.First().Type;

                    if (AttributeFilter.ShouldExclude(type.DocId()))
                    {
                        break;
                    }

                    // Allow for additions
                    differences.Add(new Difference("AddedAttribute",
                                                   $"Attribute '{type.FullName()}' exists on '{target.FullName()}' in the {Implementation} but not the {Contract}."));

                    break;
                }

                case DifferenceType.Changed:
                {
                    ITypeReference type = group.Representative.Attributes.First().Type;

                    if (AttributeFilter.ShouldExclude(type.DocId()))
                    {
                        break;
                    }

                    string contractKey       = attributeComparer.GetKey(group[0].Attributes.First());
                    string implementationKey = attributeComparer.GetKey(group[1].Attributes.First());

                    differences.AddIncompatibleDifference("CannotChangeAttribute",
                                                          $"Attribute '{type.FullName()}' on '{target.FullName()}' changed from '{contractKey}' in the {Contract} to '{implementationKey}' in the {Implementation}.");

                    difference = DifferenceType.Changed;
                    break;
                }

                case DifferenceType.Removed:
                {
                    ITypeReference type = group.Representative.Attributes.First().Type;

                    if (AttributeFilter.ShouldExclude(type.DocId()))
                    {
                        break;
                    }

                    differences.AddIncompatibleDifference("CannotRemoveAttribute",
                                                          $"Attribute '{type.FullName()}' exists on '{target.FullName()}' in the {Contract} but not the {Implementation}.");


                    // removals of an attribute are considered a "change" of the type
                    difference = DifferenceType.Changed;
                    break;
                }
                }
            }
            return(difference);
        }
Пример #3
0
        private bool CheckAttributeDifferences(IDifferences differences, IReference target, IEnumerable <ICustomAttribute> implAttributes, IEnumerable <ICustomAttribute> contractAttributes, IReference member = null)
        {
            AttributesMapping <IEnumerable <ICustomAttribute> > attributeMapping = new AttributesMapping <IEnumerable <ICustomAttribute> >(_settings);
            AttributeComparer attributeComparer = new AttributeComparer();

            attributeMapping.AddMapping(0, contractAttributes.OrderBy(a => a, attributeComparer));
            attributeMapping.AddMapping(1, implAttributes.OrderBy(a => a, attributeComparer));

            string errString = $"'{target.FullName()}'";

            if (target is IParameterDefinition || target is IGenericParameter)
            {
                errString  = target is IGenericParameter ? "generic param" : "parameter";
                errString += $" '{target.FullName()}' on member '{member?.FullName()}'";
            }

            bool changed = false;

            foreach (var group in attributeMapping.Attributes)
            {
                switch (group.Difference)
                {
                case DifferenceType.Added:
                {
                    ITypeReference type = group.Representative.Attributes.First().Type;

                    if (AttributeFilter.ShouldExclude(type.DocId()))
                    {
                        break;
                    }

                    // Allow for additions
                    differences.Add(new Difference("AddedAttribute",
                                                   $"Attribute '{type.FullName()}' exists on {errString} in the {Implementation} but not the {Contract}."));

                    changed = true;
                    break;
                }

                case DifferenceType.Changed:
                {
                    ITypeReference type = group.Representative.Attributes.First().Type;

                    if (AttributeFilter.ShouldExclude(type.DocId()))
                    {
                        break;
                    }

                    string contractKey       = attributeComparer.GetKey(group[0].Attributes.First());
                    string implementationKey = attributeComparer.GetKey(group[1].Attributes.First());

                    differences.AddIncompatibleDifference("CannotChangeAttribute",
                                                          $"Attribute '{type.FullName()}' on {errString} changed from '{contractKey}' in the {Contract} to '{implementationKey}' in the {Implementation}.");

                    changed = true;
                    break;
                }

                case DifferenceType.Removed:
                {
                    ITypeReference type = group.Representative.Attributes.First().Type;

                    if (AttributeFilter.ShouldExclude(type.DocId()))
                    {
                        break;
                    }

                    differences.AddIncompatibleDifference("CannotRemoveAttribute",
                                                          $"Attribute '{type.FullName()}' exists on {errString} in the {Contract} but not the {Implementation}.");


                    // removals of an attribute are considered a "change" of the type
                    changed = true;
                    break;
                }
                }
            }
            return(changed);
        }
Пример #4
0
        /// <summary>
        /// SqlSugar的功能介绍
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //设置执行的DEMO
            string switchOn = "select";
            IDemos demo     = null;

            switch (switchOn)
            {
            /****************************基本功能**************************************/
            //查询
            case "select": demo = new Select(); break;

            //删除
            case "delete": demo = new Delete(); break;

            //插入
            case "insert": demo = new Insert(); break;

            //更新
            case "update": demo = new Update(); break;

            //插入或者更新
            case "insertorupdate": demo = new InsertOrUpdate(); break;

            //基层函数的用法
            case "ado": demo = new Ado(); break;

            //事务
            case "tran": demo = new Tran(); break;

            //创建实体函数
            case "createclass": demo = new CreateClass(); break;
            //T4生成 http://www.cnblogs.com/sunkaixuan/p/5751503.html

            //日志记录
            case "log": demo = new Log(); break;

            //枚举支持
            case "enum": demo = new EnumDemo(); break;



            /****************************实体映射**************************************/
            //自动排除非数据库列
            case "ignoreerrorcolumns": demo = new IgnoreErrorColumns(); break;

            //别名表
            case "mappingtable": demo = new MappingTable(); break;

            //别名列
            case "mappingcolumns": demo = new MappingColumns(); break;

            //通过属性的方法设置别名表和别名字段
            case "attributesmapping": demo = new AttributesMapping(); break;



            /****************************业务应用**************************************/
            //过滤器
            case "filter": demo = new Filter(); break;

            //过滤器2
            case "filter2": demo = new Filter2(); break;

            //流水号功能
            case "serialnumber": demo = new SerialNumber(); break;

            //多语言支持 http://www.cnblogs.com/sunkaixuan/p/5709583.html
            //多库并行计算 http://www.cnblogs.com/sunkaixuan/p/5046517.html

            //配置与实例的用法
            case "initconfig": demo = new InitConfig(); break;



            /****************************支持**************************************/
            //公开函数数
            case "pubmethod": demo = new PubMethod(); break;

            //Sql2012分页的支持
            case "sqlpagemodel": demo = new SqlPageModel(); break;

            //设置ToJson的日期格式
            case "serializerdateformat": demo = new SerializerDateFormat(); break;



            /****************************测试用例**************************************/
            case "test": demo = new Test(); break;

            default: Console.WriteLine("switchOn的值错误,请输入正确的 case"); break;
            }
            //执行DEMO
            demo.Init();

            //更多例子请查看API
            //http://www.cnblogs.com/sunkaixuan/p/5654695.html
            Console.WriteLine("执行成功请关闭窗口");
            Console.ReadKey();
        }
Пример #5
0
        private bool AnyAttributeAdded(IDifferences differences, IReference target, IEnumerable<ICustomAttribute> implAttributes, IEnumerable<ICustomAttribute> contractAttributes)
        {
            bool added = false;

            AttributesMapping<IEnumerable<ICustomAttribute>> attributeMapping = new AttributesMapping<IEnumerable<ICustomAttribute>>(_settings);
            attributeMapping.AddMapping(0, implAttributes);
            attributeMapping.AddMapping(1, contractAttributes);

            foreach (var group in attributeMapping.Attributes)
            {
                switch (group.Difference)
                {
                    case DifferenceType.Added:
                        ITypeReference type = group.Representative.Attributes.First().Type;
                        string attribName = type.FullName();

                        if (s_IgnorableAttributes.Contains(attribName))
                            break;

                        differences.AddIncompatibleDifference(this,
                            "Attribute '{0}' exists in the contract but not the implementation.",
                            attribName, target.FullName());

                        added = true;

                        break;
                    case DifferenceType.Changed:

                        //TODO: Add some more logic to check the two lists of attributes which have the same type.
                        break;

                    case DifferenceType.Removed:
                        // Removing attributes is OK
                        break;
                }
            }

            return added;
        }