public DefaultUnresolvedAttribute(ITypeReference attributeType, IEnumerable<ITypeReference> constructorParameterTypes)
		{
			if (attributeType == null)
				throw new ArgumentNullException("attributeType");
			this.attributeType = attributeType;
			this.ConstructorParameterTypes.AddRange(constructorParameterTypes);
		}
 private void WriteDefaultOf(ITypeReference type)
 {
     WriteKeyword("default", true);
     WriteSymbol("(");
     WriteTypeName(type, true);
     WriteSymbol(")");
 }
Ejemplo n.º 3
0
 private static IEnumerable<ITypeReference> AnalyzeNonGenericTypeReference(ITypeReference typeReference)
 {
     if (typeReference is Vector)
         return AnalyzeVectorTypeReference(typeReference);
     else
         return AnalyzeNonVectorTypeReference(typeReference);
 }
Ejemplo n.º 4
0
 public InstanceCreatorOptions(IUnitReflector reflector, ILocalVariableBindings locals, ITypeReference type, params ITypeReference[] constructorParameters)
 {
     this.type = type;
     this.locals = locals;
     this.reflector = reflector;
     this.constructorParameters = constructorParameters;
 }
Ejemplo n.º 5
0
 public CustomAttribute(
     IMethodReference constructor,
     ITypeReference type,
     ReadOnlyArray<MetadataConstant> positionalArguments) :
     this(constructor, type, positionalArguments, ReadOnlyArray<IMetadataNamedArgument>.Empty)
 {
 }
Ejemplo n.º 6
0
 internal ConstantExpression(
   ITypeReference typeReference,
   object/*?*/ value
 ) {
   this.TypeReference = typeReference;
   this.value = value;
 }
Ejemplo n.º 7
0
		public SimpleConstantValue(ITypeReference type, object value)
		{
			if (type == null)
				throw new ArgumentNullException("type");
			this.type = type;
			this.value = value;
		}
Ejemplo n.º 8
0
		public DefaultAttribute(ITypeReference attributeType, IEnumerable<ITypeReference> constructorParameterTypes)
		{
			if (attributeType == null)
				throw new ArgumentNullException("attributeType");
			this.attributeType = attributeType;
			this.constructorParameterTypes = constructorParameterTypes != null ? constructorParameterTypes.ToArray() : null;
		}
Ejemplo n.º 9
0
 public static ITypeReference Unspecialize(ITypeReference type) {
   var sntr = type as ISpecializedNestedTypeReference;
   if (sntr != null) return sntr.UnspecializedVersion;
   var gtir = type as IGenericTypeInstanceReference;
   if (gtir != null) return gtir.GenericType;
   return type;
 }
        protected override LocalDefinition DeclareLocalInternal(
            ITypeReference type,
            object identity,
            string name,
            bool isCompilerGenerated,
            LocalSlotConstraints constraints,
            bool isDynamic,
            ImmutableArray<TypedConstant> dynamicTransformFlags)
        {
            if (allLocals == null)
            {
                allLocals = ImmutableArray.CreateBuilder<ILocalDefinition>(1);
            }

            var local = new LocalDefinition(
                identity: identity,
                name: name,
                type: type,
                slot: this.allLocals.Count,
                isCompilerGenerated: isCompilerGenerated,
                constraints: constraints,
                isDynamic: isDynamic,
                dynamicTransformFlags: dynamicTransformFlags);

            this.allLocals.Add(local);
            return local;
        }
Ejemplo n.º 11
0
		public static ITypeReference Create(ITypeReference elementType)
		{
			if (elementType is IType)
				return new PointerType((IType)elementType);
			else
				return new PointerTypeReference(elementType);
		}
Ejemplo n.º 12
0
 public ConstantArrayCreation(ITypeReference type, IList<ConstantExpression> arrayElements)
 {
     if (arrayElements == null)
         throw new ArgumentNullException("arrayElements");
     this.elementType = type;
     this.arrayElements = arrayElements;
 }
Ejemplo n.º 13
0
		string TypeToString(ITypeReference type, ITypeDefinition currentTypeDef = null)
		{
			var builder = CreateBuilder(currentTypeDef);
			IType resolvedType = type.Resolve(ctx);
			AstType node = builder.ConvertType(resolvedType);
			return node.ToString();
		}
