Example #1
0
        public void EqualityTest_SimpleType_DifferentVersion()
        {
            AssetIdentifier aid  = AssetIdentifier.Parse("{T:System.Object, V:4.1.2.3}");
            AssetIdentifier aid2 = AssetIdentifier.FromMemberInfo(typeof(object));

            Assert.False(aid.Equals(aid2));
        }
Example #2
0
        public void EqualityTest_ClosedGenericType_EqualTypeParam()
        {
            AssetIdentifier aid  = AssetIdentifier.FromMemberInfo(typeof(List <int>));
            AssetIdentifier aid2 = AssetIdentifier.FromMemberInfo(typeof(List <int>));

            Assert.True(aid.Equals(aid2));
        }
Example #3
0
        public void EqualityTest_OpenGenericType()
        {
            AssetIdentifier aid  = AssetIdentifier.FromMemberInfo(typeof(List <>));
            AssetIdentifier aid2 = AssetIdentifier.FromMemberInfo(typeof(List <>));

            Assert.True(aid.Equals(aid2));
        }
Example #4
0
        public void EqualityTest_ClosedGenericType_NotEqual()
        {
            AssetIdentifier aid  = AssetIdentifier.FromMemberInfo(typeof(List <string>));
            AssetIdentifier aid2 = AssetIdentifier.FromMemberInfo(typeof(HashSet <string>));

            Assert.False(aid.Equals(aid2));
        }
Example #5
0
        public void ParseOpenGenericTypeAssetId_TwoParams()
        {
            AssetIdentifier aid  = AssetIdentifier.Parse("{T:System.Collections.Generic.Dictionary`2, V:4.0.0.0}");
            AssetIdentifier aid2 = AssetIdentifier.FromMemberInfo(typeof(Dictionary <string, string>));

            Assert.Equal(aid.ToString(), aid2.ToString());
        }
Example #6
0
        public void EqualityTest_SimpleType_NotEqual()
        {
            AssetIdentifier aid  = AssetIdentifier.FromMemberInfo(typeof(string));
            AssetIdentifier aid2 = AssetIdentifier.FromMemberInfo(typeof(int));

            Assert.False(aid.Equals(aid2));
        }
        public void RoundTripTypes(string assetId)
        {
            Debug.WriteLine(assetId);
            AssetIdentifier aid = AssetIdentifier.Parse(assetId);
            object          obj = this._resolver.Resolve(aid);

            Assert.NotNull(obj);
            Assert.Equal(assetId, AssetIdentifier.FromMemberInfo((Type)obj).AssetId);
        }
        public void RoundTripMember(string assetId)
        {
            Debug.WriteLine(assetId);
            AssetIdentifier aid = AssetIdentifier.Parse(assetId);
            MemberInfo      obj = (MemberInfo)this._resolver.Resolve(aid);

            Assert.NotNull(obj);
            Assert.Equal(assetId, AssetIdentifier.FromMemberInfo(obj).AssetId);
        }
        public string getVersionedId(string assetId)
        {
            AssetIdentifier aid        = AssetIdentifier.Parse(assetId);
            AssetIdentifier hintAsmAid = null;

            if (this._hintAssembly != null)
            {
                hintAsmAid = AssetIdentifier.FromAssembly(this._hintAssembly);
            }

            if (aid.Type == AssetType.Assembly)
            {
                Assembly asm = (Assembly)this._context.AssetResolver.Resolve(aid, hintAsmAid);
                aid = AssetIdentifier.FromAssembly(asm);
            }
            else if (aid.Type == AssetType.Namespace)
            {
                string ns = aid.AssetId.Substring(aid.TypeMarker.Length + 1);

                var version = this.GetNamespaceVersion(this._hintAssembly, ns);

                if (version == null)
                {
                    throw new Exception("Version not found for asset: " + assetId);
                }

                aid = AssetIdentifier.FromNamespace(ns, version);
            }
            else
            {
                object obj = this._context.AssetResolver.Resolve(aid, hintAsmAid);
                if (aid.Type == AssetType.Unknown)
                {
                    MethodInfo[] arr = obj as MethodInfo[];
                    if (arr != null)
                    {
                        // TODO this isn't very nice but it should do the trick for now
                        var dummyAid = AssetIdentifier.FromMemberInfo(arr[0]);
                        aid = new AssetIdentifier(aid.AssetId, dummyAid.Version);
                    }
                    else
                    {
                        throw new NotSupportedException("Unknow AssetIdentifier marker: " + aid.TypeMarker);
                    }
                }
                else
                {
                    aid = AssetIdentifier.FromMemberInfo((MemberInfo)obj);
                }
            }

            this._context.AddReference(aid);

            return(aid.ToString());
        }
