예제 #1
0
        private static String GetSimpleTypeName(Type t)
        {
            String result = XmlPrimitiveSerializer.TryGetPrimitiveTypeName(t);

            if (result == null)
            {
                if (t.IsArray)
                {
                    result = "ArrayOf" + FirstLetterUpper(GetSimpleTypeName(t.GetElementType()));
                }
                else if (t.GetInterface("ICollection`1") != null)
                {
                    // for backward compat
                    var elementType = t.GetInterface("ICollection`1").GetGenericArguments()[0];
                    result = "ArrayOf" + FirstLetterUpper(GetSimpleTypeName(elementType));
                }
                else if (t.IsGenericType)
                {
                    result = t.Name.Split('`')[0] + "Of" + String.Join(String.Empty, t.GetGenericArguments().Select(GetSimpleTypeName));
                }
                else
                {
                    result = t.Name;
                }
            }
            return(result);
        }
예제 #2
0
        internal static XmlNameDeclaration GetRootNameForType(Type t)
        {
            XmlNameDeclaration result = XmlPrimitiveSerializer.TryGetPrimitiveTypeName(t).Bind(str => new XmlNameDeclaration(str));

            if (result == null)
            {
                var rootAttr = t.GetCustomAttributes <XmlRootAttribute>(inherit: false).FirstOrDefault();
                if (rootAttr != null)
                {
                    result = new XmlNameDeclaration(rootAttr.ElementName, rootAttr.Namespace);
                }
                else
                {
                    result = new XmlNameDeclaration(GetSimpleTypeName(t));
                }
            }
            return(result);
        }