Ejemplo n.º 14
0
		public static string GetName(ITypeReference value)
		{
			if (value != null)
			{
				ITypeCollection genericParameters = value.GenericArguments;
				if (genericParameters.Count > 0)
				{
					using (StringWriter writer = new StringWriter(CultureInfo.InvariantCulture))
					{
						for (int i = 0; i < genericParameters.Count; i++)
						{
							if (i != 0)
							{
								writer.Write(",");
							}

							IType genericParameter = genericParameters[i];
							if (genericParameter != null)
							{
								writer.Write(genericParameter.ToString());
							}
						}

						return value.Name + "<" + writer.ToString() + ">";
					}
				}

				return value.Name;
			}

			throw new NotSupportedException();
		}
Ejemplo n.º 15
0
        private string NameForLocal(int depth, ITypeReference type)
        {
            Contract.Requires(0 <= depth);
            Contract.Requires(type != null);

            var str = String.Format("stack_{0}_{1}", depth, TypeHelper.GetTypeName(type));
            return CleanUpIdentifierName(str);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Creates a fresh local var of the given Type and adds it to the
 /// Bpl Implementation
 /// </summary>
 /// <param name="typeReference"> The type of the new variable </param>
 /// <returns> A fresh Variable with automatic generated name and location </returns>
 public Bpl.Variable CreateFreshLocal(ITypeReference typeReference) {
   Bpl.IToken loc = Bpl.Token.NoToken; // Helper Variables do not have a location
   Bpl.Type t = TranslationHelper.CciTypeToBoogie(typeReference);
   Bpl.LocalVariable v = new Bpl.LocalVariable(loc, new Bpl.TypedIdent(loc, TranslationHelper.GenerateTempVarName(), t));
   ILocalDefinition dummy = new LocalDefinition(); // Creates a dummy entry for the Dict, since only locals in the dict are translated to boogie
   localVarMap.Add(dummy, v);
   return v;
 }
Ejemplo n.º 17
0
        public ModifiedTypeReference(ITypeReference modifiedType, IEnumerable<ICustomModifier> customModifiers)
        {
            Debug.Assert(modifiedType != null);
            Debug.Assert(customModifiers != null);

            this.modifiedType = modifiedType;
            this.customModifiers = customModifiers;
        }
        public ModifiedTypeReference(ITypeReference modifiedType, ImmutableArray<ICustomModifier> customModifiers)
        {
            Debug.Assert(modifiedType != null);
            Debug.Assert(!customModifiers.IsDefault);

            this.modifiedType = modifiedType;
            this.customModifiers = customModifiers;
        }
Ejemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VB6UnresolvedMethod"/> class.
 /// </summary>
 /// <param name="method">The instance of <see cref="IVbMethod"/> that is the source of this entity.</param>
 /// <param name="file">The file that is the source of this entity.</param>
 /// <param name="typeReference">The <see cref="IUnresolvedTypeReference"/> that this member is a child of. May be null.</param>
 /// <param name="typeDefinition">The <see cref="IUnresolvedTypeDefinition"/> that this entity is a child of. May be null.</param>
 internal VB6UnresolvedMethod(IVbMethod method, IUnresolvedFile file, ITypeReference typeReference, IUnresolvedTypeDefinition typeDefinition)
     : base(method, file, typeReference, typeDefinition)
 {
     if (method == null)
     {
         throw new ArgumentNullException("method");
     }
 }
Ejemplo n.º 20
0
 public bool Matches(ITypeReference typeReference)
 {
     typeReference = TypeHelper.UninstantiateAndUnspecialize(typeReference);
     string name = TypeHelper.GetTypeName(typeReference,
             NameFormattingOptions.TypeParameters );
     _log.Debug("Matching type : " + name+" by " + _identifier.ClassName);
     return _identifier.ClassName == name;
 }
Ejemplo n.º 21
0
        public IExpression TypeOf(ITypeReference typeReference)
        {
            var typeOf = new TypeOf();
            typeOf.TypeToGet = typeReference;
            typeOf.Type = reflector.Get<Type>();

            return typeOf;
        }
Ejemplo n.º 22
0
        private Tuple<int, uint> KeyForLocal(int depth, ITypeReference type)
        {
            Contract.Requires(0 <= depth);
            Contract.Requires(type != null);

            var key = Tuple.Create(depth, type.InternedKey);
            return key;
        }
		public DefaultUnresolvedParameter(ITypeReference type, string name)
		{
			if (type == null)
				throw new ArgumentNullException("type");
			if (name == null)
				throw new ArgumentNullException("name");
			this.type = type;
			this.name = name;
		}
Ejemplo n.º 24
0
		internal static ITypeReference Substitute(ITypeReference type, TypeVisitor substitution, ITypeResolveContext context)
		{
			if (substitution == null)
				return type;
			if (context != null)
				return type.Resolve(context).AcceptVisitor(substitution);
			else
				return SubstitutionTypeReference.Create(type, substitution);
		}
Ejemplo n.º 25
0
		public AttributeTypeReference(ITypeReference withoutSuffix, ITypeReference withSuffix)
		{
			if (withoutSuffix == null)
				throw new ArgumentNullException("withoutSuffix");
			if (withSuffix == null)
				throw new ArgumentNullException("withSuffix");
			this.withoutSuffix = withoutSuffix;
			this.withSuffix = withSuffix;
		}
Ejemplo n.º 26
0
        public static IAssembly GetDefiningAssembly(ITypeReference type)
        {
            IUnit unit = TypeHelper.GetDefiningUnit(CanonicalizeType(type));
            // TODO: Does this work?
            IModule module = unit as IModule;
            if (module != null) unit = module.ContainingAssembly;

            return unit as IAssembly;
        }
		public static ITypeReference Create(ITypeReference baseTypeReference, TypeVisitor substitution)
		{
			IType baseType = baseTypeReference as IType;
			if (baseType != null && substitution != null) {
				return baseType.AcceptVisitor(substitution);
			} else {
				return new SubstitutionTypeReference(baseTypeReference, substitution);
			}
		}
		public DefaultExplicitInterfaceImplementation(ITypeReference interfaceType, string memberName)
		{
			if (interfaceType == null)
				throw new ArgumentNullException("interfaceType");
			if (memberName == null)
				throw new ArgumentNullException("memberName");
			this.InterfaceType = interfaceType;
			this.MemberName = memberName;
		}
		public ExplicitInterfaceImplementationMemberReference(ITypeReference typeReference, IMemberReference interfaceMemberReference)
		{
			if (typeReference == null)
				throw new ArgumentNullException("typeReference");
			if (interfaceMemberReference == null)
				throw new ArgumentNullException("interfaceMemberReference");
			this.typeReference = typeReference;
			this.interfaceMemberReference = interfaceMemberReference;
		}
		public SubstitutionTypeReference(ITypeReference baseTypeReference, TypeVisitor substitution)
		{
			if (baseTypeReference == null)
				throw new ArgumentNullException("baseTypeReference");
			if (substitution == null)
				throw new ArgumentNullException("substitution");
			this.baseTypeReference = baseTypeReference;
			this.substitution = substitution;
		}
Ejemplo n.º 31
0
        public virtual void PrintTypeReference(ITypeReference typeReference)
        {
            Contract.Requires(typeReference != null);

            PrintTypeReferenceName(typeReference);
        }
Ejemplo n.º 32
0
        public static IAssembly RewriteModule(IMetadataHost host, PdbReader pdbReader, IAssembly assembly, ITypeReference contractClassType,
                                              ITypeReference compilerGeneratedAttributeType,
                                              ITypeReference systemAttributeType,
                                              ITypeReference systemBooleanType,
                                              ITypeReference systemObjectType,
                                              ITypeReference systemStringType,
                                              ITypeReference systemVoidType)
        {
            var me = new AsmMetaRewriter(host, pdbReader, contractClassType, compilerGeneratedAttributeType, systemAttributeType, systemBooleanType, systemObjectType, systemStringType, systemVoidType);

            return(me.Rewrite(assembly));
        }
Ejemplo n.º 33
0
 public virtual void Visit(ITypeReference typeReference)
 {
     this.DispatchAsReference(typeReference);
 }
Ejemplo n.º 34
0
 void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
 {
     declaringTypeRef = provider.Intern(declaringTypeRef);
     name             = provider.Intern(name);
 }
Ejemplo n.º 35
0
        private void AddTransferInstruction(BasicBlock block, BasicBlock succ, int successorIndex, object targetLocal, object sourceLocal, ITypeReference type)
        {
            Contract.Requires(block != null);
            Contract.Requires(succ != null);
            Contract.Requires(type != null);

            if (block.transferBlocks == null)
            {
                block.transferBlocks = new PeBasicBlock <Instruction> [this.cdfg.SuccessorsFor(block).Count];
            }
            Contract.Assume(0 <= successorIndex && successorIndex < block.transferBlocks.Length);
            var transferBlock = block.transferBlocks[successorIndex];

            if (transferBlock == null)
            {
                transferBlock = block.transferBlocks[successorIndex] = new PeBasicBlock <Instruction>();
            }
            var transferInstructions = transferBlock.transferInstructions;

            if (transferInstructions == null)
            {
                transferInstructions = transferBlock.transferInstructions = new List <Instruction>();
            }
            var ldlocOp = new Operation()
            {
                OperationCode = Cci.OperationCode.Ldloc, Value = sourceLocal
            };
            var ldlocInstr = new Instruction()
            {
                Operation = ldlocOp, Type = type
            };

            transferInstructions.Add(ldlocInstr);
            var stlocOp = new Operation()
            {
                OperationCode = Cci.OperationCode.Stloc, Value = targetLocal
            };
            var stlocInstr = new Instruction()
            {
                Operation = stlocOp, Type = type.PlatformType.SystemVoid
            };

            transferInstructions.Add(stlocInstr);
        }
        private void WriteTypeName(ITypeReference type, ITypeReference containingType, IEnumerable <ICustomAttribute> attributes = null, byte?methodNullableContextValue = null)
        {
            var useKeywords = containingType.GetTypeName() != type.GetTypeName();

            WriteTypeName(type, attributes: attributes, useTypeKeywords: useKeywords, methodNullableContextValue: methodNullableContextValue);
        }
Ejemplo n.º 37
0
 /// <summary>
 /// Creates a reference to the specified type.
 /// </summary>
 /// <param name="type">The type to be converted.</param>
 /// <returns>Returns the type reference.</returns>
 /// <remarks>
 /// If the type is open (contains type parameters '`0' or '``0'),
 /// an <see cref="ITypeResolveContext"/> with the appropriate CurrentTypeDefinition/CurrentMember is required
 /// to resolve the type reference.
 /// For closed types, the root type resolve context for the compilation is sufficient.
 /// </remarks>
 public static ITypeReference ToTypeReference(this Type type)
 {
     if (type == null)
     {
         return(SpecialType.UnknownType);
     }
     if (type.IsGenericType && !type.IsGenericTypeDefinition)
     {
         ITypeReference   def        = ToTypeReference(type.GetGenericTypeDefinition());
         Type[]           arguments  = type.GetGenericArguments();
         ITypeReference[] args       = new ITypeReference[arguments.Length];
         bool             allUnbound = true;
         for (int i = 0; i < arguments.Length; i++)
         {
             args[i]     = ToTypeReference(arguments[i]);
             allUnbound &= args[i].Equals(SpecialType.UnboundTypeArgument);
         }
         if (allUnbound)
         {
             return(def);
         }
         else
         {
             return(new ParameterizedTypeReference(def, args));
         }
     }
     else if (type.IsArray)
     {
         return(new ArrayTypeReference(ToTypeReference(type.GetElementType()), type.GetArrayRank()));
     }
     else if (type.IsPointer)
     {
         return(new PointerTypeReference(ToTypeReference(type.GetElementType())));
     }
     else if (type.IsByRef)
     {
         return(new ByReferenceTypeReference(ToTypeReference(type.GetElementType())));
     }
     else if (type.IsGenericParameter)
     {
         if (type.DeclaringMethod != null)
         {
             return(TypeParameterReference.Create(SymbolKind.Method, type.GenericParameterPosition));
         }
         else
         {
             return(TypeParameterReference.Create(SymbolKind.TypeDefinition, type.GenericParameterPosition));
         }
     }
     else if (type.DeclaringType != null)
     {
         if (type == typeof(Dynamic))
         {
             return(SpecialType.Dynamic);
         }
         else if (type == typeof(NInt))
         {
             return(SpecialType.NInt);
         }
         else if (type == typeof(NUInt))
         {
             return(SpecialType.NUInt);
         }
         else if (type == typeof(Null))
         {
             return(SpecialType.NullType);
         }
         else if (type == typeof(UnboundTypeArgument))
         {
             return(SpecialType.UnboundTypeArgument);
         }
         ITypeReference baseTypeRef = ToTypeReference(type.DeclaringType);
         int            typeParameterCount;
         string         name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
         return(new NestedTypeReference(baseTypeRef, name, typeParameterCount));
     }
     else
     {
         IModuleReference assemblyReference = new DefaultAssemblyReference(type.Assembly.FullName);
         int    typeParameterCount;
         string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
         return(new GetClassTypeReference(assemblyReference, type.Namespace, name, typeParameterCount));
     }
 }
Ejemplo n.º 38
0
 public TypeExpression(ITypeReference t, Location l)
 {
     type = t;
     loc  = l;
 }
Ejemplo n.º 39
0
 internal PdbMetadataConstant(object value, ITypeReference type)
 {
     this.value = value;
     this.type  = type;
 }
Ejemplo n.º 40
0
 public SizeofExpression(ITypeReference measuredType)
 {
     this.MeasuredType = measuredType;
 }
Ejemplo n.º 41
0
 public ConvertExpression(IExpression operand, ConvertOperation operation, ITypeReference conversionType)
 {
     this.Operand        = operand;
     this.Operation      = operation;
     this.ConversionType = conversionType;
 }
Ejemplo n.º 42
0
 public CatchExpression(ITypeReference exceptionType)
 {
     this.ExceptionType = exceptionType;
 }
Ejemplo n.º 43
0
 void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
 {
     withoutSuffix = provider.Intern(withoutSuffix);
     withSuffix    = provider.Intern(withSuffix);
 }
Ejemplo n.º 44
0
        unsafe uint IMetaDataImport.GetTypeDefProps(uint td, IntPtr szTypeDef, uint cchTypeDef, out uint pchTypeDef, IntPtr pdwTypeDefFlags)
        {
            pchTypeDef = 0;
            if (td == 0)
            {
                return(0);
            }
            ITypeReference t = null;

            if ((td & 0xFF000000) == 0x1B000000)
            {
                t = this.writer.typeSpecList[(int)(td & 0xFFFFFF) - 1];
                IGenericTypeInstanceReference gt = t as IGenericTypeInstanceReference;
                if (gt != null)
                {
                    t = gt.GenericType;
                }
            }
            else
            {
                t = this.writer.typeDefList[(int)(td & 0xFFFFFF) - 1];
            }
            string tName;
            uint   parentToken = 0;

            if (this.lastTd == td)
            {
                tName       = this.lastTName;
                parentToken = this.lastParentToken;
            }
            else
            {
                tName          = TypeHelper.GetTypeName(t, NameFormattingOptions.UseGenericTypeNameSuffix | NameFormattingOptions.OmitContainingType);
                this.lastTd    = td;
                this.lastTName = tName;
                ITypeReference bc = null;
                foreach (ITypeReference baseClassRef in t.ResolvedType.BaseClasses)
                {
                    bc = baseClassRef;
                }
                if (bc != null)
                {
                    parentToken = (uint)this.writer.GetTypeToken(bc);
                }
                this.lastParentToken = parentToken;
            }
            pchTypeDef = (uint)tName.Length;
            if (pchTypeDef >= cchTypeDef)
            {
                pchTypeDef = cchTypeDef - 1;
            }
            char *pTypeDef = (char *)szTypeDef.ToPointer();

            for (int i = 0; i < pchTypeDef; i++)
            {
                *(pTypeDef + i) = tName[i];
            }
            *(pTypeDef + pchTypeDef) = (char)0;
            uint *pFlags = (uint *)pdwTypeDefFlags.ToPointer();

            *(pFlags) = PeWriter.GetTypeDefFlags(t.ResolvedType);
            return(parentToken);
        }
Ejemplo n.º 45
0
 protected override TypeSpecificationHandle GetOrAddTypeSpecificationHandle(ITypeReference reference)
 {
     return(MetadataTokens.TypeSpecificationHandle(_typeSpecIndex.GetOrAdd(reference)));
 }
Ejemplo n.º 46
0
        /// <summary>
        /// If a definition should be captured, capture it. Otherwise noop.
        ///
        /// The act of capturing means mapping the definition (or its type's interned id if the definition is a reference to THIS) to
        /// a new BoundField object that represents a field in the closure class.
        /// </summary>
        /// <param name="definition"></param>
        private void CaptureDefinition(object definition)
        {
            IThisReference /*?*/ thisRef = definition as IThisReference;

            if (thisRef != null)
            {
                definition = thisRef.Type.ResolvedType.InternedKey;
            }
            if (this.fieldForCapturedLocalOrParameter.ContainsKey(definition))
            {
                return;
            }

            IName /*?*/            name  = null;
            ITypeReference /*?*/   type  = null;
            ILocalDefinition /*?*/ local = definition as ILocalDefinition;
            var containingClass          = this.generatedclosureClass;

            if (local != null)
            {
                if (!this.localOrParameter2ClosureClass.TryGetValue(local, out containingClass))
                {
                    return;
                }
                if (false && containingClass == this.generatedclosureClass)
                {
                    // A use of a local is captured only if it is found in a *nested* closure,
                    // not the closure where the local is defined.
                    return;
                }
                name = local.Name;
                type = local.Type;
            }
            else
            {
                IParameterDefinition /*?*/ par = definition as IParameterDefinition;
                if (par != null)
                {
                    if (!this.localOrParameter2ClosureClass.TryGetValue(par, out containingClass))
                    {
                        return;
                    }
                    name = par.Name;
                    type = par.Type;
                }
                else
                {
                    if (definition is uint)
                    {
                        type = thisRef.Type;
                        name = this.nameTable.GetNameFor("__this value");
                    }
                    else
                    {
                        return;
                    }
                }
            }
            if (name == null)
            {
                return;
            }

            FieldDefinition field = new FieldDefinition()
            {
                ContainingTypeDefinition = containingClass,
                InternFactory            = this.host.InternFactory,
                Name       = name,
                Type       = this.copyTypeToClosure.Visit(type),
                Visibility = TypeMemberVisibility.Public
            };

            containingClass.Fields.Add(field);
            BoundField be = new BoundField(field, field.Type);

            this.fieldForCapturedLocalOrParameter.Add(definition, be);
        }
Ejemplo n.º 47
0
        private static IObjectFieldDescriptor UseFiltering(
            IObjectFieldDescriptor descriptor,
            Type?filterType,
            ITypeSystemMember?filterTypeInstance = null)
        {
            FieldMiddleware placeholder         = next => context => default;
            string          argumentPlaceholder =
                "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);

            descriptor
            .Use(placeholder)
            .Extend()
            .OnBeforeCreate((c, definition) =>
            {
                Type?argumentType = filterType;

                if (argumentType is null)
                {
                    if (definition.ResultType is null ||
                        definition.ResultType == typeof(object) ||
                        !c.TypeInspector.TryCreateTypeInfo(
                            definition.ResultType, out ITypeInfo? typeInfo))
                    {
                        throw new ArgumentException(
                            FilterResources.FilterObjectFieldDescriptor_InvalidType,
                            nameof(descriptor));
                    }

                    argumentType = typeof(FilterInputType <>)
                                   .MakeGenericType(typeInfo.NamedType);
                }

                ITypeReference argumentTypeReference = filterTypeInstance is null
                        ? (ITypeReference)c.TypeInspector.GetTypeRef(
                    argumentType,
                    TypeContext.Input)
                        : TypeReference.Create(filterTypeInstance);

                if (argumentType == typeof(object))
                {
                    throw new SchemaException(
                        SchemaErrorBuilder.New()
                        .SetMessage(
                            FilterResources.FilterObjectFieldDescriptor_InvalidType_Msg)
                        .SetCode(ErrorCodes.Filtering.FilterObjectType)
                        .Build());
                }

                var argumentDefinition = new ArgumentDefinition
                {
                    Name = argumentPlaceholder,
                    Type = c.TypeInspector.GetTypeRef(argumentType, TypeContext.Input)
                };

                argumentDefinition.ConfigureArgumentName();
                definition.Arguments.Add(argumentDefinition);

                ILazyTypeConfiguration lazyConfiguration =
                    LazyTypeConfigurationBuilder
                    .New <ObjectFieldDefinition>()
                    .Definition(definition)
                    .Configure((context, definition) =>
                               CompileMiddleware(
                                   context,
                                   definition,
                                   argumentTypeReference,
                                   placeholder))
                    .On(ApplyConfigurationOn.Completion)
                    .DependsOn(argumentTypeReference, true)
                    .Build();
                definition.Configurations.Add(lazyConfiguration);
            });

            return(descriptor);
        }
 public new static SortObjectOperationDescriptor New(
     IDescriptorContext context,
     NameString name,
     ITypeReference type,
     SortOperation operation) =>
 new SortObjectOperationDescriptor(context, name, type, operation);
Ejemplo n.º 49
0
 internal static UsedNamespaceOrType CreateType(ITypeReference type, string aliasOpt = null)
 {
     Debug.Assert(type != null);
     return(new UsedNamespaceOrType(alias: aliasOpt, targetType: type));
 }
Ejemplo n.º 50
0
        public static IObjectFieldDescriptor UseSorting(
            this IObjectFieldDescriptor descriptor,
            Type sortType,
            ITypeSystemMember sortTypeInstance = null)
        {
            FieldMiddleware placeholder =
                next => context => Task.CompletedTask;

            descriptor
            .Use(placeholder)
            .Extend()
            .OnBeforeCreate(definition =>
            {
                Type argumentType = GetArgumentType(definition, sortType);

                ITypeReference argumentTypeReference =
                    sortTypeInstance is null
                            ? (ITypeReference) new ClrTypeReference(
                        argumentType, TypeContext.Input)
                            : new SchemaTypeReference(sortTypeInstance);

                var argumentDefinition = new ArgumentDefinition
                {
                    Type = new ClrTypeReference(
                        argumentType, TypeContext.Input)
                };

                ILazyTypeConfiguration lazyArgumentConfiguration =
                    LazyTypeConfigurationBuilder
                    .New <ArgumentDefinition>()
                    .Definition(argumentDefinition)
                    .Configure((context, definition) =>
                {
                    ISortingNamingConvention convention =
                        context.DescriptorContext.GetSortingNamingConvention();
                    definition.Name = convention.ArgumentName;
                })
                    .On(ApplyConfigurationOn.Completion)
                    .Build();

                argumentDefinition.Configurations.Add(lazyArgumentConfiguration);
                definition.Arguments.Add(argumentDefinition);

                ILazyTypeConfiguration lazyConfiguration =
                    LazyTypeConfigurationBuilder
                    .New <ObjectFieldDefinition>()
                    .Definition(definition)
                    .Configure((context, definition) =>
                               CompileMiddleware(
                                   context,
                                   definition,
                                   argumentTypeReference,
                                   placeholder))
                    .On(ApplyConfigurationOn.Completion)
                    .DependsOn(argumentTypeReference, true)
                    .Build();
                definition.Configurations.Add(lazyConfiguration);
            });

            return(descriptor);
        }
Ejemplo n.º 51
0
 public ModuleType(string name, ITypeReference body)
     : base(name)
 {
     Body = body;
 }
Ejemplo n.º 52
0
 public static bool IsUnsafeType(this ITypeReference type)
 {
     return(type.TypeCode == PrimitiveTypeCode.Pointer);
 }
 public PInvokeMethodMetadataTraverser(ITypeReference skipTypeReference)
 {
     this.skipTypeReference = skipTypeReference;
 }
Ejemplo n.º 54
0
 // Token: 0x06001CC4 RID: 7364 RVA: 0x0009C21F File Offset: 0x0009A61F
 public TypeReference(ITypeReference typeReference)
 {
     this.assemblyQualifiedName = typeReference.assemblyQualifiedName;
 }
Ejemplo n.º 55
0
        public static IObjectFieldDescriptor UseSorting(
            this IObjectFieldDescriptor descriptor,
            Type?sortType,
            ITypeSystemMember?sortTypeInstance = null)
        {
            FieldMiddleware placeholder         = next => context => default;
            string          argumentPlaceholder =
                "_" + Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);

            descriptor
            .Use(placeholder)
            .Extend()
            .OnBeforeCreate((c, definition) =>
            {
                Type argumentType = GetArgumentType(definition, sortType, c.TypeInspector);

                ITypeReference argumentTypeReference = sortTypeInstance is null
                        ? (ITypeReference)c.TypeInspector.GetTypeRef(
                    argumentType,
                    TypeContext.Input)
                        : TypeReference.Create(sortTypeInstance);

                var argumentDefinition = new ArgumentDefinition
                {
                    Name = argumentPlaceholder,
                    Type = c.TypeInspector.GetTypeRef(argumentType, TypeContext.Input)
                };

                ILazyTypeConfiguration lazyArgumentConfiguration =
                    LazyTypeConfigurationBuilder
                    .New <ArgumentDefinition>()
                    .Definition(argumentDefinition)
                    .Configure((context, definition) =>
                {
                    ISortingNamingConvention convention =
                        context.DescriptorContext.GetSortingNamingConvention();
                    definition.Name = convention.ArgumentName;
                })
                    .On(ApplyConfigurationOn.Completion)
                    .Build();

                argumentDefinition.Configurations.Add(lazyArgumentConfiguration);
                definition.Arguments.Add(argumentDefinition);

                ILazyTypeConfiguration lazyConfiguration =
                    LazyTypeConfigurationBuilder
                    .New <ObjectFieldDefinition>()
                    .Definition(definition)
                    .Configure((context, definition) =>
                               CompileMiddleware(
                                   context,
                                   definition,
                                   argumentTypeReference,
                                   placeholder))
                    .On(ApplyConfigurationOn.Completion)
                    .DependsOn(argumentTypeReference, true)
                    .Build();
                definition.Configurations.Add(lazyConfiguration);
            });

            return(descriptor);
        }
