Ejemplo n.º 1
0
 internal TypeMapping GetDefaultMapping(TypeFlags flags) {
     PrimitiveMapping mapping = new PrimitiveMapping();
     mapping.TypeDesc = Scope.GetTypeDesc("string", XmlSchema.Namespace, flags);
     mapping.TypeName = mapping.TypeDesc.DataType.Name;
     mapping.Namespace = XmlSchema.Namespace;
     return mapping;
 }
 internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName)
 {
     this.name = name.Replace('+', '.');
     this.fullName = fullName.Replace('+', '.');
     this.kind = kind;
     this.baseTypeDesc = baseTypeDesc;
     this.flags = flags;
     this.isXsdType = kind == TypeKind.Primitive;
     if (this.isXsdType)
     {
         this.weight = 1;
     }
     else if (kind == TypeKind.Enum)
     {
         this.weight = 2;
     }
     else if (this.kind == TypeKind.Root)
     {
         this.weight = -1;
     }
     else
     {
         this.weight = (baseTypeDesc == null) ? 0 : (baseTypeDesc.Weight + 1);
     }
     this.dataType = dataType;
     this.formatterName = formatterName;
 }
Ejemplo n.º 3
0
 protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
 {
     // We might be able to compute the type flags for some masks, but for some this will always throw (e.g.
     // Category and GenericVariance should always throw). If you hit an exception, it means you need a
     // special case for IsSignatureVariable.
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
 protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
 {
     return TypeFlags.Class |
         TypeFlags.ContainsGenericVariablesComputed |
         TypeFlags.HasGenericVarianceComputed |
         TypeFlags.HasStaticConstructorComputed;
 }
Ejemplo n.º 5
0
        public void Init(string fullName, int flags, JsTypeFunction thisType, JsTypeFunction baseType, JsTypeFunction[] interfaces, JsTypeFunction[] typeArguments, FieldInfo[] fields, MethodInfo[] methods, ConstructorInfo[] constructors, PropertyInfo[] properties, EventInfo[] events, JsTypeFunction elementType, JsTypeFunction unconstructedType)
        {
            FullName = fullName;

            typeFlags = (TypeFlags)flags;

//            this.typeAttributes = typeAttributes;
            this.thisType = thisType;
            this.baseType = baseType;
            this.interfaces = interfaces;
            this.typeArguments = typeArguments;
            this.fields = fields ?? new FieldInfo[0];
            this.methods = methods ?? new MethodInfo[0];
            this.properties = properties ?? new PropertyInfo[0];
            this.constructors = constructors ?? new ConstructorInfo[0];
            this.events = events ?? new EventInfo[0];
            this.elementType = elementType;
            this.unconstructedType = unconstructedType;

            foreach (var field in this.fields)
                field.declaringType = this;
            foreach (var method in this.methods)
                method.declaringType = this;
            foreach (var property in this.properties)
            {
                property.declaringType = this;
                if (property.GetMethod != null)
                    property.GetMethod.declaringType = this;
                if (property.SetMethod != null)
                    property.SetMethod.declaringType = this;
            }
            foreach (var constructor in this.constructors)
                constructor.declaringType = this;
        }
Ejemplo n.º 6
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = TypeFlags.FunctionPointer;

            if ((mask & TypeFlags.ContainsGenericVariablesComputed) != 0)
            {
                flags |= TypeFlags.ContainsGenericVariablesComputed;

                if (_signature.ReturnType.ContainsGenericVariables)
                    flags |= TypeFlags.ContainsGenericVariables;
                else
                {
                    for (int i = 0; i < _signature.Length; i++)
                    {
                        if (_signature[i].ContainsGenericVariables)
                        {
                            flags |= TypeFlags.ContainsGenericVariables;
                            break;
                        }
                    }
                }
            }

            flags |= TypeFlags.HasGenericVarianceComputed;

            return flags;
        }
 internal void CheckNeedConstructor()
 {
     if ((!this.IsValueType && !this.IsAbstract) && !this.HasDefaultConstructor)
     {
         this.flags |= TypeFlags.Unsupported;
         this.exception = new InvalidOperationException(Res.GetString("XmlConstructorInaccessible", new object[] { this.FullName }));
     }
 }
Ejemplo n.º 8
0
 public TypeDesc(string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags) {
     this.name = name.Replace('+', '.');
     this.fullName = fullName.Replace('+', '.');
     this.kind = kind;
     if (baseTypeDesc != null) {
         this.baseTypeDesc = baseTypeDesc;
     }
     this.flags = flags;
     this.isXsdType = kind == TypeKind.Primitive;
 }
Ejemplo n.º 9
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            flags |= TypeFlags.ContainsGenericVariablesComputed | TypeFlags.ContainsGenericVariables;

            flags |= TypeFlags.GenericParameter;

            return flags;
        }
Ejemplo n.º 10
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                flags |= TypeFlags.SignatureTypeVariable;
            }

            return flags;
        }
Ejemplo n.º 11
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            flags |= TypeFlags.ContainsGenericVariablesComputed | TypeFlags.ContainsGenericVariables;

            flags |= TypeFlags.GenericParameter;

            flags |= TypeFlags.HasGenericVarianceComputed;

            Debug.Assert((flags & mask) != 0);
            return flags;
        }
Ejemplo n.º 12
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = TypeFlags.ByRef;

            if ((mask & TypeFlags.ContainsGenericVariablesComputed) != 0)
            {
                flags |= TypeFlags.ContainsGenericVariablesComputed;
                if (this.ParameterType.ContainsGenericVariables)
                    flags |= TypeFlags.ContainsGenericVariables;
            }

            return flags;
        }
 private static void AddPrimitive(Type type, string dataTypeName, string formatterName, TypeFlags flags)
 {
     XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
         Name = dataTypeName
     };
     TypeDesc desc = new TypeDesc(type, true, dataType, formatterName, flags);
     if (primitiveTypes[type] == null)
     {
         primitiveTypes.Add(type, desc);
     }
     primitiveDataTypes.Add(dataType, desc);
     primitiveNames.Add(dataTypeName, "http://www.w3.org/2001/XMLSchema", desc);
 }
