示例#1
0
        private void RoleReader_ReadInterface(DCIRole role, RegionNodes roleRegion, string roleName, ClassDeclarationSyntax parentNode)
        {
            foreach (var node in roleRegion.Nodes)
            {
                if (node.IsKind(SyntaxKind.InterfaceDeclaration) &&
                    parentNode == node.Parent)
                {
                    var interfaceNode = node as InterfaceDeclarationSyntax;

                    if (roleName.Equals(interfaceNode.Identifier.ToString()))
                    {
                        var newInterface = new DCIRoleInterface();
                        newInterface.Name = interfaceNode.Identifier.ToString();
                        role.Interface    = newInterface;
                        foreach (var member in interfaceNode.Members)
                        {
                            var property = member as PropertyDeclarationSyntax;
                            var method   = member as MethodDeclarationSyntax;
                            var newInterfaceSignature = new DCIInterfaceSignature();

                            var start  = property != null ? property.Span.Start : method.Span.Start;
                            var length = property != null ? property.Span.Length : method.Span.Length;

                            newInterfaceSignature.Name = property != null?property.Identifier.ToString() : method.Identifier.ToString();

                            newInterfaceSignature.CodeSpan = new Span(start, length);

                            newInterface.AddSignature(newInterfaceSignature);
                        }
                    }
                }
            }
        }
示例#2
0
        void InteractionReader_AddRoleMethods(ref DCIRole role, string expression)
        {
            if (role.Interface == null)
            {
                var newInterface = new DCIRoleInterface();
                newInterface.Name = "methods";
                role.Interface    = newInterface;
            }

            for (int nameStart = 0; nameStart < expression.Length; ++nameStart)
            {
                var nameEnd = nameStart + role.Name.Length + 1;

                if (nameEnd < expression.Length && expression[nameStart + 1] != ' ' &&
                    (expression[nameStart + 1] != ' ' || expression[nameStart + 1] != '('))
                {
                    string name = expression.Substring(nameStart + 1, nameEnd - nameStart);

                    if (name.ToLower().Equals(role.Name.ToLower() + "."))
                    {
                        var methodStart = nameStart + role.Name.Length + 2;

                        string[] endChar = { " ", ";", "(", ".", ")", ",", "/", "+", "*" };

                        var methodEnd = expression.Length;
                        for (int k = 0; k < endChar.Length; ++k)
                        {
                            var me = expression.IndexOf(endChar[k], methodStart);
                            me        = me < 0 ? expression.Length : me;
                            methodEnd = Math.Min(methodEnd, me);
                        }

                        if (methodEnd >= 0 && methodEnd < expression.Length)
                        {
                            var methodName = expression.Substring(methodStart, methodEnd - methodStart);
                            methodName = Char.ToLower(methodName[0]) + methodName.Substring(1);

                            var newInterfaceSignature = new DCIInterfaceSignature();
                            newInterfaceSignature.Name     = methodName;
                            newInterfaceSignature.CodeSpan = role.CodeSpan;

                            role.Interface.AddSignature(newInterfaceSignature);
                        }
                    }
                }
            }
        }