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


C# Microsoft.Cci.GetType方法代码示例

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


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

示例1: ResolveField

        private FieldInfo ResolveField(Cci.IFieldReference fieldRef)
        {
            var fieldDef = fieldRef.GetResolvedField(_context);
            if (fieldDef != null && IsLocal(fieldRef.GetContainingType(_context)))
            {
                return _fieldBuilders[fieldDef];
            }

            FieldInfo result;
            if (_fieldRefs.TryGetValue(fieldRef, out result))
            {
                return result;
            }

            Type declaringType = ResolveType(fieldRef.GetContainingType(_context));
            Cci.ISpecializedFieldReference specializedRef = fieldRef.AsSpecializedFieldReference;

            if (specializedRef != null)
            {
                if (IsLocal(specializedRef.UnspecializedVersion.GetContainingType(_context)))
                {
                    // declaring type is TypeBuilder or TypeBuilderInstantiation since it's defined in the module being built:
                    FieldBuilder fieldBuilder = _fieldBuilders[(Cci.IFieldDefinition)specializedRef.UnspecializedVersion.AsDefinition(_context)];
                    result = TypeBuilder.GetField(declaringType, fieldBuilder);
                }
                else
                {
                    FieldInfo unspecializedDefinition = ResolveField(specializedRef.UnspecializedVersion);
                    result = new FieldRef(declaringType, fieldRef.Name, unspecializedDefinition.FieldType);
                }
            }
            else
            {
                GenericContext genericContext;
                if (declaringType.IsGenericTypeDefinition)
                {
                    genericContext = new GenericContext(declaringType.GetGenericArguments(), Type.EmptyTypes);
                }
                else
                {
                    genericContext = default(GenericContext);
                }

                // TODO: modifiers?
                Type fieldType = ResolveType(fieldRef.GetType(_context), genericContext);
                result = new FieldRef(declaringType, fieldRef.Name, fieldType);
            }

            _fieldRefs.Add(fieldRef, result);
            return result;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:51,代码来源:ReflectionEmitter.cs

示例2: MakeMethodParameters

        private void MakeMethodParameters(MethodBase method, Cci.IMethodReference methodRef, out Type[] methodGenericParameters, out ParameterInfo[] parameters, out ParameterInfo returnParameter)
        {
            Type declaringType = method.DeclaringType;

            if (methodRef.IsGeneric && methodRef.AsGenericMethodInstanceReference == null)
            {
                // generic definition
                methodGenericParameters = MakeGenericParameters((MethodInfo)method, methodRef);
            }
            else
            {
                methodGenericParameters = Type.EmptyTypes;
            }

            Type[] typeGenericParameters;
            if (declaringType.IsGenericTypeDefinition)
            {
                typeGenericParameters = declaringType.GetGenericArguments();
            }
            else
            {
                typeGenericParameters = Type.EmptyTypes;
            }

            GenericContext genericContext = methodGenericParameters.Length > 0 || typeGenericParameters.Length > 0 ?
                new GenericContext(typeGenericParameters, methodGenericParameters) : default(GenericContext);

            parameters = new ParameterInfo[methodRef.ParameterCount];
            int i = 0;
            foreach (var parameter in methodRef.GetParameters(_context))
            {
                parameters[i] = MakeParameterInfo(method, i + 1, parameter.GetType(_context), genericContext, parameter.CustomModifiers, parameter.IsByReference);
                i++;
            }

            returnParameter = MakeParameterInfo(method, 0, methodRef.GetType(_context), genericContext, methodRef.ReturnValueCustomModifiers, methodRef.ReturnValueIsByRef);
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:37,代码来源:ReflectionEmitter.cs

示例3: ResolveParameterType

        private Type ResolveParameterType(Cci.IParameterTypeInformation parameter, GenericContext genericContext = default(GenericContext))
        {
            var parameterType = ResolveType(parameter.GetType(_context), genericContext);

            if (parameter.IsByReference)
            {
                parameterType = parameterType.MakeByRefType();
            }

            if (parameter.CustomModifiers.Any())
            {
                Type[] reqMods, optMods;
                ResolveCustomModifiers(parameter.CustomModifiers, out reqMods, out optMods);
                return new ModifiedType(parameterType, reqMods, optMods);
            }
            else
            {
                return parameterType;
            }
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:20,代码来源:ReflectionEmitter.cs

示例4: DefineParameter

        private void DefineParameter(MethodBuilder methodBuilder, ConstructorBuilder constructorBuilder, Cci.IParameterDefinition paramDef)
        {
            // No explicit param row is needed if param has no flags (other than optionally IN),
            // no name and no references to the param row, such as CustomAttribute, Constant, or FieldMarshall
            var attributes = paramDef.GetAttributes(_context);
            var defaultValue = paramDef.GetDefaultValue(_context);

            if (defaultValue != null ||
                paramDef.IsOptional ||
                paramDef.IsOut ||
                paramDef.IsMarshalledExplicitly ||
                attributes.Any() ||
                paramDef.Name.Length > 0)
            {
                int index = paramDef is Cci.ReturnValueParameter ? 0 : paramDef.Index + 1;
                ParameterAttributes attrs = (ParameterAttributes)Cci.MetadataWriter.GetParameterFlags(paramDef);

                ParameterBuilder paramBuilder = (methodBuilder != null) ?
                    methodBuilder.DefineParameter(index, attrs, paramDef.Name) :
                    constructorBuilder.DefineParameter(index, attrs, paramDef.Name);

                if (defaultValue != null)
                {
                    object rawValue = defaultValue.Value;
                    if (rawValue == null)
                    {
                        var paramTypeRef = paramDef.GetType(_context);
                        if (paramTypeRef.IsValueType)
                        {
                            SetParameterDefaultStructValue(paramBuilder);
                        }
                        else
                        {
                            paramBuilder.SetConstant(null);
                        }
                    }
                    else
                    {
                        // TODO (tomat): Ref.Emit has too strict checks on the constant type. While it is ok to emit value,
                        // e.g. of type Int16 for parameter of type Int32 to metadata, Ref.Emit checks if these types are Type.IsAssignableFrom.
                        // To make this work we need to convert.
                        //
                        // We also need to support Nullable<T>.
                        if (rawValue.GetType().IsPrimitive)
                        {
                            // parameter type has already been resolved once when defining the method, so just retrive it:
                            Type paramType = ResolveType(paramDef.GetType(_context));

                            if (paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(Nullable<>))
                            {
                                paramType = paramType.GetGenericArguments()[0];
                            }

                            if (paramType.IsEnum)
                            {
                                // If emitting the enum, it isn't "created" as this stage so Enum.GetUnderlyingType() will throw
                                // Otherwise, if the enum is already defined, we should use Enum.GetUnderlyingType() to get the correct type
                                paramType = paramType is TypeBuilder ? paramType.UnderlyingSystemType : Enum.GetUnderlyingType(paramType);
                            }

                            rawValue = Convert.ChangeType(rawValue, paramType, System.Globalization.CultureInfo.InvariantCulture);
                        }

                        paramBuilder.SetConstant(rawValue);
                    }
                }

                if (paramDef.IsMarshalledExplicitly)
                {
                    // FieldMarshal
                    var marshallingInformation = paramDef.MarshallingInformation;

                    if (marshallingInformation != null)
                    {
                        paramBuilder.SetCustomAttribute(GetMarshalAsAttribute(marshallingInformation));
                    }
                    else
                    {
                        Debug.Assert(!paramDef.MarshallingDescriptor.IsDefaultOrEmpty);
                        // TODO:
                        throw new NotImplementedException();
                    }
                }

                EmitCustomAttributes(paramBuilder, attributes);
            }
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:87,代码来源:ReflectionEmitter.cs

示例5: GetReturnType

        private void GetReturnType(Cci.ISignature signature, out Type returnType, out Type[] reqMods, out Type[] optMods)
        {
            returnType = ResolveType(signature.GetType(_context));
            if (signature.ReturnValueIsByRef)
            {
                returnType = returnType.MakeByRefType();
            }

            // TODO (tomat, Dev12): this doesn't handle types constructed from modified types, we need Ref.Emit supporte for that:
            if (signature.ReturnValueCustomModifiers.Any())
            {
                ResolveCustomModifiers(signature.ReturnValueCustomModifiers, out reqMods, out optMods);
            }
            else
            {
                reqMods = optMods = null;
            }
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:18,代码来源:ReflectionEmitter.cs

示例6: DefineEvent

        private EventBuilder DefineEvent(TypeBuilder typeBuilder, Cci.IEventDefinition eventDef)
        {
            EventAttributes attrs = (EventAttributes)Cci.MetadataWriter.GetEventFlags(eventDef);
            Type type = ResolveType(eventDef.GetType(_context));

            // Event, EventMap
            var eventBuilder = typeBuilder.DefineEvent(eventDef.Name, attrs, type);

            // MethodSemantics
            foreach (var accessor in eventDef.Accessors)
            {
                var accessorDef = (Cci.IMethodDefinition)accessor.AsDefinition(_context);
                var accessorBuilder = _methodBuilders[accessorDef];

                if (accessor == eventDef.Adder)
                {
                    eventBuilder.SetAddOnMethod(accessorBuilder);
                }
                else if (accessor == eventDef.Remover)
                {
                    eventBuilder.SetRemoveOnMethod(accessorBuilder);
                }
                else if (accessor == eventDef.Caller)
                {
                    eventBuilder.SetRaiseMethod(accessorBuilder);
                }
                else
                {
                    eventBuilder.AddOtherMethod(accessorBuilder);
                }
            }

            return eventBuilder;
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:34,代码来源:ReflectionEmitter.cs

示例7: DefineField

        private void DefineField(TypeBuilder typeBuilder, Cci.IFieldDefinition fieldDef)
        {
            FieldAttributes attrs = (FieldAttributes)Cci.MetadataWriter.GetFieldFlags(fieldDef);
            FieldBuilder fieldBuilder;

            if (!fieldDef.MappedData.IsDefault)
            {
                // TODO (tomat, Dev12): Unfortunately, Reflection.Emit doesn't allow us to directly set FieldRVA on arbitrary FieldBuilder.
                // Instead it creates the mapping types itself and provides APIs to define mapped fields.
                // So we use that API and ignore the mapping types provided by the compiler.

                // FieldRVA
                fieldBuilder = typeBuilder.DefineInitializedData(fieldDef.Name, fieldDef.MappedData.ToArray(), attrs);
            }
            else
            {
                // Field types that are value types need to be loaded before the declaring type.
                // If the field type is a nested type, e.g. A.B.C only the inner-most type needs to be loaded before the declaring type.
                Type type = ResolveType(
                    fieldDef.GetType(_context),
                    genericContext: default(GenericContext),
                    dependentType: typeBuilder,
                    valueTypeDependency: true);

                // TODO (tomat, Dev12): this doesn't handle types constructed from modified types, we need Ref.Emit support for that:
                Type[] reqMods = null, optMods = null;
                ModifiedType modified = type as ModifiedType;
                if (modified != null)
                {
                    reqMods = modified.RequiredModifiers;
                    optMods = modified.OptionalModifiers;
                    type = modified.UnmodifiedType;
                }

                fieldBuilder = typeBuilder.DefineField(fieldDef.Name, type, reqMods, optMods, attrs);
            }

            // FieldLayout
            if (fieldDef.ContainingTypeDefinition.Layout == LayoutKind.Explicit && !fieldDef.IsStatic)
            {
                fieldBuilder.SetOffset((int)fieldDef.Offset);
            }

            // FieldMarshal
            if (fieldDef.IsMarshalledExplicitly)
            {
                var marshallingInformation = fieldDef.MarshallingInformation;

                if (marshallingInformation != null)
                {
                    fieldBuilder.SetCustomAttribute(GetMarshalAsAttribute(marshallingInformation));
                }
                else
                {
                    Debug.Assert(!fieldDef.MarshallingDescriptor.IsDefaultOrEmpty);
                    // TODO:
                    throw new NotImplementedException();
                }
            }

            _fieldBuilders.Add(fieldDef, fieldBuilder);
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:62,代码来源:ReflectionEmitter.cs

示例8: ReturnTypeMatches

        private bool ReturnTypeMatches(Cci.IMethodReference methodRef, MethodBase method, GenericContext genericContext)
        {
            MethodInfo methodInfo = method as MethodInfo;
            if (methodInfo == null)
            {
                return true;
            }

            return methodInfo.ReturnType.IsEquivalentTo(ResolveType(methodRef.GetType(_context), genericContext));
        }
开发者ID:furesoft,项目名称:roslyn,代码行数:10,代码来源:ReflectionEmitter.cs

示例9: ResolveCCIType

 private static CCI.TypeNode ResolveCCIType(CCI.AssemblyNode assembly, string ns, string nm)
 {
     var n = assembly.GetType(CCI.Identifier.For(ns), CCI.Identifier.For(nm));
     if (n == null)
         throw new InvalidOperationException("unable to load well-known type");
     return n;
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:7,代码来源:CCILoader.cs


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