Ejemplo n.º 14
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                flags |= TypeFlags.SignatureTypeVariable;
            }

            // Not all masks are valid to ask on signature variables. If you hit this assert, you might
            // need to special case, or you have a bug.
            Debug.Assert((flags & mask) != 0);
            return flags;
        }
 private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
 {
     XmlSchemaSimpleType dataType = new XmlSchemaSimpleType {
         Name = dataTypeName
     };
     XmlSchemaSimpleTypeRestriction restriction = new XmlSchemaSimpleTypeRestriction {
         BaseTypeName = baseTypeName
     };
     foreach (XmlSchemaFacet facet in facets)
     {
         restriction.Facets.Add(facet);
     }
     dataType.Content = restriction;
     TypeDesc desc = new TypeDesc(type, false, dataType, formatterName, flags);
     if (primitiveTypes[type] == null)
     {
         primitiveTypes.Add(type, desc);
     }
     primitiveDataTypes.Add(dataType, desc);
     primitiveNames.Add(dataTypeName, ns, desc);
 }
Ejemplo n.º 16
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                flags |= TypeFlags.Class;
            }

            if ((mask & TypeFlags.HasGenericVarianceComputed) != 0)
            {
                flags |= TypeFlags.HasGenericVarianceComputed;
            }

            return flags;
        }
Ejemplo n.º 17
0
		protected void MarkEnumOrValueType(string typeNamespace, string typeName)
		{
			// we don't assume that mscorlib won't have nested types with these names,
			// so we don't check that we're not a nested type
			if (typeNamespace == "System"
				&& (typeName == "Enum" || typeName == "ValueType")
				&& this.Assembly.GetName().Name.Equals("mscorlib", StringComparison.OrdinalIgnoreCase))
			{
				typeFlags |= TypeFlags.EnumOrValueType;
			}
		}
 public static bool IsArray(this TypeFlags flags)
 {
     return((flags & TypeFlags.kArray) != 0);
 }
Ejemplo n.º 19
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                unsafe
                {
                    EEType *eetype = _genericTypeDefinition.ToEETypePtr();
                    if (eetype->IsValueType)
                    {
                        if (eetype->CorElementType == 0)
                        {
                            flags |= TypeFlags.ValueType;
                        }
                        else
                        {
                            if (eetype->BaseType == typeof(System.Enum).TypeHandle.ToEETypePtr())
                            {
                                flags |= TypeFlags.Enum;
                            }
                            else
                            {
                                // Primitive type.
                                if (eetype->CorElementType <= CorElementType.ELEMENT_TYPE_U8)
                                {
                                    flags |= (TypeFlags)eetype->CorElementType;
                                }
                                else
                                {
                                    switch (eetype->CorElementType)
                                    {
                                    case CorElementType.ELEMENT_TYPE_I:
                                        flags |= TypeFlags.IntPtr;
                                        break;

                                    case CorElementType.ELEMENT_TYPE_U:
                                        flags |= TypeFlags.UIntPtr;
                                        break;

                                    case CorElementType.ELEMENT_TYPE_R4:
                                        flags |= TypeFlags.Single;
                                        break;

                                    case CorElementType.ELEMENT_TYPE_R8:
                                        flags |= TypeFlags.Double;
                                        break;

                                    default:
                                        throw new BadImageFormatException();
                                    }
                                }
                            }
                        }
                    }
                    else if (eetype->IsInterface)
                    {
                        flags |= TypeFlags.Interface;
                    }
                    else
                    {
                        flags |= TypeFlags.Class;
                    }
                }
            }

            if ((mask & TypeFlags.IsByRefLikeComputed) != 0)
            {
                flags |= TypeFlags.IsByRefLikeComputed;

                unsafe
                {
                    EEType *eetype = _genericTypeDefinition.ToEETypePtr();
                    if (eetype->IsByRefLike)
                    {
                        flags |= TypeFlags.IsByRefLike;
                    }
                }
            }

            return(flags);
        }
Ejemplo n.º 20
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.ContainsGenericVariablesComputed) != 0)
            {
                flags |= TypeFlags.ContainsGenericVariablesComputed;

                // TODO: Do we really want to get the instantiation to figure out whether the type is generic?
                if (this.HasInstantiation)
                {
                    flags |= TypeFlags.ContainsGenericVariables;
                }
            }

            if ((mask & TypeFlags.CategoryMask) != 0 && (flags & TypeFlags.CategoryMask) == 0)
            {
                TypeDesc baseType = this.BaseType;

                if (baseType != null && baseType.IsWellKnownType(WellKnownType.ValueType) &&
                    !this.IsWellKnownType(WellKnownType.Enum))
                {
                    TypeFlags categoryFlags;
                    if (!TryGetCategoryFlagsForPrimitiveType(out categoryFlags))
                    {
                        categoryFlags = TypeFlags.ValueType;
                    }
                    flags |= categoryFlags;
                }
                else
                if (baseType != null && baseType.IsWellKnownType(WellKnownType.Enum))
                {
                    flags |= TypeFlags.Enum;
                }
                else
                {
                    if ((_typeDefinition.Flags & TypeAttributes.Interface) != 0)
                    {
                        flags |= TypeFlags.Interface;
                    }
                    else
                    {
                        flags |= TypeFlags.Class;
                    }
                }

                // All other cases are handled during TypeSystemContext intitialization
            }

            if ((mask & TypeFlags.HasGenericVarianceComputed) != 0 &&
                (flags & TypeFlags.HasGenericVarianceComputed) == 0)
            {
                flags |= TypeFlags.HasGenericVarianceComputed;

                foreach (GenericParameterDesc genericParam in Instantiation)
                {
                    if (genericParam.Variance != GenericVariance.None)
                    {
                        flags |= TypeFlags.HasGenericVariance;
                        break;
                    }
                }
            }

            return(flags);
        }
Ejemplo n.º 21
0
 public TypeFilter(TypeFlags typeFlags, Func <IType, bool> predicate)
 {
     this.TypeFlags = typeFlags;
     this.Predicate = predicate;
 }
