예제 #1
0
        public void Test_GetNamespace_IgnoredNamespaceGeneric()
        {
            TypeDefinition testType = GetType(typeof(ReadOnlySpan <>).Module.FullyQualifiedName, "mdoc.Test.SampleClasses.ReadOnlySpan`1");
            var            ns       = DocUtils.GetNamespace(testType.GenericParameters.First());

            Assert.AreEqual("", ns);
        }
예제 #2
0
        public void DocidCheck()
        {
            XmlDocument doc = new System.Xml.XmlDocument();

            doc.LoadXml(XmlConsts.CheckDocidXml);

            //c# MemberSignature is the same,but docid not
            var listA = doc.SelectNodes("/Type/Members/Member[@MemberName='op_Implicit']");

            if (listA.Count == 2)
            {
                var Notequal = DocUtils.DocIdCheck(listA[0], (XmlElement)listA[1]);
                Assert.IsTrue(Notequal);
            }

            //note:c not have docid item in xml
            var b = doc.SelectSingleNode("/Type/Members/Member[@MemberName='op_Implicit']");
            var c = doc.SelectSingleNode("/Type/Members/Member[@MemberName='.ctor']");

            var flg1 = DocUtils.DocIdCheck(b, (XmlElement)c);

            Assert.IsFalse(flg1);

            //Parameter change position
            var flg2 = DocUtils.DocIdCheck(c, (XmlElement)b);

            Assert.IsFalse(flg2);

            // c# MemberSignature is not same,docid also
            var d    = doc.SelectSingleNode("/Type/Members/Member[@MemberName='Value']");
            var flg3 = DocUtils.DocIdCheck(b, (XmlElement)d);

            Assert.IsTrue(flg3);
        }
        public bool HasNestedClassesDuplicateNames(TypeReference tref)
        {
            string         inputName = DocUtils.GetFormattedTypeName(tref.Name);
            TypeDefinition parentType;

            try
            {
                parentType = tref.DeclaringType?.Resolve();
            }
            catch
            {
                //Resolve() can fail as sometimes Cecil understands types as .net
                //needs to ignore those errors
                parentType = null;
            }

            if (parentType != null && parentType.HasNestedTypes)
            {
                var listOfNested = parentType.NestedTypes;
                int count        = listOfNested.Select(x => DocUtils.GetFormattedTypeName(x.Name)).Count(y => y == inputName);
                if (count > 1)
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #4
0
        public void UpdateDMVT()
        {
            DataTable dt = LibQLSX.Select("exec spGetNewModule");

            if (dt.Rows.Count == 0)
            {
                return;
            }
            foreach (DataRow item in dt.Rows)
            {
                try
                {
                    string moduleCode    = TextUtils.ToString(item["FolderCode"]);
                    string _serverPathCK = string.Format("Thietke.Ck/{0}/{1}.Ck/VT.{1}.xlsm", moduleCode.Substring(0, 6), moduleCode);
                    DocUtils.InitFTPQLSX();
                    if (DocUtils.CheckExits(_serverPathCK))
                    {
                        DocUtils.DownloadFile(_path, "VT." + moduleCode + ".xlsm", _serverPathCK);
                        string filePathDMVT = _path + "VT." + moduleCode + ".xlsm";
                        if (!File.Exists(filePathDMVT))
                        {
                            continue;
                        }
                        DataTable dtDMVT = TextUtils.ExcelToDatatableNoHeader(filePathDMVT, "DMVT");
                        TextUtils.AddDMVTfromModule(filePathDMVT);
                        File.Delete(filePathDMVT);
                    }
                }
                catch
                {
                }
            }
        }
        protected virtual IList <GenericParameter> GetTypeSpecifiGenericParameters(TypeDefinition type)
        {
            var returnItems = new Collection <GenericParameter>();

            List <TypeReference> decls   = DocUtils.GetDeclaringTypes(type);
            List <TypeReference> genArgs = GetGenericArguments(type);
            int argIndex = 0;
            int previouslyAppliedCount = 0;

            var lastItem = decls.Last();

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;

                int argumentCount      = DocUtils.GetGenericArgumentCount(declDef);
                int countLeftUnupplied = argumentCount - previouslyAppliedCount;
                previouslyAppliedCount = argumentCount;

                if (decl != lastItem)
                {
                    argIndex = argIndex + argumentCount;
                }

                if (countLeftUnupplied > 0 && decl == lastItem)
                {
                    for (int i = 0; i < countLeftUnupplied; ++i)
                    {
                        returnItems.Add((GenericParameter)genArgs[argIndex++]);
                    }
                }
            }

            return(returnItems);
        }
예제 #6
0
        public void Update_ImportDoc_Test()
        {
            List <DocumentationImporter> setimporters = new List <DocumentationImporter>();
            List <DocumentationImporter> importers    = new List <DocumentationImporter>();
            var filePath = Path.Combine(Path.GetDirectoryName(this.GetType().Module.Assembly.Location), "SampleClasses\\testImportDoc.xml");
            MsxdocDocumentationImporter importer = new MsxdocDocumentationImporter(
                filePath);

            setimporters.Add(importer);

            XmlDocument doc = new System.Xml.XmlDocument();

            doc.LoadXml(XmlConsts.internalEllXml);

            var type    = GetType(typeof(mdoc.Test2.InternalEIICalss));
            var docEnum = new DocumentationEnumerator();

            var nodeMember = docEnum.GetDocumentationMembers(doc, type, FrameworkTypeEntry.Empty).FirstOrDefault(t => t.Member.FullName == "System.String mdoc.Test2.InternalEIICalss::Getstring(System.Int32)");

            var testKeys = new string[] { "returns", "value", "related", "seealso" };

            for (int i = 0; i < testKeys.Length; i++)
            {
                Assert.IsTrue(DocUtils.CheckRemoveByImporter(nodeMember, testKeys[i], importers, setimporters));
            }
        }
예제 #7
0
        private static bool ChkPropertyVisible(PropertyDefinition property)
        {
            MethodDefinition method;
            bool             get_visible = false;
            bool             set_visible = false;

            if ((method = property.GetMethod) != null &&
                (DocUtils.IsExplicitlyImplemented(method) ||
                 (!method.IsPrivate && !method.IsAssembly && !method.IsFamilyAndAssembly)))
            {
                get_visible = true;
            }

            if ((method = property.SetMethod) != null &&
                (DocUtils.IsExplicitlyImplemented(method) ||
                 (!method.IsPrivate && !method.IsAssembly && !method.IsFamilyAndAssembly)))
            {
                set_visible = true;
            }

            if ((set_visible == false) && (get_visible == false))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
예제 #8
0
        public void TestNodeCleaner2()
        {
            string      xml = @"<Docs>
    <summary>To be added.</summary>
    <param name=""one"" name2=""n2"">To be added.</param>
<!-- this is an xml comment -->
    <param name=""two"">written docs</param>
random text
<param name=""three"">Written but not provided</param>
<![CDATA[
  for some reason
]]>
</Docs>"; string xml2 = @"<Docs>
    <summary>new summary</summary>
<!-- this is another xml comment -->
    <param name=""one"" name2=""n2"">To be added.</param>
    random text
    <param name=""two"">written docs but changed</param>
<param name=""three"">Written but and</param>
<![CDATA[
  for some reason
]]>
</Docs>";
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);

            XmlDocument incomingDoc = new XmlDocument();

            incomingDoc.LoadXml(xml2);
            DocUtils.ClearNodesIfNotDefault(doc.FirstChild, incomingDoc.FirstChild);
            Assert.IsTrue(doc.FirstChild.ChildNodes.Count == 0);
        }
예제 #9
0
        protected override StringBuilder AppendGenericType(StringBuilder buf, TypeReference type, IAttributeParserContext context, bool appendGeneric = true, bool useTypeProjection = false, bool isTypeofOperator = false)
        {
            List <TypeReference> decls = DocUtils.GetDeclaringTypes(
                type is GenericInstanceType ? type.GetElementType() : type);
            bool first = true;

            foreach (var decl in decls)
            {
                TypeReference declDef = decl.Resolve() ?? decl;
                if (!first)
                {
                    buf.Append(NestedTypeSeparator);
                }
                first = false;
                AppendTypeName(buf, declDef, context);
            }
            buf.Append('<');
            first = true;
            foreach (TypeReference arg in GetGenericArguments(type))
            {
                if (!first)
                {
                    buf.Append(", ");
                }
                first = false;
                _AppendTypeName(buf, arg, context);
            }
            buf.Append('>');
            return(buf);
        }
예제 #10
0
        public void IsIgnored_GetMethodIsNotGeneratedByProperty_IsIgnoredFalse()
        {
            var method = GetMethod(typeof(SomeClass), nameof(SomeClass.get_Method));

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.False(isIgnoredPropertyGeneratedMethod);
        }
예제 #11
0
 protected override string GetMethodName(MethodReference method)
 {
     if (DocUtils.IsDestructor(method.Resolve()))
     {
         return("Close");
     }
     return(CamelCase(method.Name));
 }
예제 #12
0
        public void IsIgnored_SetMethodIsGeneratedByProperty_IsIgnoredTrue()
        {
            var method = GetMethod(typeof(SomeClass), "set_" + nameof(SomeClass.Property4));

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
        }
예제 #13
0
        public void IsIgnored_GetMethodInIterfaceIsGeneratedByProperty_IsIgnoredTrue()
        {
            var method = GetMethod(typeof(SomeInterface), "get_B");

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
        }
예제 #14
0
        public void TestCase_OnlyDirectlyImplemented()
        {
            var type   = GetTypeDef <TestClassWithInterfaces> ();
            var ifaces = DocUtils.GetUserImplementedInterfaces(type).ToArray();

            Assert.AreEqual(2, ifaces.Count());
            Assert.AreEqual("I2", ifaces[0].Name);
            Assert.AreEqual("ICombined", ifaces[1].Name);
        }
예제 #15
0
        protected override string GetTypeDeclaration(TypeDefinition type)
        {
            var buf = new StringBuilder();

            if (type.IsEnum)
            {
                // var value = [fully qualified type].[camel-cased name of first enum value];
                var firstElement = type.GetMembers().Skip(1).First();//skip "__value element"

                buf.Append("var value = ");
                buf.Append(ProcessFullName(type.FullName));
                buf.Append(".");
                buf.Append(CamelCase(firstElement.Name));
                return(buf.ToString());
            }
            if (type.IsValueType)
            {
                //Structures: Windows Runtime structures are objects in JavaScript.
                // If you want to pass a Windows Runtime structure to a Windows Runtime method,
                // don't instantiate the structure with the new keyword. Instead, create an object
                // and add the relevant members and their values. The names of the members should be in camel case:
                // SomeStruct.firstMember.

                // var [struct name, camel cased] = {
                //	[fieldname, came cased] : /* Your value */
                buf.Append("var ");
                buf.Append(CamelCase(GetName(type)));
                buf.Append(" = {");
                buf.Append(GetLineEnding());
                buf.Append(string.Join("," + GetLineEnding(),
                                       type.Fields.Select(i => CamelCase(i.Name) + " : /* Your value */")));
                buf.Append(GetLineEnding());
                buf.Append("}");
                return(buf.ToString());
            }
            if (DocUtils.IsDelegate(type))
            {
                //  var [delegateName, camel-cased]Handler = function([parameter name list, camel cased]){
                //  /* Your code */
                //            }
                MethodDefinition invoke = type.GetMethod("Invoke");
                buf.Append("var ");
                buf.Append(CamelCase(GetName(type)));
                buf.Append("Handler = function(");
                AppendParameters(buf, invoke, invoke.Parameters);
                buf.Append("){");
                buf.Append(GetLineEnding());
                buf.Append("/* Your code */");
                buf.Append(GetLineEnding());
                buf.Append("}");
                return(buf.ToString());
            }

            var publicConstructor = GetConstructor(type);

            return(GetDeclaration(publicConstructor));
        }
예제 #16
0
        public void IsIgnored_GetMethodIsGeneratedByProperty_IsIgnoredTrue()
        {
            var method = GetMethod(typeof(DiscriminatedUnions.Shape.Circle),
                                   "get_" + nameof(DiscriminatedUnions.Shape.Circle.radius));

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
        }
예제 #17
0
        public void IsIgnored_GetMethodIsNotGeneratedByProperty_IsIgnoredFalse()
        {
            var method = GetMethod(typeof(Functions),
                                   nameof(Functions.get_function));

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.IsFalse(isIgnoredPropertyGeneratedMethod);
        }
예제 #18
0
        public void IsIgnored_GetMethodIsGeneratedByProperty2_IsIgnoredTrue()
        {
            var method = GetMethod(typeof(DiscriminatedUnions.SizeUnion),
                                   "get_" + nameof(DiscriminatedUnions.SizeUnion.Large));

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
        }
예제 #19
0
        protected override string GetPropertyDeclaration(PropertyDefinition property)
        {
            MethodDefinition gm = null, sm = null;

            string get_visible = null;

            if ((gm = property.GetMethod) != null &&
                (DocUtils.IsExplicitlyImplemented(gm) ||
                 (!gm.IsPrivate && !gm.IsAssembly && !gm.IsFamilyAndAssembly)))
            {
                get_visible = AppendVisibility(new StringBuilder(), gm).ToString();
            }
            string set_visible = null;

            if ((sm = property.SetMethod) != null &&
                (DocUtils.IsExplicitlyImplemented(sm) ||
                 (!sm.IsPrivate && !sm.IsAssembly && !sm.IsFamilyAndAssembly)))
            {
                set_visible = AppendVisibility(new StringBuilder(), sm).ToString();
            }

            if ((set_visible == null) && (get_visible == null))
            {
                return(null);
            }

            StringBuilder buf = new StringBuilder()
                                .Append(".property ");

            if (!(gm ?? sm).IsStatic)
            {
                buf.Append("instance ");
            }
            _AppendTypeName(buf, property.PropertyType, AttributeParserContext.Create(property));
            buf.Append(' ').Append(property.Name);
            if (!property.HasParameters || property.Parameters.Count == 0)
            {
                return(buf.ToString());
            }

            buf.Append('(');
            bool first = true;

            foreach (ParameterDefinition p in property.Parameters)
            {
                if (!first)
                {
                    buf.Append(", ");
                }
                first = false;
                _AppendTypeName(buf, p.ParameterType, AttributeParserContext.Create(p));
            }
            buf.Append(')');

            return(buf.ToString());
        }
예제 #20
0
        public void TestCase()
        {
            var type   = GetTypeDef <TestClassWithInterfaces> ();
            var ifaces = DocUtils.GetAllPublicInterfaces(type).ToArray();

            Assert.AreEqual(3, ifaces.Count());
            Assert.AreEqual("I2", ifaces[0].Name);
            Assert.AreEqual("ICombined", ifaces[1].Name);
            Assert.AreEqual("I1", ifaces[2].Name);
        }
        protected override StringBuilder AppendNamespace(StringBuilder buf, TypeReference type)
        {
            string ns = DocUtils.GetNamespace(type, NestedTypeSeparator);

            if (GetCppType(type.FullName) == null && !string.IsNullOrEmpty(ns) && ns != "System")
            {
                buf.Append(ns).Append(NestedTypeSeparator);
            }
            return(buf);
        }
예제 #22
0
        private bool IsMethodSupported(MethodDefinition methodDefinition)
        {
            bool isDestructor = DocUtils.IsDestructor(methodDefinition);

            return
                (!DocUtils.IsOperator(methodDefinition) &&
                 (!isDestructor || methodDefinition.DeclaringType.Interfaces.Any(i => i.InterfaceType.FullName == "Windows.Foundation.IClosable")) &&
                 methodDefinition.Parameters.All(i => IsSupported(i.CustomAttributes) && !(i.ParameterType is ByReferenceType)) &&
                 IsSupported(methodDefinition.MethodReturnType.CustomAttributes));
        }
예제 #23
0
        public void IsIgnored_PutMethodIsGeneratedByProperty_IsIgnoredTrue()
        {
            var classWithProperties = GetType(UWPTestComponentWinMD, "mdoc.Test.UWP.TestComponent.UwpClassWithProperties");

            var method = GetMethod(classWithProperties, i => i.Name == "put_MyReadWriteProperty");

            var isIgnoredPropertyGeneratedMethod = DocUtils.IsIgnored(method);

            Assert.IsTrue(isIgnoredPropertyGeneratedMethod);
        }
예제 #24
0
        protected override StringBuilder AppendNamespace(StringBuilder buf, TypeReference type)
        {
            string ns = DocUtils.GetNamespace(type);

            if (GetCSharpType(type.FullName) == null && ns != null && ns.Length > 0 && ns != "System")
            {
                buf.Append(ns).Append('.');
            }
            return(buf);
        }
        private bool IsCustomAttribute(TypeDefinition typedef)
        {
            var containingTypeNamespace = DocUtils.GetNamespace(typedef);

            if (typedef.BaseType?.FullName == "System.Attribute" && !containingTypeNamespace.StartsWith("System.") && !containingTypeNamespace.StartsWith("System"))
            {
                return(true);
            }

            return(false);
        }
예제 #26
0
        public void IsEiiignoredMethod()
        {
            var type   = GetType(typeof(mdoc.Test2.InternalEIICalss));
            var member = type.Methods.FirstOrDefault(t => t.FullName == "System.String mdoc.Test2.InternalEIICalss::mdoc.Test.SampleClasses.InterfaceA.get_color()");

            Assert.IsTrue(member.IsSpecialName);
            member.IsSpecialName = false;
            var result = DocUtils.IsEiiIgnoredMethod(member, member.Overrides[0]);

            Assert.IsTrue(result);
        }
예제 #27
0
        private static bool IsAttachedEventHandler(TypeReference typeReference)
        {
            var type = typeReference.Resolve();

            if (!DocUtils.IsDelegate(type))
            {
                return(false);
            }
            MethodDefinition invoke = type.GetMethod("Invoke");

            return(invoke.Parameters.Count == 2);
        }
예제 #28
0
 protected override StringBuilder AppendMethodName(StringBuilder buf, MethodDefinition method)
 {
     if (DocUtils.IsExplicitlyImplemented(method))
     {
         TypeReference   iface;
         MethodReference ifaceMethod;
         DocUtils.GetInfoForExplicitlyImplementedMethod(method, out iface, out ifaceMethod);
         return(buf.Append(new CSharpMemberFormatter(this.TypeMap).GetName(iface))
                .Append('.')
                .Append(ifaceMethod.Name));
     }
     return(base.AppendMethodName(buf, method));
 }
예제 #29
0
        protected override string GetPropertyDeclaration(PropertyDefinition property)
        {
            bool getVisible = property.GetMethod != null && property.GetMethod.IsPublic;
            bool setVisible = property.SetMethod != null && property.SetMethod.IsPublic;
            var  method     = property.SetMethod ?? property.GetMethod;

            // https://github.com/mono/api-doc-tools/issues/133
            // var [property value type, camel-cased] = [typename, camel-cased].[property name, camel-cased];
            // [typename, camel-cased].[property name, camel-cased] = [property value type, camel-cased];
            // Static properties
            // var [property value type, camel-cased] = [typename].[property name, camel-cased];
            // [typename].[property name, camel-cased] = [property value type, camel-cased];
            var buf = new StringBuilder();
            var propertyValueType      = CamelCase(GetName(property.PropertyType));
            var propertyName           = DocUtils.GetPropertyName(property, NestedTypeSeparator);
            var propertyNameCamelCased = CamelCase(propertyName);
            var typeName = GetName(property.DeclaringType);

            if (!method.IsStatic)
            {
                typeName = CamelCase(typeName);
            }

            if (getVisible)
            {
                buf.Append("var ");
                buf.Append(propertyValueType);
                buf.Append(" = ");
                buf.Append(typeName);
                buf.Append(".");
                buf.Append(propertyNameCamelCased);
                buf.Append(";");
            }

            if (setVisible)
            {
                if (getVisible)
                {
                    buf.Append(GetLineEnding());
                }

                buf.Append(typeName);
                buf.Append(".");
                buf.Append(propertyNameCamelCased);
                buf.Append(" = ");
                buf.Append(propertyValueType);
                buf.Append(";");
            }
            return(buf.ToString());
        }
        public override bool IsSupportedMethod(MethodDefinition mdef)
        {
            if (DocUtils.IsExtensionMethod(mdef)
                //no support of 'params';
                //can be substituted with 'Variadic functions' hovewer it's not full equivalent(not type safe + specific mechanism for reading)
                || mdef.Parameters.Any(IsParamsParameter)
                )
            {
                return(false);
            }

            return
                (IsSupported(mdef.ReturnType) &&
                 mdef.Parameters.All(i => IsSupported(i.ParameterType)));
        }