コード例 #1
0
            public void CopyTo(DmdCustomAttributeData[] destination, ref int index, DmdMarshalType marshalType)
            {
                if (Count == 0)
                {
                    return;
                }
                int argsCount = 5;

                if (marshalType.MarshalType != null)
                {
                    argsCount++;
                }
                if ((object)marshalType.MarshalTypeRef != null)
                {
                    argsCount++;
                }
                if (marshalType.MarshalCookie != null)
                {
                    argsCount++;
                }
                if ((object)marshalType.SafeArrayUserDefinedSubType != null)
                {
                    argsCount++;
                }
                var type              = ctor.ReflectedType;
                var appDomain         = type.AppDomain;
                var unmanagedTypeType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_UnmanagedType, isOptional: false);
                var varEnumType       = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_VarEnum, isOptional: false);
                var namedArgs         = new DmdCustomAttributeNamedArgument[argsCount];
                int w = 0;

                namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("ArraySubType"), new DmdCustomAttributeTypedArgument(unmanagedTypeType, (int)marshalType.ArraySubType));
                namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("SizeParamIndex"), new DmdCustomAttributeTypedArgument(appDomain.System_Int16, marshalType.SizeParamIndex));
                namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("SizeConst"), new DmdCustomAttributeTypedArgument(appDomain.System_Int32, marshalType.SizeConst));
                namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("IidParameterIndex"), new DmdCustomAttributeTypedArgument(appDomain.System_Int32, marshalType.IidParameterIndex));
                namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("SafeArraySubType"), new DmdCustomAttributeTypedArgument(varEnumType, (int)marshalType.SafeArraySubType));
                if (marshalType.MarshalType != null)
                {
                    namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("MarshalType"), new DmdCustomAttributeTypedArgument(appDomain.System_String, marshalType.MarshalType));
                }
                if ((object)marshalType.MarshalTypeRef != null)
                {
                    namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("MarshalTypeRef"), new DmdCustomAttributeTypedArgument(appDomain.System_Type, marshalType.MarshalTypeRef));
                }
                if (marshalType.MarshalCookie != null)
                {
                    namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("MarshalCookie"), new DmdCustomAttributeTypedArgument(appDomain.System_String, marshalType.MarshalCookie));
                }
                if ((object)marshalType.SafeArrayUserDefinedSubType != null)
                {
                    namedArgs[w++] = new DmdCustomAttributeNamedArgument(type.GetField("SafeArrayUserDefinedSubType"), new DmdCustomAttributeTypedArgument(appDomain.System_Type, marshalType.SafeArrayUserDefinedSubType));
                }
                if (namedArgs.Length != w)
                {
                    throw new InvalidOperationException();
                }
                var ctorArgs = new[] { new DmdCustomAttributeTypedArgument(unmanagedTypeType, (int)marshalType.Value) };

                destination[index++] = new DmdCustomAttributeData(ctor, ctorArgs, namedArgs, isPseudoCustomAttribute: true);
            }
コード例 #2
0
            static DmdConstructorInfo Initialize(DmdAppDomain appDomain, DmdMarshalType marshalType)
            {
                if (marshalType == null)
                {
                    return(null);
                }
                var caType            = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_MarshalAsAttribute, isOptional: true);
                var unmanagedTypeType = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_UnmanagedType, isOptional: true);
                var varEnumType       = appDomain.GetWellKnownType(DmdWellKnownType.System_Runtime_InteropServices_VarEnum, isOptional: true);

                if ((object)caType == null || (object)unmanagedTypeType == null || (object)varEnumType == null)
                {
                    return(null);
                }
                var ctor = caType.GetConstructor(new[] { unmanagedTypeType });

                Debug.Assert((object)ctor != null);
                return(ctor);
            }
コード例 #3
0
 public MarshalAsAttributeInfo(DmdParameterInfo parameter, DmdMarshalType marshalType) => ctor = Initialize(parameter.Member.AppDomain, marshalType);
コード例 #4
0
 public MarshalAsAttributeInfo(DmdFieldInfo field, DmdMarshalType marshalType) => ctor         = Initialize(field.AppDomain, marshalType);