Ejemplo n.º 22
0
 public bool IsAdaptive()
 {
     return(TypeFlags.Test((uint)(NetConnectionTypeFlags.ConnectionAdaptive | NetConnectionTypeFlags.ConnectionRemoteAdaptive)));
 }
 public static bool IsValueType(this TypeFlags flags)
 {
     return((flags & TypeFlags.kValueType) != 0);
 }
Ejemplo n.º 24
0
 public bool IsConnectionToClient()
 {
     return(TypeFlags.Test((uint)NetConnectionTypeFlags.ConnectionToClient));
 }
Ejemplo n.º 25
0
 public void SetIsAdaptive()
 {
     TypeFlags.Set((uint)NetConnectionTypeFlags.ConnectionAdaptive);
     LocalRateChanged = true;
 }
Ejemplo n.º 26
0
 public void SetIsConnectionToClient()
 {
     TypeFlags.Set((uint)NetConnectionTypeFlags.ConnectionToClient);
 }
Ejemplo n.º 27
0
 public bool IsConnectionToServer()
 {
     return(TypeFlags.Test((uint)NetConnectionTypeFlags.ConnectionToServer));
 }
Ejemplo n.º 28
0
            private bool ComputeCanCompareValueTypeBits(MetadataType type)
            {
                Debug.Assert(type.IsValueType);

                if (type.ContainsGCPointers)
                {
                    return(false);
                }

                if (type.IsGenericDefinition)
                {
                    return(false);
                }

                OverlappingFieldTracker overlappingFieldTracker = new OverlappingFieldTracker(type);

                bool result = true;

                foreach (var field in type.GetFields())
                {
                    if (field.IsStatic)
                    {
                        continue;
                    }

                    if (!overlappingFieldTracker.TrackField(field))
                    {
                        // This field overlaps with another field - can't compare memory
                        result = false;
                        break;
                    }

                    TypeDesc fieldType = field.FieldType;
                    if (fieldType.IsPrimitive || fieldType.IsEnum || fieldType.IsPointer || fieldType.IsFunctionPointer)
                    {
                        TypeFlags category = fieldType.UnderlyingType.Category;
                        if (category == TypeFlags.Single || category == TypeFlags.Double)
                        {
                            // Double/Single have weird behaviors around negative/positive zero
                            result = false;
                            break;
                        }
                    }
                    else
                    {
                        // Would be a suprise if this wasn't a valuetype. We checked ContainsGCPointers above.
                        Debug.Assert(fieldType.IsValueType);

                        MethodDesc objectEqualsMethod = ((CompilerTypeSystemContext)fieldType.Context)._objectEqualsMethod;

                        // If the field overrides Equals, we can't use the fast helper because we need to call the method.
                        if (fieldType.FindVirtualFunctionTargetMethodOnObjectType(objectEqualsMethod).OwningType == fieldType)
                        {
                            result = false;
                            break;
                        }

                        if (!_hashtable.GetOrCreateValue((MetadataType)fieldType).CanCompareValueTypeBits)
                        {
                            result = false;
                            break;
                        }
                    }
                }

                // If there are gaps, we can't memcompare
                if (result && overlappingFieldTracker.HasGaps)
                {
                    result = false;
                }

                return(result);
            }
Ejemplo n.º 29
0
 public static bool CanBuildDispatcher(this TypeFlags flags)
 {
     return((flags & (TypeFlags.CanSerialize | TypeFlags.Remotable)) == (TypeFlags.CanSerialize | TypeFlags.Remotable));
 }
Ejemplo n.º 30
0
 static void AddSoapEncodedPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, TypeFlags flags) {
     AddNonXsdPrimitive(type, dataTypeName, ns, formatterName, baseTypeName, new XmlSchemaFacet[0], flags);
 }
Ejemplo n.º 31
0
 protected abstract TypeFlags ComputeTypeFlags(TypeFlags mask);
Ejemplo n.º 32
0
 public static bool CanBuildProxy(this TypeFlags flags)
 {
     return((flags & (TypeFlags.CanDeserialize | TypeFlags.Remotable)) == (TypeFlags.CanDeserialize | TypeFlags.Remotable));
 }
Ejemplo n.º 33
0
 public TypeFilter(TypeFlags typeFlags)
 {
     this.TypeFlags = typeFlags;
 }
Ejemplo n.º 34
0
 public static bool CanDeserialize(this TypeFlags flags)
 {
     return((flags & TypeFlags.CanDeserialize) == TypeFlags.CanDeserialize);
 }
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0 && (flags & TypeFlags.CategoryMask) == 0)
            {
                TypeDesc baseType = this.BaseType;

                if (baseType != null && baseType.IsWellKnownType(WellKnownType.ValueType) &&
                    !this.IsWellKnownType(WellKnownType.Enum))
                {
                    TypeFlags categoryFlags;
                    if (!TryGetCategoryFlagsForPrimitiveType(out categoryFlags))
                    {
                        categoryFlags = TypeFlags.ValueType;
                    }
                    flags |= categoryFlags;
                }
                else
                if (baseType != null && baseType.IsWellKnownType(WellKnownType.Enum))
                {
                    flags |= TypeFlags.Enum;
                }
                else
                {
                    if ((_typeDefinition.Flags & TypeAttributes.Interface) != 0)
                    {
                        flags |= TypeFlags.Interface;
                    }
                    else
                    {
                        flags |= TypeFlags.Class;
                    }
                }

                // All other cases are handled during TypeSystemContext intitialization
            }

            if ((mask & TypeFlags.HasGenericVarianceComputed) != 0 &&
                (flags & TypeFlags.HasGenericVarianceComputed) == 0)
            {
                flags |= TypeFlags.HasGenericVarianceComputed;

                foreach (GenericParameterDesc genericParam in Instantiation)
                {
                    if (genericParam.Variance != GenericVariance.None)
                    {
                        flags |= TypeFlags.HasGenericVariance;
                        break;
                    }
                }
            }

            if ((mask & TypeFlags.HasFinalizerComputed) != 0)
            {
                flags |= TypeFlags.HasFinalizerComputed;

                if (GetFinalizer() != null)
                {
                    flags |= TypeFlags.HasFinalizer;
                }
            }

            if ((mask & TypeFlags.AttributeCacheComputed) != 0)
            {
                flags |= TypeFlags.AttributeCacheComputed;

                if (IsValueType && HasCustomAttribute("System.Runtime.CompilerServices", "IsByRefLikeAttribute"))
                {
                    flags |= TypeFlags.IsByRefLike;
                }
            }

            return(flags);
        }
