コード例 #1
0
        /// <summary>
        /// Implements the interface.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="constructor">The constructor.</param>
        /// <param name="variable">The variable.</param>
        public static void ImplementInterface(
            this CodeClass instance, 
            CodeFunction constructor, 
            string variable)
        {
            TraceService.WriteLine("CodeClassExtensions::ImplementInterface file=" + variable);

            //// now add in the interfaces!

            //// split the variable string
            string[] parts = variable.Split(' ');

            constructor.AddParameter(parts[1], parts[0]);

            //// we need to add the variable.
            //// variable could already exist!
            try
            {
                instance.ImplementVariable(parts[1], parts[0], true);
            }
            catch (Exception)
            {
                TraceService.WriteError("variable already exists " + parts[1]);
            }

            //// now do the wiring up of the interface and variable!
            EditPoint editPoint = constructor.GetEndPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

            string code = string.Format("this.{0} = {1};", parts[1], parts[1]);
            editPoint.InsertCodeLine(code);

            //// now update the constructor document comments.
            string paramComment = string.Format("<param name=\"{0}\">The {0}.</param>{1}", parts[1], Environment.NewLine);
            string currentComment = constructor.DocComment;

            int index = currentComment.LastIndexOf("</summary>", StringComparison.Ordinal);

            StringBuilder sb = new StringBuilder();

            if (index != -1)
            {
                sb.Append(currentComment.Substring(0, index + 10));
                sb.Append(paramComment);
                sb.Append(currentComment.Substring(index + 10));

                TraceService.WriteLine("comment added=" + paramComment);
            }

            constructor.DocComment = sb.ToString();
        }