Example #10
0
        public void ParseExplicitInterfaceImpl()
        {
            var dict = typeof(Dictionary <String, String>);

            var icol = dict.GetInterfaceMap(typeof(ICollection <KeyValuePair <String, String> >));

            var addMethod = icol.TargetMethods.Single(m => m.IsPrivate && m.Name.EndsWith(".Add"));

            var aid = AssetIdentifier.FromMemberInfo(addMethod);

            var id = AssetIdentifier.Parse(aid.AssetId);
        }
        private static IEnumerable <XObject> GenerateAttributeArgument(IProcessingContext context,
                                                                       CustomAttributeTypedArgument cata)
        {
            // TODO this needs to be cleaned up, and fixed
            context.AddReference(AssetIdentifier.FromMemberInfo(cata.ArgumentType));
            yield return(new XAttribute("type", AssetIdentifier.FromMemberInfo(cata.ArgumentType)));

            if (cata.ArgumentType.IsEnum)
            {
                if (
                    cata.ArgumentType.GetCustomAttributesData().Any(
                        ca =>
                        ca.Constructor.DeclaringType ==
                        typeof(FlagsAttribute)))
                {
                    string   flags = Enum.ToObject(cata.ArgumentType, cata.Value).ToString();
                    string[] parts = flags.Split(',');

                    yield return
                        (new XElement("literal",
                                      new XAttribute("value", cata.Value),
                                      Array.ConvertAll(parts,
                                                       s => new XElement("flag", new XAttribute("value", s.Trim())))));
                }
                else
                {
                    string value = Enum.GetName(cata.ArgumentType, cata.Value);
                    if (value != null)
                    {
                        yield return(new XElement("literal", new XAttribute("value", value)));
                    }

                    yield return(new XElement("literal", new XAttribute("value", cata.Value)));
                }
            }
            else if (cata.ArgumentType == typeof(Type))
            {
                XElement tmp = new XElement("tmp");
                DocGenerator.GenerateTypeRef(context.Clone(tmp), (Type)cata.Value, "value");
                yield return(tmp.Attribute("value"));

                foreach (XElement xElement in tmp.Elements())
                {
                    yield return(xElement);
                }
            }
            else // TODO fix how this encodes unprintable characters
            {
                yield return(new XAttribute("value", cata.Value.ToString().Replace("\0", "\\0")));
            }
        }
Example #12
0
        public void ParseMethodsWithRefParams()
        {
            var aid = AssetIdentifier.FromMemberInfo(typeof(GenericClass <>).GetMethod("TryRefMethod"));
            // Ensure we can parse this.
            var id = AssetIdentifier.Parse(aid.AssetId);

            aid = AssetIdentifier.FromMemberInfo(typeof(GenericClass <>).GetMethod("TryRefMethodGeneric"));

            Assert.Equal(
                "M:Company.Project.Library.GenericClass`1.TryRefMethodGeneric``1(Company.Project.Library.GenericClass{`0}.NestedGeneric{``0}@)",
                aid.AssetId);

            // Ensure we can parse this.
            id = AssetIdentifier.Parse(aid.AssetId);
        }