Ejemplo n.º 36
0
        /// <summary>
        /// Deflate the token
        /// </summary>
        /// <param name="destination">Stream to deflate token to</param>
        public override void Deflate(Stream destination)
        {
            // Calculate total length by adding strings
            uint totalPacketLength = (uint)(FixedPacketLength
                                            + (uint)(string.IsNullOrEmpty(HostName) ? 0 : HostName.Length * 2)                     // HostName
                                            + (uint)(string.IsNullOrEmpty(UserID) ? 0 : UserID.Length * 2)                         // UserID
                                            + (uint)(string.IsNullOrEmpty(Password) ? 0 : Password.Length * 2)                     // Password
                                            + (uint)(string.IsNullOrEmpty(ApplicationName) ? 0 : ApplicationName.Length * 2)       // ApplicationName
                                            + (uint)(string.IsNullOrEmpty(ServerName) ? 0 : ServerName.Length * 2)                 // ServerName
                                            + (uint)(string.IsNullOrEmpty(LibraryName) ? 0 : LibraryName.Length * 2)               // LibraryName
                                            + (uint)(string.IsNullOrEmpty(Language) ? 0 : Language.Length * 2)                     // Language
                                            + (uint)(string.IsNullOrEmpty(Database) ? 0 : Database.Length * 2)                     // Database
                                            + (uint)(string.IsNullOrEmpty(AttachDatabaseFile) ? 0 : AttachDatabaseFile.Length * 2) // AttachDatabaseFile
                                            + (uint)(string.IsNullOrEmpty(ChangePassword) ? 0 : ChangePassword.Length * 2)         // ChangePassword
                                            + (uint)(SSPI == null ? 0 : SSPI.Length)                                               // SSPI
                                            + 0);                                                                                  // Feature extension

            MemoryStream featureExtension = null;

            // Check if we have a feature extension
            if (FeatureExt != null)
            {
                // Allocate feature extension block
                featureExtension = new MemoryStream();

                // Serialize feature extension
                FeatureExt.Deflate(featureExtension);

                // Update total lentgh
                totalPacketLength += (uint)(sizeof(uint) /* Offset of feature extension data */ + featureExtension.Length /* feature extension itself*/);
            }

            // Write packet length
            TDSUtilities.WriteUInt(destination, totalPacketLength);

            // Compile TDS version
            uint tdsVersion = Convert.ToUInt32(string.Format("{0:X}", Math.Max(TDSVersion.Major, 0)) + string.Format("{0:X}", Math.Max(TDSVersion.Minor, 0)) + string.Format("{0:X2}", Math.Max(TDSVersion.Build, 0)) + string.Format("{0:X4}", Math.Max(TDSVersion.Revision, 0)), 16);

            // Write TDS version
            TDSUtilities.WriteUInt(destination, tdsVersion);

            // Write packet length
            TDSUtilities.WriteUInt(destination, PacketSize);

            // Write client program version
            TDSUtilities.WriteUInt(destination, ClientProgramVersion);

            // Write client program identifier
            TDSUtilities.WriteUInt(destination, ClientPID);

            // Write connection identifier
            TDSUtilities.WriteUInt(destination, ConnectionID);

            // Write the first optional flags
            destination.WriteByte(OptionalFlags1.ToByte());

            // Write the second optional flags
            destination.WriteByte(OptionalFlags2.ToByte());

            // Instantiate type flags
            destination.WriteByte(TypeFlags.ToByte());

            // Write the third optional flags
            destination.WriteByte(OptionalFlags3.ToByte());

            // Write client time zone
            TDSUtilities.WriteInt(destination, ClientTimeZone);

            // Write client locale identifier
            TDSUtilities.WriteUInt(destination, ClientLCID);

            // Prepare a collection of property values that will be set later
            IList <TDSLogin7TokenOffsetProperty> variableProperties = new List <TDSLogin7TokenOffsetProperty>();

            // Write client host name
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("HostName"), FixedPacketLength, (ushort)(string.IsNullOrEmpty(HostName) ? 0 : HostName.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write user name and password
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("UserID"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(UserID) ? 0 : UserID.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("Password"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(Password) ? 0 : Password.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write application name
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("ApplicationName"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(ApplicationName) ? 0 : ApplicationName.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write server name
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("ServerName"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(ServerName) ? 0 : ServerName.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Check if we have a feature extension block
            if (FeatureExt != null)
            {
                // Write the offset of the feature extension offset (pointer to pointer)
                variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("FeatureExt"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), sizeof(uint) / 2, true)); // Should be 4 bytes, devided by 2 because the next guy multiplies by 2
                TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
                TDSUtilities.WriteUShort(destination, (ushort)(variableProperties.Last().Length * 2));                                                                                                                      // Compensate for division by 2 above
            }
            else
            {
                // Skip unused
                TDSUtilities.WriteUShort(destination, 0);
                TDSUtilities.WriteUShort(destination, 0);
            }

            // Write client library name
            // We do not need to account for skipped unused bytes here because they're already accounted in fixedPacketLength
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("LibraryName"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(LibraryName) ? 0 : LibraryName.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write language
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("Language"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(Language) ? 0 : Language.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write database
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("Database"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(Database) ? 0 : Database.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Check if client is defined
            if (ClientID == null)
            {
                // Allocate empty identifier
                ClientID = new byte[6];
            }

            // Write unique client identifier
            destination.Write(ClientID, 0, 6);

            // Write SSPI
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("SSPI"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(SSPI == null ? 0 : SSPI.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write database file to be attached. NOTE, "variableProperties.Last().Length" without " * 2" because the preceeding buffer isn't string
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("AttachDatabaseFile"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length), (ushort)(string.IsNullOrEmpty(AttachDatabaseFile) ? 0 : AttachDatabaseFile.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Write password change
            variableProperties.Add(new TDSLogin7TokenOffsetProperty(GetType().GetProperty("ChangePassword"), (ushort)(variableProperties.Last().Position + variableProperties.Last().Length * 2), (ushort)(string.IsNullOrEmpty(ChangePassword) ? 0 : ChangePassword.Length)));
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Position);
            TDSUtilities.WriteUShort(destination, (ushort)variableProperties.Last().Length);

            // Skip long SSPI
            TDSUtilities.WriteUInt(destination, 0);

            // We will be changing collection as we go and serialize everything. As such we can't use foreach and iterator.
            int iCurrentProperty = 0;

            // Iterate through the collection
            while (iCurrentProperty < variableProperties.Count)
            {
                // Get current property by index
                TDSLogin7TokenOffsetProperty property = variableProperties[iCurrentProperty];

                // Check if length is positive
                if (property.Length == 0)
                {
                    // Move to the next property
                    iCurrentProperty++;
                    continue;
                }

                // Check special properties
                if (property.Property.Name == "Password" || property.Property.Name == "ChangePassword")
                {
                    // Write encrypted string value
                    TDSUtilities.WritePasswordString(destination, (string)property.Property.GetValue(this, null));
                }
                else if (property.Property.Name == "FeatureExt")
                {
                    // Check if we are to serialize the offset or the actual data
                    if (property.IsOffsetOffset)
                    {
                        // Property will be written at the offset immediately following all variable length data
                        property.Position = variableProperties.Last().Position + variableProperties.Last().Length;

                        // Write the position at which we'll be serializing the feature extension block
                        TDSUtilities.WriteUInt(destination, property.Position);

                        // Order strings in ascending order by offset
                        variableProperties = variableProperties.OrderBy(p => p.Position).ToList();

                        // Compensate increment to the next position in order to stay on the same
                        iCurrentProperty--;

                        // No longer offset, actual data is going to follow
                        property.IsOffsetOffset = false;
                    }
                    else
                    {
                        // Transfer deflated feature extension into the login stream
                        featureExtension.WriteTo(destination);
                    }
                }
                else if (property.Property.Name == "SSPI")
                {
                    // Write SSPI
                    destination.Write(SSPI, 0, SSPI.Length);
                }
                else
                {
                    // Write the string value
                    TDSUtilities.WriteString(destination, (string)property.Property.GetValue(this, null));
                }

                // Move to the next property
                iCurrentProperty++;
            }
        }
Ejemplo n.º 37
0
 internal TypeDesc(Type type, bool isXsdType, XmlSchemaType dataType, string formatterName, TypeFlags flags)
     : this(type.Name, type.FullName, dataType, TypeKind.Primitive, (TypeDesc)null, flags, formatterName)
 {
     _isXsdType = isXsdType;
     _type = type;
 }
Ejemplo n.º 38
0
 public bool HasFlag(int arrayIndex, TypeFlags flag)
 {
     return((flags[arrayIndex] & flag) == flag);
 }
Ejemplo n.º 39
0
 internal void CheckNeedConstructor()
 {
     if (!IsValueType && !IsAbstract && !HasDefaultConstructor)
     {
         _flags |= TypeFlags.Unsupported;
         _exception = new InvalidOperationException(SR.Format(SR.XmlConstructorInaccessible, FullName));
     }
 }
Ejemplo n.º 40
0
 private static void AddNonXsdPrimitive(Type type, string dataTypeName, string ns, string formatterName, XmlQualifiedName baseTypeName, XmlSchemaFacet[] facets, TypeFlags flags)
 {
     XmlSchemaSimpleType dataType = new XmlSchemaSimpleType();
     dataType.Name = dataTypeName;
     TypeDesc typeDesc = new TypeDesc(type, false, dataType, formatterName, flags);
     if (s_primitiveTypes[type] == null)
         s_primitiveTypes.Add(type, typeDesc);
     s_primitiveDataTypes.Add(dataType, typeDesc);
     s_primitiveNames.Add(dataTypeName, ns, typeDesc);
 }
Ejemplo n.º 41
0
        public RoslynNamedType(INamedTypeSymbol namedTypeSymbol, ParseContext context)
            : base(
                // For unbound generics, we need to use the type it is constructed from to actuall get information about it
                namedTypeSymbol.IsUnboundGenericType ? namedTypeSymbol.ConstructedFrom : namedTypeSymbol,
                context
                )
        {
            Comments = context.DocumentationProvider.GetDocumentationForSymbol(NamedTypeSymbol).Summary;
            FullName = NamedTypeSymbol.GetNormalizedMetadataName();                                      // TODO May need to rethink
            FilePath = namedTypeSymbol.DeclaringSyntaxReferences.FirstOrDefault()?.SyntaxTree?.FilePath; // TODO get rid of this

            _constructedFrom = new Lazy <INamedType>(() => new RoslynNamedType(NamedTypeSymbol.ConstructedFrom, context));

            _typeArguments = new Lazy <IReadOnlyList <IType> >(() =>
            {
                List <IType> typeArgs = new List <IType>();
                foreach (ITypeSymbol typeParam in NamedTypeSymbol.TypeArguments)
                {
                    typeArgs.Add(CreateType(typeParam, context));
                }
                return(typeArgs);
            });


            // Properties
            _properties = new Lazy <IReadOnlyList <IProperty> >(() =>
            {
                List <IProperty> props = new List <IProperty>();
                IEnumerable <IPropertySymbol> properties = NamedTypeSymbol.GetMembers().OfType <IPropertySymbol>();

                foreach (IPropertySymbol propSymb in properties)
                {
                    if (propSymb.GetMethod.DeclaredAccessibility == Accessibility.Public)
                    {
                        RoslynProperty clientProp = new RoslynProperty(propSymb, context);
                        props.Add(clientProp);
                    }
                }
                return(props);
            });

            // fields
            _fields = new Lazy <IReadOnlyList <IField> >(() =>
            {
                List <IField> fields = new List <IField>();
                foreach (IFieldSymbol fieldSymb in NamedTypeSymbol.GetMembers().OfType <IFieldSymbol>())
                {
                    if (fieldSymb.DeclaredAccessibility == Accessibility.Public)
                    {
                        RoslynField field = new RoslynField(fieldSymb, context);
                        fields.Add(field);
                    }
                }
                return(fields);
            });

            // methods
            _methods = new Lazy <IReadOnlyList <IMethod> >(() =>
            {
                List <IMethod> methods = new List <IMethod>();
                foreach (IMethodSymbol methodSymb in NamedTypeSymbol.GetMembers().OfType <IMethodSymbol>())
                {
                    if (methodSymb.DeclaredAccessibility == Accessibility.Public)
                    {
                        RoslynMethod clientProp = new RoslynMethod(methodSymb, context);
                        methods.Add(clientProp);
                    }
                }
                return(methods);
            });

            // Attributes
            _attrs = new Lazy <IReadOnlyList <IAttributeData> >(() =>
            {
                return(RoslynAttributeData.FromSymbol(NamedTypeSymbol, context));
            });

            // Interfaces
            _interfaces = new Lazy <IReadOnlyList <INamedType> >(() =>
            {
                List <INamedType> interfaces = new List <INamedType>();
                foreach (INamedTypeSymbol interfaceSym in NamedTypeSymbol.Interfaces)
                {
                    interfaces.Add(CreateNamedType(interfaceSym, context));
                }
                return(interfaces);
            });

            Flags = new TypeFlags(
                isEnum: namedTypeSymbol.TypeKind == TypeKind.Enum,
                isNullable: IsNullableType(),
                isArray: namedTypeSymbol.TypeKind == TypeKind.Array,
                isList: IsListType(),
                isDictionary: IsDictionaryType(),
                isAnonymous: TypeSymbol.IsAnonymousType,
                isInterface: TypeSymbol.TypeKind == TypeKind.Interface
                );
        }
Ejemplo n.º 42
0
 internal TypeDesc(string name, string fullName, XmlSchemaType dataType, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, string formatterName)
 {
     _name = name.Replace('+', '.');
     _fullName = fullName.Replace('+', '.');
     _kind = kind;
     _baseTypeDesc = baseTypeDesc;
     _flags = flags;
     _isXsdType = kind == TypeKind.Primitive;
     if (_isXsdType)
         _weight = 1;
     else if (kind == TypeKind.Enum)
         _weight = 2;
     else if (_kind == TypeKind.Root)
         _weight = -1;
     else
         _weight = baseTypeDesc == null ? 0 : baseTypeDesc.Weight + 1;
     _dataType = dataType;
     _formatterName = formatterName;
 }
Ejemplo n.º 43
0
 public void SetIsConnectionToServer()
 {
     TypeFlags.Set((uint)NetConnectionTypeFlags.ConnectionToServer);
 }
 public static int ArrayRank(this TypeFlags flags)
 {
     return((int)(flags & TypeFlags.kArrayRankMask) >> 16);
 }
Ejemplo n.º 45
0
 internal void CheckNeedConstructor() {
     if (!IsValueType && !IsAbstract && !HasDefaultConstructor) {
         flags |= TypeFlags.Unsupported;
         this.exception = new InvalidOperationException(Res.GetString(Res.XmlConstructorInaccessible, FullName));
     }
 }
Ejemplo n.º 46
0
 public TypeDescription(string name, string assembly, FieldDescription[] fields, byte[] staticFieldBytes, int baseOrElementTypeIndes, int size, UInt64 typeInfoAddress, int typeIndex, TypeFlags flags)
 {
     m_Name                   = name;
     m_Assembly               = assembly;
     m_Fields                 = fields;
     m_StaticFieldBytes       = staticFieldBytes;
     m_BaseOrElementTypeIndex = baseOrElementTypeIndes;
     m_Size                   = size;
     m_TypeInfoAddress        = typeInfoAddress;
     m_TypeIndex              = typeIndex;
     m_Flags                  = flags;
 }
Ejemplo n.º 47
0
        private static Type GetEnumeratorElementType(Type type, ref TypeFlags flags)
        {
            if (typeof(IEnumerable).IsAssignableFrom(type))
            {
                MethodInfo enumerator = type.GetMethod("GetEnumerator", Array.Empty<Type>());

                if (enumerator == null || !typeof(IEnumerator).IsAssignableFrom(enumerator.ReturnType))
                {
                    // try generic implementation
                    enumerator = null;
                    foreach (MemberInfo member in type.GetMember("System.Collections.Generic.IEnumerable<*", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic))
                    {
                        enumerator = member as MethodInfo;
                        if (enumerator != null && typeof(IEnumerator).IsAssignableFrom(enumerator.ReturnType))
                        {
                            // use the first one we find
                            flags |= TypeFlags.GenericInterface;
                            break;
                        }
                        else
                        {
                            enumerator = null;
                        }
                    }
                    if (enumerator == null)
                    {
                        // and finally private interface implementation
                        flags |= TypeFlags.UsePrivateImplementation;
                        enumerator = type.GetMethod("System.Collections.IEnumerable.GetEnumerator", BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic, Array.Empty<Type>());
                    }
                }
                if (enumerator == null || !typeof(IEnumerator).IsAssignableFrom(enumerator.ReturnType))
                {
                    return null;
                }
                XmlAttributes methodAttrs = new XmlAttributes(enumerator);
                if (methodAttrs.XmlIgnore) return null;

                PropertyInfo p = enumerator.ReturnType.GetProperty("Current");
                Type currentType = (p == null ? typeof(object) : p.PropertyType);

                MethodInfo addMethod = type.GetMethod("Add", new Type[] { currentType });

                if (addMethod == null && currentType != typeof(object))
                {
                    currentType = typeof(object);
                    addMethod = type.GetMethod("Add", new Type[] { currentType });
                }
                if (addMethod == null)
                {
                    throw new InvalidOperationException(SR.Format(SR.XmlNoAddMethod, type.FullName, currentType, "IEnumerable"));
                }
                return currentType;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 48
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                TypeDesc baseType = this.BaseType;

                if (baseType != null && baseType.IsWellKnownType(WellKnownType.ValueType))
                {
                    flags |= TypeFlags.ValueType;
                }
                else
                if (baseType != null && baseType.IsWellKnownType(WellKnownType.Enum))
                {
                    flags |= TypeFlags.Enum;
                }
                else
                {
                    if ((_typeDefinition.Attributes & TypeAttributes.Interface) != 0)
                    {
                        flags |= TypeFlags.Interface;
                    }
                    else
                    {
                        flags |= TypeFlags.Class;
                    }
                }

                // All other cases are handled during TypeSystemContext intitialization
            }

            if ((mask & TypeFlags.HasGenericVarianceComputed) != 0)
            {
                flags |= TypeFlags.HasGenericVarianceComputed;

                foreach (GenericParameterDesc genericParam in Instantiation)
                {
                    if (genericParam.Variance != GenericVariance.None)
                    {
                        flags |= TypeFlags.HasGenericVariance;
                        break;
                    }
                }
            }

            if ((mask & TypeFlags.HasFinalizerComputed) != 0)
            {
                flags |= TypeFlags.HasFinalizerComputed;

                if (GetFinalizer() != null)
                {
                    flags |= TypeFlags.HasFinalizer;
                }
            }

            if ((mask & TypeFlags.AttributeCacheComputed) != 0)
            {
                MetadataReader         reader         = MetadataReader;
                MetadataStringComparer stringComparer = reader.StringComparer;
                bool isValueType = IsValueType;

                flags |= TypeFlags.AttributeCacheComputed;

                foreach (CustomAttributeHandle attributeHandle in _typeDefinition.GetCustomAttributes())
                {
                    if (MetadataReader.GetAttributeNamespaceAndName(attributeHandle, out StringHandle namespaceHandle, out StringHandle nameHandle))
                    {
                        if (isValueType &&
                            stringComparer.Equals(nameHandle, "IsByRefLikeAttribute") &&
                            stringComparer.Equals(namespaceHandle, "System.Runtime.CompilerServices"))
                        {
                            flags |= TypeFlags.IsByRefLike;
                        }

                        if (stringComparer.Equals(nameHandle, "IntrinsicAttribute") &&
                            stringComparer.Equals(namespaceHandle, "System.Runtime.CompilerServices"))
                        {
                            flags |= TypeFlags.IsIntrinsic;
                        }
                    }
                }
            }

            return(flags);
        }
Ejemplo n.º 49
0
 internal TypeDesc(Type type, string name, string fullName, TypeKind kind, TypeDesc baseTypeDesc, TypeFlags flags, TypeDesc arrayElementTypeDesc)
     : this(name, fullName, null, kind, baseTypeDesc, flags, null)
 {
     _arrayElementTypeDesc = arrayElementTypeDesc;
     _type = type;
 }
Ejemplo n.º 50
0
        void Write(DmdType type, TypeFlags flags)
        {
            if ((object)type == null)
            {
                writer.Append("???");
                return;
            }

            if (!IncrementRecursionCounter())
            {
                writer.Append("???");
                return;
            }

            switch (type.TypeSignatureKind)
            {
            case DmdTypeSignatureKind.Type:
                if ((flags & TypeFlags.NoDeclaringTypeNames) == 0 && type.DeclaringType is DmdType declType && !type.IsGenericParameter)
                {
                    Write(declType, flags | (IsGenericTypeDefinition(type) ? TypeFlags.NoGenericDefParams : 0));
                    writer.Append('+');
                }
                if (!type.IsNested && type.MetadataNamespace is string ns && ns.Length > 0)
                {
                    if ((globalFlags & GlobalFlags.Serializable) != 0 ||
                        ((flags & TypeFlags.MethodGenericArgumentType) == 0 && ((flags & TypeFlags.ShortSpecialNames) == 0 || !IsShortNameType(type))))
                    {
                        WriteIdentifier(ns);
                        writer.Append('.');
                    }
                }
                WriteIdentifier(type.MetadataName);
                if ((flags & TypeFlags.NoGenericDefParams) == 0 && (globalFlags & GlobalFlags.Serializable) == 0)
                {
                    WriteTypeGenericArguments(GetGenericArguments(type), flags & ~TypeFlags.NoGenericDefParams);
                }
                break;

            case DmdTypeSignatureKind.Pointer:
                Write(type.GetElementType(), flags);
                writer.Append('*');
                break;

            case DmdTypeSignatureKind.ByRef:
                Write(type.GetElementType(), flags);
                writer.Append('&');
                break;

            case DmdTypeSignatureKind.TypeGenericParameter:
            case DmdTypeSignatureKind.MethodGenericParameter:
                WriteIdentifier(type.MetadataName);
                break;

            case DmdTypeSignatureKind.SZArray:
                Write(type.GetElementType(), flags);
                writer.Append("[]");
                break;

            case DmdTypeSignatureKind.MDArray:
                Write(type.GetElementType(), flags);
                writer.Append('[');
                var rank = type.GetArrayRank();
                if (rank <= 0)
                {
                    writer.Append("???");
                }
                else if (rank == 1)
                {
                    writer.Append('*');
                }
                else
                {
                    writer.Append(',', rank - 1);
                }
                writer.Append(']');
                break;

            case DmdTypeSignatureKind.GenericInstance:
                Write(GetGenericTypeDefinition(type), flags | TypeFlags.NoGenericDefParams);
                if ((flags & TypeFlags.MethodGenericArgumentType) == 0)
                {
                    WriteTypeGenericArguments(GetGenericArguments(type), flags);
                }
                break;

            case DmdTypeSignatureKind.FunctionPointer:
                if ((flags & TypeFlags.FnPtrIsIntPtr) != 0)
                {
                    Write(type.AppDomain.System_IntPtr, flags);
                }
                else
                {
                    writer.Append("(fnptr)");
                }
                break;

            default: throw new InvalidOperationException();
            }

            DecrementRecursionCounter();
        }
Ejemplo n.º 51
0
 private static void AddPrimitive(Type type, string dataTypeName, string formatterName, TypeFlags flags)
 {
     XmlSchemaSimpleType dataType = new XmlSchemaSimpleType();
     dataType.Name = dataTypeName;
     TypeDesc typeDesc = new TypeDesc(type, true, dataType, formatterName, flags);
     if (s_primitiveTypes[type] == null)
         s_primitiveTypes.Add(type, typeDesc);
     s_primitiveDataTypes.Add(dataType, typeDesc);
     s_primitiveNames.Add(dataTypeName, XmlSchema.Namespace, typeDesc);
 }
Ejemplo n.º 52
0
 void WriteTypeGenericArguments(IList <DmdType> genericArguments, TypeFlags flags) => WriteGenericArguments(genericArguments, flags & ~(TypeFlags.ShortSpecialNames | TypeFlags.NoDeclaringTypeNames));
Ejemplo n.º 53
0
 internal TypeDesc GetTypeDesc(string name, string ns, TypeFlags flags)
 {
     TypeDesc typeDesc = (TypeDesc)s_primitiveNames[name, ns];
     if (typeDesc != null)
     {
         if ((typeDesc.Flags & flags) != 0)
         {
             return typeDesc;
         }
     }
     return null;
 }
Ejemplo n.º 54
0
 void WriteMethodGenericArguments(IList <DmdType> genericArguments, TypeFlags flags) => WriteGenericArguments(genericArguments, flags | TypeFlags.MethodGenericArgumentType);
Ejemplo n.º 55
0
		internal Type MarkValueType()
		{
			typeFlags |= TypeFlags.ValueType;
			return this;
		}
Ejemplo n.º 56
0
        void WriteName(DmdType type, TypeFlags flags)
        {
            if ((object)type == null)
            {
                writer.Append("???");
                return;
            }

            if (!IncrementRecursionCounter())
            {
                writer.Append("???");
                return;
            }

            switch (type.TypeSignatureKind)
            {
            case DmdTypeSignatureKind.Type:
                WriteIdentifier(type.MetadataName);
                break;

            case DmdTypeSignatureKind.Pointer:
                WriteName(type.GetElementType(), flags);
                writer.Append('*');
                break;

            case DmdTypeSignatureKind.ByRef:
                WriteName(type.GetElementType(), flags);
                writer.Append('&');
                break;

            case DmdTypeSignatureKind.TypeGenericParameter:
            case DmdTypeSignatureKind.MethodGenericParameter:
                WriteIdentifier(type.MetadataName);
                break;

            case DmdTypeSignatureKind.SZArray:
                WriteName(type.GetElementType(), flags);
                writer.Append("[]");
                break;

            case DmdTypeSignatureKind.MDArray:
                WriteName(type.GetElementType(), flags);
                writer.Append('[');
                var rank = type.GetArrayRank();
                if (rank <= 0)
                {
                    writer.Append("???");
                }
                else if (rank == 1)
                {
                    writer.Append('*');
                }
                else
                {
                    writer.Append(',', rank - 1);
                }
                writer.Append(']');
                break;

            case DmdTypeSignatureKind.GenericInstance:
                WriteName(GetGenericTypeDefinition(type), flags);
                break;

            case DmdTypeSignatureKind.FunctionPointer:
                if ((flags & TypeFlags.FnPtrIsIntPtr) != 0)
                {
                    WriteName(type.AppDomain.System_IntPtr, flags);
                }
                else
                {
                    writer.Append("(fnptr)");
                }
                break;

            default: throw new InvalidOperationException();
            }

            DecrementRecursionCounter();
        }
Ejemplo n.º 57
0
		internal Type(Type underlyingType)
		{
			System.Diagnostics.Debug.Assert(underlyingType.underlyingType == underlyingType);
			this.underlyingType = underlyingType;
			this.typeFlags = underlyingType.typeFlags;
		}
Ejemplo n.º 58
0
 protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
 {
     return(TypeFlags.Class |
            TypeFlags.HasGenericVarianceComputed |
            TypeFlags.HasStaticConstructorComputed);
 }
Ejemplo n.º 59
0
        protected override TypeFlags ComputeTypeFlags(TypeFlags mask)
        {
            TypeFlags flags = 0;

            if ((mask & TypeFlags.CategoryMask) != 0)
            {
                // Universally canonical type is reported as a variable-sized struct.
                // It's the closest logical thing and avoids special casing around it.
                flags |= TypeFlags.ValueType;
            }

            return flags;
        }
        StructMapping ImportStructType(XmlSchemaComplexType type, string typeNs, bool excludeFromImport)
        {
            if (type.Name == null)
            {
                XmlSchemaElement element    = (XmlSchemaElement)type.Parent;
                XmlQualifiedName parentType = XmlSchemas.GetParentName(element);
                throw new InvalidOperationException(Res.GetString(Res.XmlInvalidSchemaElementType, parentType.Name, parentType.Namespace, element.Name));
            }

            TypeDesc baseTypeDesc = null;

            Mapping baseMapping = null;

            if (!type.DerivedFrom.IsEmpty)
            {
                baseMapping = ImportType(type.DerivedFrom, excludeFromImport);

                if (baseMapping is StructMapping)
                {
                    baseTypeDesc = ((StructMapping)baseMapping).TypeDesc;
                }
                else
                {
                    baseMapping = null;
                }
            }
            if (baseMapping == null)
            {
                baseMapping = GetRootMapping();
            }
            Mapping previousMapping = (Mapping)ImportedMappings[type];

            if (previousMapping != null)
            {
                return((StructMapping)previousMapping);
            }
            string        typeName      = GenerateUniqueTypeName(Accessor.UnescapeName(type.Name));
            StructMapping structMapping = new StructMapping();

            structMapping.IsReference = Schemas.IsReference(type);
            TypeFlags flags = TypeFlags.Reference;

            if (type.IsAbstract)
            {
                flags |= TypeFlags.Abstract;
            }
            structMapping.TypeDesc    = new TypeDesc(typeName, typeName, TypeKind.Struct, baseTypeDesc, flags);
            structMapping.Namespace   = typeNs;
            structMapping.TypeName    = type.Name;
            structMapping.BaseMapping = (StructMapping)baseMapping;
            ImportedMappings.Add(type, structMapping);
            if (excludeFromImport)
            {
                structMapping.IncludeInSchema = false;
            }
            CodeIdentifiers members = new CodeIdentifiers();

            members.AddReserved(typeName);
            AddReservedIdentifiersForDataBinding(members);
            structMapping.Members = ImportTypeMembers(type, typeNs, members);
            Scope.AddTypeMapping(structMapping);
            ImportDerivedTypes(new XmlQualifiedName(type.Name, typeNs));
            return(structMapping);
        }