public sealed override String ToString()
        {
            try
            {
                TypeContext            typeContext            = _contextTypeInfo.TypeContext;
                ReflectionTypeProvider reflectionTypeProvider = new ReflectionTypeProvider(throwOnError: false);
                RuntimeTypeInfo        fieldType = _field.DecodeSignature(reflectionTypeProvider, typeContext);

                string fieldTypeName;
                if (reflectionTypeProvider.ExceptionOccurred)
                {
                    fieldTypeName = Type.DefaultTypeNameWhenMissingMetadata;
                }
                else
                {
                    fieldTypeName = fieldType.FormatTypeNameForReflection();
                }

                return(fieldTypeName + " " + this.Name);
            }
            catch
            {
                return(Type.DefaultTypeNameWhenMissingMetadata + " " + this.Name);
            }
        }
        public sealed override String ToString()
        {
            try
            {
                TypeContext            typeContext            = _contextTypeInfo.TypeContext;
                ReflectionTypeProvider reflectionTypeProvider = new ReflectionTypeProvider(throwOnError: false);
                RuntimeTypeInfo        fieldType = _field.DecodeSignature(reflectionTypeProvider, typeContext);

                string fieldTypeName;
                if (reflectionTypeProvider.ExceptionOccurred)
                {
                    fieldTypeName = ToStringUtils.UnavailableType;
                }
                else
                {
                    fieldTypeName = fieldType.FormatTypeName();
                }

                return(fieldTypeName + " " + this.Name);
            }
            catch
            {
                return(ToStringUtils.UnavailableType + " " + this.Name);
            }
        }
        //
        // Main routine to parse a metadata type specification signature.
        //
        private static RuntimeTypeInfo TryResolveTypeSignature(this TypeSpecificationHandle typeSpecHandle, MetadataReader reader, TypeContext typeContext, ref Exception exception)
        {
            TypeSpecification      typeSpec        = reader.GetTypeSpecification(typeSpecHandle);
            ReflectionTypeProvider refTypeProvider = new ReflectionTypeProvider(throwOnError: false);
            RuntimeTypeInfo        result          = typeSpec.DecodeSignature <RuntimeTypeInfo, TypeContext>(refTypeProvider, typeContext);

            exception = refTypeProvider.ExceptionResult;
            return(result);
        }
 private RuntimeTypeInfo TryResolveSignature(TypeContext typeContext, ref Exception exception)
 {
     ReflectionTypeProvider typeProvider = new ReflectionTypeProvider(throwOnError: false);
     SignatureDecoder<RuntimeTypeInfo, TypeContext> signatureDecoder = new SignatureDecoder<RuntimeTypeInfo, TypeContext>(typeProvider, (MetadataReader)Reader, typeContext);
     BlobReader localCopyOfReader = _blobReader;
     RuntimeTypeInfo result = signatureDecoder.DecodeType(ref localCopyOfReader, false);
     exception = typeProvider.ExceptionResult;
     return result;
 }
Exemple #5
0
        protected sealed override Guid?ComputeGuidFromCustomAttributes()
        {
            //
            // Look for a [Guid] attribute. If found, return that.
            //
            foreach (CustomAttributeHandle cah in _typeDefinition.GetCustomAttributes())
            {
                // We can't reference the GuidAttribute class directly as we don't have an official dependency on System.Runtime.InteropServices.
                // Following age-old CLR tradition, we search for the custom attribute using a name-based search. Since this makes it harder
                // to be sure we won't run into custom attribute constructors that comply with the GuidAttribute(String) signature,
                // we'll check that it does and silently skip the CA if it doesn't match the expected pattern.
                CustomAttribute attribute = Reader.GetCustomAttribute(cah);
                EntityHandle    ctorType;
                EcmaMetadataHelpers.GetAttributeTypeDefRefOrSpecHandle(_reader, attribute.Constructor, out ctorType);
                StringHandle typeNameHandle;
                StringHandle typeNamespaceHandle;
                if (EcmaMetadataHelpers.GetAttributeNamespaceAndName(Reader, ctorType, out typeNamespaceHandle, out typeNameHandle))
                {
                    MetadataStringComparer stringComparer = Reader.StringComparer;
                    if (stringComparer.Equals(typeNamespaceHandle, "System.Runtime.InteropServices"))
                    {
                        if (stringComparer.Equals(typeNameHandle, "GuidAttribute"))
                        {
                            ReflectionTypeProvider typeProvider = new ReflectionTypeProvider(throwOnError: false);

                            CustomAttributeValue <RuntimeTypeInfo> customAttributeValue = attribute.DecodeValue(typeProvider);
                            if (customAttributeValue.FixedArguments.Length != 1)
                            {
                                continue;
                            }

                            CustomAttributeTypedArgument <RuntimeTypeInfo> firstArg = customAttributeValue.FixedArguments[0];
                            if (firstArg.Value == null)
                            {
                                continue;
                            }

                            string guidString = firstArg.Value as string;
                            if (guidString == null)
                            {
                                continue;
                            }

                            return(new Guid(guidString));
                        }
                    }
                }
            }

            return(null);
        }
        // Equals/GetHashCode no need to override (they just implement reference equality but desktop never unified these things.)

        private void LoadArgumentInfo(bool throwIfMissingMetadata, out IList <CustomAttributeNamedArgument> namedArguments, out IList <CustomAttributeTypedArgument> fixedArguments, out bool metadataWasMissing)
        {
            LowLevelListWithIList <CustomAttributeNamedArgument> newNamedArguments = new LowLevelListWithIList <CustomAttributeNamedArgument>();
            LowLevelListWithIList <CustomAttributeTypedArgument> newFixedArguments = new LowLevelListWithIList <CustomAttributeTypedArgument>();
            ReflectionTypeProvider typeProvider = new ReflectionTypeProvider(throwIfMissingMetadata);

            CustomAttributeValue <RuntimeTypeInfo> customAttributeValue = _customAttribute.DecodeValue(typeProvider);

            foreach (CustomAttributeTypedArgument <RuntimeTypeInfo> fixedArgument in customAttributeValue.FixedArguments)
            {
                newFixedArguments.Add(WrapInCustomAttributeTypedArgument(fixedArgument.Value, fixedArgument.Type));
            }

            foreach (CustomAttributeNamedArgument <RuntimeTypeInfo> ecmaNamedArgument in customAttributeValue.NamedArguments)
            {
                bool isField = ecmaNamedArgument.Kind == CustomAttributeNamedArgumentKind.Field;
                CustomAttributeTypedArgument typedArgument = WrapInCustomAttributeTypedArgument(ecmaNamedArgument.Value, ecmaNamedArgument.Type);
                newNamedArguments.Add(ReflectionAugments.CreateCustomAttributeNamedArgument(this.AttributeType, ecmaNamedArgument.Name, isField, typedArgument));
            }

            if (newFixedArguments.Count == 0)
            {
                fixedArguments = Array.Empty <CustomAttributeTypedArgument>();
            }
            else
            {
                fixedArguments = newFixedArguments;
            }

            if (newNamedArguments.Count == 0)
            {
                namedArguments = Array.Empty <CustomAttributeNamedArgument>();
            }
            else
            {
                namedArguments = newNamedArguments;
            }

            metadataWasMissing = typeProvider.ExceptionOccurred;
        }