当前位置: 首页>>代码示例>>C#>>正文


C# TypeDesc.CheckNeedConstructor方法代码示例

本文整理汇总了C#中System.Xml.Serialization.TypeDesc.CheckNeedConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# TypeDesc.CheckNeedConstructor方法的具体用法?C# TypeDesc.CheckNeedConstructor怎么用?C# TypeDesc.CheckNeedConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Serialization.TypeDesc的用法示例。


在下文中一共展示了TypeDesc.CheckNeedConstructor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportTypeDesc


//.........这里部分代码省略.........
            else if (type.GetTypeInfo().IsClass)
            {
                if (type == typeof(XmlAttribute))
                {
                    kind = TypeKind.Attribute;
                    flags |= TypeFlags.Special | TypeFlags.CanBeAttributeValue;
                }
                else if (typeof(XmlNode).IsAssignableFrom(type))
                {
                    kind = TypeKind.Node;
                    baseType = type.GetTypeInfo().BaseType;
                    flags |= TypeFlags.Special | TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue;
                    if (typeof(XmlText).IsAssignableFrom(type))
                        flags &= ~TypeFlags.CanBeElementValue;
                    else if (typeof(XmlElement).IsAssignableFrom(type))
                        flags &= ~TypeFlags.CanBeTextValue;
                    else if (type.IsAssignableFrom(typeof(XmlAttribute)))
                        flags |= TypeFlags.CanBeAttributeValue;
                }
                else
                {
                    kind = TypeKind.Class;
                    baseType = type.GetTypeInfo().BaseType;
                    if (type.GetTypeInfo().IsAbstract)
                        flags |= TypeFlags.Abstract;
                }
            }
            else if (type.GetTypeInfo().IsInterface)
            {
                kind = TypeKind.Void;
                flags |= TypeFlags.Unsupported;
                if (exception == null)
                {
                    if (memberInfo == null)
                    {
                        exception = new NotSupportedException(SR.Format(SR.XmlUnsupportedInterface, type.FullName));
                    }
                    else
                    {
                        exception = new NotSupportedException(SR.Format(SR.XmlUnsupportedInterfaceDetails, memberInfo.DeclaringType.FullName + "." + memberInfo.Name, type.FullName));
                    }
                }
            }
            else
            {
                kind = TypeKind.Void;
                flags |= TypeFlags.Unsupported;
                if (exception == null)
                {
                    exception = new NotSupportedException(SR.Format(SR.XmlSerializerUnsupportedType, type.FullName));
                }
            }

            // check to see if the type has public default constructor for classes
            if (kind == TypeKind.Class && !type.GetTypeInfo().IsAbstract)
            {
                flags |= GetConstructorFlags(type, ref exception);
            }
            // check if a struct-like type is enumerable
            if (kind == TypeKind.Struct || kind == TypeKind.Class)
            {
                if (typeof(IEnumerable).IsAssignableFrom(type))
                {
                    arrayElementType = GetEnumeratorElementType(type, ref flags);
                    kind = TypeKind.Enumerable;

                    // GetEnumeratorElementType checks for the security attributes on the GetEnumerator(), Add() methods and Current property, 
                    // we need to check the MoveNext() and ctor methods for the security attribues
                    flags |= GetConstructorFlags(type, ref exception);
                }
            }
            typeDesc = new TypeDesc(type, CodeIdentifier.MakeValid(TypeName(type)), type.ToString(), kind, null, flags, null);
            typeDesc.Exception = exception;

            if (directReference && (typeDesc.IsClass || kind == TypeKind.Serializable))
                typeDesc.CheckNeedConstructor();

            if (typeDesc.IsUnsupported)
            {
                // return right away, do not check anything else
                return typeDesc;
            }
            _typeDescs.Add(type, typeDesc);

            if (arrayElementType != null)
            {
                TypeDesc td = GetTypeDesc(arrayElementType, memberInfo, true, false);
                // explicitly disallow read-only elements, even if they are collections
                if (directReference && (td.IsCollection || td.IsEnumerable) && !td.IsPrimitive)
                {
                    td.CheckNeedConstructor();
                }
                typeDesc.ArrayElementTypeDesc = td;
            }
            if (baseType != null && baseType != typeof(object) && baseType != typeof(ValueType))
            {
                typeDesc.BaseTypeDesc = GetTypeDesc(baseType, memberInfo, false, false);
            }
            return typeDesc;
        }