コード例 #2
0
        internal static void GenerateSerializaCode(CodeClass2 classElement, CodeFunction serializeMethod, CodeFunction deserializeMethod, Dictionary<string, CodeClass2> dic, TyrantVSPackage package/*, string serializeMethodParameterName, string deserializeMethodParameterName*/)
        {
            var memberList = new List<SerializeMember>();
            foreach (CodeElement2 member in classElement.Members)
            {
                var field = member as CodeVariable2;
                if (field != null)
                {
                    memberList.Add(new SerializeMember() { Name = field.Name, TypeRef = field.Type, Attributes = field.Attributes });
                    continue;
                }
                var property = member as CodeProperty2;
                if (property != null && property.Getter != null && property.Setter != null)
                    memberList.Add(new SerializeMember() { Name = property.Name, TypeRef = property.Type, Attributes = property.Attributes });
            }
            int iii = serializeMethod.Parameters.Count;
            string serializeMethodParameterName = serializeMethod.Parameters.Item(1).Name;
            string deserializeMethodParameterName = deserializeMethod.Parameters.Item(1).Name;
            var serializeStatementList = new List<string>();
            var deserializeStatementList = new List<string>();
            string deserializeMethodCode = string.Format("int num;{0}while ((num = source.ReadFieldHeader()) > 0){0}{1}{0}switch (num){0}{1}{0}", Environment.NewLine, "{");
            for (int i = 0; i < memberList.Count; ++i)
            {
                var mem = memberList[i];
                bool needContinue = false;
                foreach (CodeAttribute2 codeArrtibute in mem.Attributes)
                {
                    if (codeArrtibute.FullName == "Tyrant.GameCore.DoNotSerializeAttribute")
                    {
                        needContinue = true;
                        break;
                    }
                }
                if (needContinue)
                    continue;

                string serializeMethodName = "";
                string deserializeMethodName = "";
                if (mem.TypeRef.TypeKind == vsCMTypeRef.vsCMTypeRefArray)
                    GetSerializeMethodAndDeserializeMethodName(mem.TypeRef.ElementType, null, ref serializeMethodName, ref deserializeMethodName, "Array", dic, package);
                else
                {
                    if (mem.TypeRef.AsFullName.StartsWith("System.Collections.Generic.List<"))
                    {
                        string fullName = mem.TypeRef.AsFullName;
                        int first = fullName.IndexOf('<');
                        var elementName = fullName.Substring(first + 1, fullName.Length - 2 - first);
                        GetSerializeMethodAndDeserializeMethodName(null, elementName, ref serializeMethodName, ref deserializeMethodName, "List", dic, package);
                    }
                    else
                        GetSerializeMethodAndDeserializeMethodName(mem.TypeRef, null, ref serializeMethodName, ref deserializeMethodName);
                }

                serializeStatementList.Add($"Tyrant.GameCore.CommunicatorHelper.{serializeMethodName}({i + 1}, {mem.Name}, {serializeMethodParameterName});");
                deserializeStatementList.Add($"case {i + 1}:{Environment.NewLine}{mem.Name} = Tyrant.GameCore.CommunicatorHelper.{deserializeMethodName}({deserializeMethodParameterName});{Environment.NewLine}break;");
            }

            if (serializeStatementList.Count > 0)
            {
                var point = serializeMethod.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
                point.ReplaceText(serializeMethod.GetEndPoint(vsCMPart.vsCMPartBody), string.Join(Environment.NewLine, serializeStatementList), (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
            }

            if (deserializeStatementList.Count > 0)
            {
                var point = deserializeMethod.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
                point.ReplaceText(deserializeMethod.GetEndPoint(vsCMPart.vsCMPartBody), deserializeMethodCode + string.Join(Environment.NewLine, deserializeStatementList) + Environment.NewLine + "}" + Environment.NewLine + "}", (int)vsEPReplaceTextOptions.vsEPReplaceTextAutoformat);
            }
        }
コード例 #3
0
        public async Task GetEndPoint_AttributesWithDelimiter()
        {
            CodeFunction testObject = await GetCodeFunctionAsync("A", "MethodA");

            Assert.Throws <COMException>(() => testObject.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter));
        }
コード例 #4
0
ファイル: UpdateLogic.cs プロジェクト: Mediomondo/codemaid
        /// <summary>
        /// Spreads the specified single line method onto multiple lines.
        /// </summary>
        /// <param name="method">The method to update.</param>
        private void SpreadSingleLineMethodOntoMultipleLines(CodeFunction method)
        {
            try
            {
                var start = method.GetStartPoint(vsCMPart.vsCMPartBody).CreateEditPoint();
                var end = method.GetEndPoint(vsCMPart.vsCMPartBody).CreateEditPoint();

                // Insert a new-line before and after the opening brace.
                start.CharLeft();
                start.Insert(Environment.NewLine);
                start.CharRight();
                start.Insert(Environment.NewLine);

                // Insert a new-line before the closing brace, unless the method is empty.
                end.DeleteWhitespace();
                if (end.DisplayColumn > 1)
                {
                    end.Insert(Environment.NewLine);
                }

                // Update the formatting of the method.
                method.StartPoint.CreateEditPoint().SmartFormat(method.EndPoint);
            }
            catch (Exception)
            {
                // Methods may not have a body (ex: partial).
            }
        }
コード例 #5
0
        public async Task GetEndPoint_Attributes()
        {
            CodeFunction testObject = await GetCodeFunctionAsync("A", "MethodA");

            Assert.Throws <NotImplementedException>(() => testObject.GetEndPoint(vsCMPart.vsCMPartAttributes));
        }
コード例 #6
0
        public void GetEndPoint_Whole()
        {
            CodeFunction testObject = GetCodeFunction("A", "MethodA");

            AssertEx.Throws <NotImplementedException>(() => testObject.GetEndPoint(vsCMPart.vsCMPartWhole));
        }
コード例 #7
0
        public void GetEndPoint_HeaderWithAttributes()
        {
            CodeFunction testObject = GetCodeFunction("A", "MethodA");

            AssertEx.Throws <NotImplementedException>(() => testObject.GetEndPoint(vsCMPart.vsCMPartHeaderWithAttributes));
        }
コード例 #8
0
        public void GetEndPoint_BodyWithDelimiter()
        {
            CodeFunction testObject = GetCodeFunction("A", "MethodA");

            AssertEx.Throws <NotImplementedException>(() => testObject.GetEndPoint(vsCMPart.vsCMPartBodyWithDelimiter));
        }
コード例 #9
0
        public void GetEndPoint_AttributesWithDelimiter()
        {
            CodeFunction testObject = GetCodeFunction("A", "MethodA");

            AssertEx.Throws <COMException>(() => testObject.GetEndPoint(vsCMPart.vsCMPartAttributesWithDelimiter));
        }