Ejemplo n.º 56
0
        /// <summary>
        /// Use this routine, rather than ITypeReference.Dispatch, to call the appropriate derived overload of an ITypeReference.
        /// The former routine will call Visit(INamespaceTypeDefinition) rather than Visit(INamespaceTypeReference), etc.,
        /// in the case where a definition is used as a reference to itself.
        /// </summary>
        /// <param name="typeReference">A reference to a type definition. Note that a type definition can serve as a reference to itself.</param>
        protected void DispatchAsReference(ITypeReference typeReference)
        {
            INamespaceTypeReference namespaceTypeReference = typeReference.AsNamespaceTypeReference;

            if (namespaceTypeReference != null)
            {
                this.Visit(namespaceTypeReference);
                return;
            }

            IGenericTypeInstanceReference genericTypeInstanceReference = typeReference.AsGenericTypeInstanceReference;

            if (genericTypeInstanceReference != null)
            {
                this.Visit(genericTypeInstanceReference);
                return;
            }

            INestedTypeReference nestedTypeReference = typeReference.AsNestedTypeReference;

            if (nestedTypeReference != null)
            {
                this.Visit(nestedTypeReference);
                return;
            }

            IArrayTypeReference arrayTypeReference = typeReference as IArrayTypeReference;

            if (arrayTypeReference != null)
            {
                this.Visit(arrayTypeReference);
                return;
            }

            IGenericTypeParameterReference genericTypeParameterReference = typeReference.AsGenericTypeParameterReference;

            if (genericTypeParameterReference != null)
            {
                this.Visit(genericTypeParameterReference);
                return;
            }

            IGenericMethodParameterReference genericMethodParameterReference = typeReference.AsGenericMethodParameterReference;

            if (genericMethodParameterReference != null)
            {
                this.Visit(genericMethodParameterReference);
                return;
            }

            IPointerTypeReference pointerTypeReference = typeReference as IPointerTypeReference;

            if (pointerTypeReference != null)
            {
                this.Visit(pointerTypeReference);
                return;
            }

            IModifiedTypeReference modifiedTypeReference = typeReference as IModifiedTypeReference;

            if (modifiedTypeReference != null)
            {
                this.Visit(modifiedTypeReference);
                return;
            }
        }
Ejemplo n.º 57
0
 public override void ApplyInterningProvider(IInterningProvider provider)
 {
     base.ApplyInterningProvider(provider);
     returnType = provider.Intern(returnType);
     interfaceImplementations = provider.InternList(interfaceImplementations);
 }
Ejemplo n.º 58
0
 public static string GetCodeStringForType(ITypeReference typeReference)
 {
     return(typeReference.IsList ? "System.Collections.Generic.List<" + typeReference.GetEnumerableContentType().GetUnderlyingType() + ">" : typeReference.GetUnderlyingType().ToString());
 }
Ejemplo n.º 59
0
 public MetadataCreateArray(IArrayTypeReference arrayType, ITypeReference elementType, IMetadataExpression[] initializers)
 {
     ArrayType   = arrayType;
     ElementType = elementType;
     Elements    = initializers;
 }
Ejemplo n.º 60
0
 protected override void RecordTypeReference(ITypeReference typeReference)
 {
 }