开发者ID:johnhhm,项目名称:corefx,代码行数:101,代码来源:Types.cs

示例2: ImportTypeDesc


//.........这里部分代码省略.........
         {
             root = TypeKind.Attribute;
             none |= TypeFlags.CanBeAttributeValue | TypeFlags.Special;
         }
         else if (typeof(XmlNode).IsAssignableFrom(type))
         {
             root = TypeKind.Node;
             baseType = type.BaseType;
             none |= TypeFlags.CanBeElementValue | TypeFlags.CanBeTextValue | TypeFlags.Special;
             if (typeof(XmlText).IsAssignableFrom(type))
             {
                 none &= ~TypeFlags.CanBeElementValue;
             }
             else if (typeof(XmlElement).IsAssignableFrom(type))
             {
                 none &= ~TypeFlags.CanBeTextValue;
             }
             else if (type.IsAssignableFrom(typeof(XmlAttribute)))
             {
                 none |= TypeFlags.CanBeAttributeValue;
             }
         }
         else
         {
             root = TypeKind.Class;
             baseType = type.BaseType;
             if (type.IsAbstract)
             {
                 none |= TypeFlags.Abstract;
             }
         }
     }
     else if (type.IsInterface)
     {
         root = TypeKind.Void;
         none |= TypeFlags.Unsupported;
         if (exception == null)
         {
             if (memberInfo == null)
             {
                 exception = new NotSupportedException(Res.GetString("XmlUnsupportedInterface", new object[] { type.FullName }));
             }
             else
             {
                 exception = new NotSupportedException(Res.GetString("XmlUnsupportedInterfaceDetails", new object[] { memberInfo.DeclaringType.FullName + "." + memberInfo.Name, type.FullName }));
             }
         }
     }
     else
     {
         root = TypeKind.Void;
         none |= TypeFlags.Unsupported;
         if (exception == null)
         {
             exception = new NotSupportedException(Res.GetString("XmlSerializerUnsupportedType", new object[] { type.FullName }));
         }
     }
     if ((root == TypeKind.Class) && !type.IsAbstract)
     {
         none |= GetConstructorFlags(type, ref exception);
     }
     if (((root == TypeKind.Struct) || (root == TypeKind.Class)) && typeof(IEnumerable).IsAssignableFrom(type))
     {
         elementType = GetEnumeratorElementType(type, ref none);
         root = TypeKind.Enumerable;
         none |= GetConstructorFlags(type, ref exception);
     }
     desc = new TypeDesc(type, CodeIdentifier.MakeValid(TypeName(type)), type.ToString(), root, null, none, null) {
         Exception = exception
     };
     if (directReference && (desc.IsClass || (root == TypeKind.Serializable)))
     {
         desc.CheckNeedConstructor();
     }
     if (!desc.IsUnsupported)
     {
         this.typeDescs.Add(type, desc);
         if (elementType != null)
         {
             TypeDesc desc2 = this.GetTypeDesc(elementType, memberInfo, true, false);
             if ((directReference && (desc2.IsCollection || desc2.IsEnumerable)) && !desc2.IsPrimitive)
             {
                 desc2.CheckNeedConstructor();
             }
             desc.ArrayElementTypeDesc = desc2;
         }
         if (((baseType != null) && (baseType != typeof(object))) && (baseType != typeof(ValueType)))
         {
             desc.BaseTypeDesc = this.GetTypeDesc(baseType, memberInfo, false, false);
         }
         if (type.IsNestedPublic)
         {
             for (Type type4 = type.DeclaringType; (type4 != null) && !type4.ContainsGenericParameters; type4 = type4.DeclaringType)
             {
                 this.GetTypeDesc(type4, null, false);
             }
         }
     }
     return desc;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:TypeScope.cs


注:本文中的System.Xml.Serialization.TypeDesc.CheckNeedConstructor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。