Example #13
0
        public void FromInheritedMemeberInfo()
        {
            AssetIdentifier aid = AssetIdentifier.FromMemberInfo(typeof(RegularClass).GetMethod("ToString"));

            Assert.Equal("{M:Company.Project.Library.RegularClass.ToString, V:" + aid.Version + "}", aid.ToString());
        }
Example #14
0
        public void FromClosedGenericType_WithTwoParams_ToString()
        {
            AssetIdentifier aid = AssetIdentifier.FromMemberInfo(typeof(Dictionary <string, string>));

            Assert.Equal("{T:System.Collections.Generic.Dictionary`2, V:4.0.0.0}", aid.ToString());
        }
Example #15
0
        public void FromClosedGenericType_ToString()
        {
            AssetIdentifier aid = AssetIdentifier.FromMemberInfo(typeof(List <string>));

            Assert.Equal("T:System.Collections.Generic.List`1", aid.AssetId);
        }
        // TODO fix this, and the accompanying XSLT template, the construction of attribute
        // arguments isn't very consitent
        private static void GenerateAttributeElements(IProcessingContext context,
                                                      IEnumerable <CustomAttributeData> attrData)
        {
            foreach (CustomAttributeData custAttr in attrData)
            {
                AssetIdentifier typeAssetId =
                    AssetIdentifier.FromMemberInfo(custAttr.Constructor.ReflectedType
                                                   ?? custAttr.Constructor.DeclaringType);

                if (context.IsFiltered(typeAssetId))
                {
                    continue;
                }

                context.AddReference(AssetIdentifier.FromMemberInfo(custAttr.Constructor));

                var attrElem = new XElement("attribute",
                                            new XAttribute("type",
                                                           typeAssetId),
                                            new XAttribute("constructor",
                                                           AssetIdentifier.FromMemberInfo(custAttr.Constructor)));

                foreach (CustomAttributeTypedArgument cta in custAttr.ConstructorArguments)
                {
                    if (cta.Value is ReadOnlyCollection <CustomAttributeTypedArgument> )
                    {
                        AssetIdentifier elementAssetId =
                            AssetIdentifier.FromMemberInfo(cta.ArgumentType.GetElementType());
                        context.AddReference(elementAssetId);
                        attrElem.Add(new XElement("argument",
                                                  new XElement("array",
                                                               new XAttribute("type", elementAssetId),
                                                               ((IEnumerable <CustomAttributeTypedArgument>)cta.Value).
                                                               Select(
                                                                   ata =>
                                                                   new XElement("element",
                                                                                GenerateAttributeArgument(
                                                                                    context,
                                                                                    ata))))));
                    }
                    else
                    {
                        attrElem.Add(new XElement("argument",
                                                  GenerateAttributeArgument(context, cta)));
                    }
                }

                foreach (CustomAttributeNamedArgument cta in custAttr.NamedArguments)
                {
                    AssetIdentifier namedMember = AssetIdentifier.FromMemberInfo(cta.MemberInfo);
                    context.AddReference(namedMember);

                    if (cta.TypedValue.Value is ReadOnlyCollection <CustomAttributeTypedArgument> )
                    {
                        context.AddReference(namedMember);
                        AssetIdentifier elementAssetId =
                            AssetIdentifier.FromMemberInfo(cta.TypedValue.ArgumentType.GetElementType());
                        context.AddReference(elementAssetId);
                        attrElem.Add(new XElement("argument",
                                                  new XAttribute("member", namedMember),
                                                  new XElement("array",
                                                               new XAttribute("type", elementAssetId),
                                                               ((IEnumerable <CustomAttributeTypedArgument>)
                                                                cta.TypedValue.Value).Select(
                                                                   ata =>
                                                                   new XElement("element",
                                                                                GenerateAttributeArgument(context, ata))))));
                    }
                    else
                    {
                        attrElem.Add(new XElement("argument",
                                                  new XAttribute("member", namedMember),
                                                  GenerateAttributeArgument(context, cta.TypedValue)));
                    }
                }


                context.Element.Add(attrElem);
            }

            //using (var ms = new MemoryStream())
            //    context.Element.Save(ms);
        }