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


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

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


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

示例1: GetMarshalAsAttribute

        private CustomAttributeBuilder GetMarshalAsAttribute(Cci.IMarshallingInformation marshallingInformation)
        {
            if (s_marshalAsCtor == null)
            {
                Type m = typeof(MarshalAsAttribute);
                s_marshalAsCtor = m.GetConstructor(new[] { typeof(UnmanagedType) });
                s_marshalArraySubType = m.GetField("ArraySubType");
                s_marshalIidParameterIndex = m.GetField("IidParameterIndex");
                s_marshalMarshalCookie = m.GetField("MarshalCookie");
                s_marshalMarshalType = m.GetField("MarshalType");
                s_marshalMarshalTypeRef = m.GetField("MarshalTypeRef");
                s_marshalSafeArraySubType = m.GetField("SafeArraySubType");
                s_marshalSafeArrayUserDefinedSubType = m.GetField("SafeArrayUserDefinedSubType");
                s_marshalSizeConst = m.GetField("SizeConst");
                s_marshalSizeParamIndex = m.GetField("SizeParamIndex");
            }

            FieldInfo[] fields = SpecializedCollections.EmptyArray<FieldInfo>();
            object[] values = SpecializedCollections.EmptyArray<object>();

            switch (marshallingInformation.UnmanagedType)
            {
                case UnmanagedType.ByValArray:
                    Debug.Assert(marshallingInformation.NumberOfElements >= 0);
                    if (marshallingInformation.ElementType >= 0)
                    {
                        fields = new[] { s_marshalSizeConst, s_marshalArraySubType };
                        values = new object[] { marshallingInformation.NumberOfElements, marshallingInformation.ElementType };
                    }
                    else
                    {
                        fields = new[] { s_marshalSizeConst };
                        values = new object[] { marshallingInformation.NumberOfElements };
                    }

                    break;

                case UnmanagedType.CustomMarshaler:
                    var marshaller = marshallingInformation.GetCustomMarshaller(_context);
                    var marshallerTypeRef = marshaller as Cci.ITypeReference;
                    if (marshallerTypeRef != null)
                    {
                        Type resolvedMarshaller = ResolveType(marshallerTypeRef);

                        fields = new[] { s_marshalMarshalTypeRef, s_marshalMarshalCookie };
                        values = new object[] { resolvedMarshaller, marshallingInformation.CustomMarshallerRuntimeArgument };
                    }
                    else
                    {
                        fields = new[] { s_marshalMarshalType, s_marshalMarshalCookie };
                        values = new object[] { marshaller, marshallingInformation.CustomMarshallerRuntimeArgument };
                    }

                    break;

                case UnmanagedType.LPArray:
                    var valueBuilder = ArrayBuilder<object>.GetInstance();
                    var fieldBuilder = ArrayBuilder<FieldInfo>.GetInstance();

                    fieldBuilder.Add(s_marshalArraySubType);
                    valueBuilder.Add(marshallingInformation.ElementType);

                    if (marshallingInformation.ParamIndex >= 0)
                    {
                        fieldBuilder.Add(s_marshalSizeParamIndex);
                        valueBuilder.Add(marshallingInformation.ParamIndex);
                    }

                    if (marshallingInformation.NumberOfElements >= 0)
                    {
                        fieldBuilder.Add(s_marshalSizeConst);
                        valueBuilder.Add(marshallingInformation.NumberOfElements);
                    }

                    fields = fieldBuilder.ToArrayAndFree();
                    values = valueBuilder.ToArrayAndFree();
                    break;

                case UnmanagedType.SafeArray:
                    if (marshallingInformation.SafeArrayElementSubtype >= 0)
                    {
                        var elementType = marshallingInformation.GetSafeArrayElementUserDefinedSubtype(_context);
                        if (elementType != null)
                        {
                            var resolvedType = ResolveType(elementType);

                            fields = new[] { s_marshalSafeArraySubType, s_marshalSafeArrayUserDefinedSubType };
                            values = new object[] { marshallingInformation.SafeArrayElementSubtype, resolvedType };
                        }
                        else
                        {
                            fields = new[] { s_marshalSafeArraySubType };
                            values = new object[] { marshallingInformation.SafeArrayElementSubtype };
                        }
                    }

                    break;

                case UnmanagedType.ByValTStr:
                    Debug.Assert(marshallingInformation.NumberOfElements >= 0);
//.........这里部分代码省略.........
开发者ID:furesoft,项目名称:roslyn,代码行数:101,代码来源:ReflectionEmitter.cs


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