public CustomAttributeNamedArgument CreateNamedArgumentStruct(string name, Type type, object value, bool isField)
        {
            // Because C# doesn't like structs which contain object references to be referenced by pointers
            // we need to use a special MOSA compiler trick to get its address to create a pointer
            CustomAttributeNamedArgument namedArgument = new CustomAttributeNamedArgument();
            var ptr = (uint**)Intrinsic.GetValueTypeAddress(namedArgument);
            ptr[0] = (uint*)Intrinsic.GetObjectAddress(name);
            ptr[1] = (uint*)Intrinsic.GetObjectAddress(type);
            ptr[2] = (uint*)Intrinsic.GetObjectAddress(value);
            ptr[3] = (uint*)(isField ? 1 : 0);

            return namedArgument;
        }
        public CustomAttributeNamedArgument(System.Reflection.CustomAttributeNamedArgument arg)
        {
            if (arg.MemberInfo is FieldInfo)
            {
                this.ArgumentType = ((FieldInfo)arg.MemberInfo).FieldType.FullName;
                this.IsField      = true;
            }
            else
            {
                this.ArgumentType = ((PropertyInfo)arg.MemberInfo).PropertyType.FullName;
            }

            this.MemberName = arg.MemberInfo.Name;
            this.Value      = arg.TypedValue.Value.ToString();
        }
Пример #3
0
 private void Init(MarshalAsAttribute marshalAs)
 {
     Type type = typeof(MarshalAsAttribute);
     this.m_ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0];
     CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument(marshalAs.Value) };
     this.m_typedCtorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>(array);
     int num = 3;
     if (marshalAs.MarshalType != null)
     {
         num++;
     }
     if (marshalAs.MarshalTypeRef != null)
     {
         num++;
     }
     if (marshalAs.MarshalCookie != null)
     {
         num++;
     }
     num++;
     num++;
     if (marshalAs.SafeArrayUserDefinedSubType != null)
     {
         num++;
     }
     CustomAttributeNamedArgument[] argumentArray = new CustomAttributeNamedArgument[num];
     num = 0;
     argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("ArraySubType"), marshalAs.ArraySubType);
     argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("SizeParamIndex"), marshalAs.SizeParamIndex);
     argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("SizeConst"), marshalAs.SizeConst);
     argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("IidParameterIndex"), marshalAs.IidParameterIndex);
     argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("SafeArraySubType"), marshalAs.SafeArraySubType);
     if (marshalAs.MarshalType != null)
     {
         argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("MarshalType"), marshalAs.MarshalType);
     }
     if (marshalAs.MarshalTypeRef != null)
     {
         argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("MarshalTypeRef"), marshalAs.MarshalTypeRef);
     }
     if (marshalAs.MarshalCookie != null)
     {
         argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("MarshalCookie"), marshalAs.MarshalCookie);
     }
     if (marshalAs.SafeArrayUserDefinedSubType != null)
     {
         argumentArray[num++] = new CustomAttributeNamedArgument(type.GetField("SafeArrayUserDefinedSubType"), marshalAs.SafeArrayUserDefinedSubType);
     }
     this.m_namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>(argumentArray);
 }
Пример #4
0
 private void Init(DllImportAttribute dllImport)
 {
     Type type = typeof(DllImportAttribute);
     this.m_ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0];
     CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument(dllImport.Value) };
     this.m_typedCtorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>(array);
     CustomAttributeNamedArgument[] argumentArray2 = new CustomAttributeNamedArgument[] { new CustomAttributeNamedArgument(type.GetField("EntryPoint"), dllImport.EntryPoint), new CustomAttributeNamedArgument(type.GetField("CharSet"), dllImport.CharSet), new CustomAttributeNamedArgument(type.GetField("ExactSpelling"), dllImport.ExactSpelling), new CustomAttributeNamedArgument(type.GetField("SetLastError"), dllImport.SetLastError), new CustomAttributeNamedArgument(type.GetField("PreserveSig"), dllImport.PreserveSig), new CustomAttributeNamedArgument(type.GetField("CallingConvention"), dllImport.CallingConvention), new CustomAttributeNamedArgument(type.GetField("BestFitMapping"), dllImport.BestFitMapping), new CustomAttributeNamedArgument(type.GetField("ThrowOnUnmappableChar"), dllImport.ThrowOnUnmappableChar) };
     this.m_namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>(argumentArray2);
 }
 private void Init(TypeForwardedToAttribute forwardedTo)
 {
     Type type = typeof(TypeForwardedToAttribute);
     Type[] types = new Type[] { typeof(Type) };
     this.m_ctor = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, types, null);
     CustomAttributeTypedArgument[] array = new CustomAttributeTypedArgument[] { new CustomAttributeTypedArgument(typeof(Type), forwardedTo.Destination) };
     this.m_typedCtorArgs = Array.AsReadOnly<CustomAttributeTypedArgument>(array);
     CustomAttributeNamedArgument[] argumentArray2 = new CustomAttributeNamedArgument[0];
     this.m_namedArgs = Array.AsReadOnly<CustomAttributeNamedArgument>(argumentArray2);
 }
Пример #6
0
        private void Init(TypeForwardedToAttribute forwardedTo)
        {
            Type type = typeof(TypeForwardedToAttribute);

            Type[] sig = new Type[] { typeof(Type) };
            m_ctor = type.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null, sig, null);

            CustomAttributeTypedArgument[] typedArgs = new CustomAttributeTypedArgument[1];
            typedArgs[0] = new CustomAttributeTypedArgument(typeof(Type), forwardedTo.Destination);
            m_typedCtorArgs = Array.AsReadOnly(typedArgs);

            CustomAttributeNamedArgument[] namedArgs = new CustomAttributeNamedArgument[0];
            m_namedArgs = Array.AsReadOnly(namedArgs);
        }
Пример #7
0
        private void Init(MarshalAsAttribute marshalAs)
        {
            Type type = typeof(MarshalAsAttribute);
            m_ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0];
            m_typedCtorArgs = Array.AsReadOnly(new CustomAttributeTypedArgument[]
            {
                new CustomAttributeTypedArgument(marshalAs.Value),
            });

            int i = 3; // ArraySubType, SizeParamIndex, SizeConst
            if (marshalAs.MarshalType != null) i++;
            if (marshalAs.MarshalTypeRef != null) i++;
            if (marshalAs.MarshalCookie != null) i++;
            i++; // IidParameterIndex
            i++; // SafeArraySubType
            if (marshalAs.SafeArrayUserDefinedSubType != null) i++;
            CustomAttributeNamedArgument[] namedArgs = new CustomAttributeNamedArgument[i];

            // For compatibility with previous runtimes, we always include the following 5 attributes, regardless
            // of if they apply to the UnmanagedType being marshaled or not.
            i = 0;
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("ArraySubType"), marshalAs.ArraySubType);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SizeParamIndex"), marshalAs.SizeParamIndex);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SizeConst"), marshalAs.SizeConst);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("IidParameterIndex"), marshalAs.IidParameterIndex);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SafeArraySubType"), marshalAs.SafeArraySubType);
            if (marshalAs.MarshalType != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalType"), marshalAs.MarshalType);
            if (marshalAs.MarshalTypeRef != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalTypeRef"), marshalAs.MarshalTypeRef);
            if (marshalAs.MarshalCookie != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalCookie"), marshalAs.MarshalCookie);
            if (marshalAs.SafeArrayUserDefinedSubType != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SafeArrayUserDefinedSubType"), marshalAs.SafeArrayUserDefinedSubType);

            m_namedArgs = Array.AsReadOnly(namedArgs);
        }
Пример #8
0
        private CustomAttributeData GetDllImportAttributeData()
        {
            if ((Attributes & MethodAttributes.PinvokeImpl) == 0)
            {
                return(null);
            }

            string            entryPoint, dllName = null;
            PInvokeAttributes flags = 0;

            GetPInvoke(out flags, out entryPoint, out dllName);

            CharSet charSet = (flags & PInvokeAttributes.CharSetMask) switch
            {
                PInvokeAttributes.CharSetNotSpec => CharSet.None,
                PInvokeAttributes.CharSetAnsi => CharSet.Ansi,
                PInvokeAttributes.CharSetUnicode => CharSet.Unicode,
                PInvokeAttributes.CharSetAuto => CharSet.Auto,
                // Invalid: default to CharSet.None
                _ => CharSet.None,
            };

            InteropServicesCallingConvention callingConvention = (flags & PInvokeAttributes.CallConvMask) switch
            {
                PInvokeAttributes.CallConvWinapi => InteropServicesCallingConvention.Winapi,
                PInvokeAttributes.CallConvCdecl => InteropServicesCallingConvention.Cdecl,
                PInvokeAttributes.CallConvStdcall => InteropServicesCallingConvention.StdCall,
                PInvokeAttributes.CallConvThiscall => InteropServicesCallingConvention.ThisCall,
                PInvokeAttributes.CallConvFastcall => InteropServicesCallingConvention.FastCall,
                // Invalid: default to CallingConvention.Cdecl
                _ => InteropServicesCallingConvention.Cdecl,
            };

            bool exactSpelling         = (flags & PInvokeAttributes.NoMangle) != 0;
            bool setLastError          = (flags & PInvokeAttributes.SupportsLastError) != 0;
            bool bestFitMapping        = (flags & PInvokeAttributes.BestFitMask) == PInvokeAttributes.BestFitEnabled;
            bool throwOnUnmappableChar = (flags & PInvokeAttributes.ThrowOnUnmappableCharMask) == PInvokeAttributes.ThrowOnUnmappableCharEnabled;
            bool preserveSig           = (GetMethodImplementationFlags() & MethodImplAttributes.PreserveSig) != 0;

            var ctorArgs = new CustomAttributeTypedArgument[] {
                new CustomAttributeTypedArgument(typeof(string), dllName),
            };

            Type attrType = typeof(DllImportAttribute);

            var namedArgs = new CustomAttributeNamedArgument[] {
                new CustomAttributeNamedArgument(attrType.GetField("EntryPoint"), entryPoint),
                new CustomAttributeNamedArgument(attrType.GetField("CharSet"), charSet),
                new CustomAttributeNamedArgument(attrType.GetField("ExactSpelling"), exactSpelling),
                new CustomAttributeNamedArgument(attrType.GetField("SetLastError"), setLastError),
                new CustomAttributeNamedArgument(attrType.GetField("PreserveSig"), preserveSig),
                new CustomAttributeNamedArgument(attrType.GetField("CallingConvention"), callingConvention),
                new CustomAttributeNamedArgument(attrType.GetField("BestFitMapping"), bestFitMapping),
                new CustomAttributeNamedArgument(attrType.GetField("ThrowOnUnmappableChar"), throwOnUnmappableChar)
            };

            return(new CustomAttributeData(
                       attrType.GetConstructor(new[] { typeof(string) }),
                       ctorArgs,
                       namedArgs));
        }
Пример #9
0
        public static IList <System.Reflection.CustomAttributeData> ToList(List <CustomAttributeData> customAttributeDataList)
        {
            var returnList                 = new List <System.Reflection.CustomAttributeData>();
            var customAttributeType        = typeof(System.Reflection.CustomAttributeData);
            var customAttributeTypeName    = customAttributeType.FullName;
            var customAttributeConstructor = customAttributeType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(Attribute) }, null);
            var ctorArgsField              = customAttributeType.GetField("m_typedCtorArgs", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);
            var namedArgsField             = customAttributeType.GetField("m_namedArgs", BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic);

            Debug.Assert(customAttributeConstructor != null);
            DebugUtils.ThrowIf(customAttributeConstructor == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get constructor for type '{0}'", customAttributeTypeName)));

            DebugUtils.ThrowIf(ctorArgsField == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get field m_typedCtorArgs for type '{0}'", customAttributeTypeName)));
            DebugUtils.ThrowIf(namedArgsField == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get field m_namedArgs for type '{0}'", customAttributeTypeName)));

            foreach (var data in customAttributeDataList)
            {
                System.Reflection.CustomAttributeData attributeData;
                Attribute       attribute = null;
                ConstructorInfo constructor;
                var             attributeType = Type.GetType(data.AttributeType);
                var             parms         = new List <object>();
                var             types         = new List <Type>();
                var             ctorArgs      = new List <System.Reflection.CustomAttributeTypedArgument>();
                var             namedArgs     = new List <System.Reflection.CustomAttributeNamedArgument>();

                DebugUtils.ThrowIf(attributeType == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get type for '{0}'", data.AttributeType)));

                if (data.ConstructorArguments.Count > 0)
                {
                    foreach (var arg in data.ConstructorArguments)
                    {
                        var type = Type.GetType(arg.ArgumentType);

                        DebugUtils.ThrowIf(type == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get type for '{0}'", arg.ArgumentType)));

                        types.Add(type);
                    }

                    constructor = attributeType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, types.ToArray(), null);

                    DebugUtils.ThrowIf(constructor == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get constructor for '{0}'", attributeType.FullName)));

                    foreach (var arg in data.ConstructorArguments)
                    {
                        var type    = Type.GetType(arg.ArgumentType);
                        var value   = arg.Value.Convert(type);
                        var ctorArg = new System.Reflection.CustomAttributeTypedArgument(type, value);

                        ctorArgs.Add(ctorArg);
                        parms.Add(value);
                    }

                    attribute = (Attribute)constructor.Invoke(parms.ToArray());
                }
                else
                {
                    constructor = attributeType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, types.ToArray(), null);

                    DebugUtils.ThrowIf(constructor == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get constructor for '{0}'", attributeType.FullName)));

                    attribute = (Attribute)constructor.Invoke(parms.ToArray());
                }

                if (data.NamedArguments.Count > 0)
                {
                    types = new List <Type>();

                    foreach (var arg in data.NamedArguments)
                    {
                        var type  = Type.GetType(arg.ArgumentType);
                        var value = arg.Value.Convert(type);
                        System.Reflection.CustomAttributeNamedArgument namedArg;

                        if (arg.IsField)
                        {
                            var fieldInfo = attributeType.GetField(arg.MemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty);

                            DebugUtils.ThrowIf(fieldInfo == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get field '{0}' for '{0}'", arg.MemberName, attributeType.FullName)));
                            namedArg = new System.Reflection.CustomAttributeNamedArgument(fieldInfo, value);

                            fieldInfo.SetValue(attribute, value);
                        }
                        else
                        {
                            var propertyInfo = attributeType.GetProperty(arg.MemberName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetProperty);

                            DebugUtils.ThrowIf(propertyInfo == null, () => new NullReferenceException(string.Format("Utils.CustomAttributeData.ToList(System.Reflection.CustomAttributeData list) could not get property '{0}' for '{0}'", arg.MemberName, attributeType.FullName)));
                            namedArg = new System.Reflection.CustomAttributeNamedArgument(propertyInfo, value);

                            propertyInfo.GetSetMethod().Invoke(attribute, new object[] { value });
                        }

                        namedArgs.Add(namedArg);
                    }
                }

                attributeData = (System.Reflection.CustomAttributeData)customAttributeConstructor.Invoke(new object[] { attribute });

                ctorArgsField.SetValue(attributeData, ctorArgs);
                namedArgsField.SetValue(attributeData, namedArgs);

                returnList.Add(attributeData);
            }

            return(returnList);
        }
Пример #10
0
        private void Init(MarshalAsAttribute marshalAs)
        {
            Type type = typeof(MarshalAsAttribute);

            this.m_ctor          = type.GetConstructors(BindingFlags.Instance | BindingFlags.Public)[0];
            this.m_typedCtorArgs = (IList <CustomAttributeTypedArgument>)Array.AsReadOnly <CustomAttributeTypedArgument>(new CustomAttributeTypedArgument[1]
            {
                new CustomAttributeTypedArgument((object)marshalAs.Value)
            });
            int num1 = 3;

            if (marshalAs.MarshalType != null)
            {
                ++num1;
            }
            if (marshalAs.MarshalTypeRef != (Type)null)
            {
                ++num1;
            }
            if (marshalAs.MarshalCookie != null)
            {
                ++num1;
            }
            int length = num1 + 1 + 1;

            if (marshalAs.SafeArrayUserDefinedSubType != (Type)null)
            {
                ++length;
            }
            CustomAttributeNamedArgument[] array = new CustomAttributeNamedArgument[length];
            int num2 = 0;

            CustomAttributeNamedArgument[] attributeNamedArgumentArray1 = array;
            int index1 = num2;
            int num3   = 1;
            int num4   = index1 + num3;
            CustomAttributeNamedArgument attributeNamedArgument1 = new CustomAttributeNamedArgument((MemberInfo)type.GetField("ArraySubType"), (object)marshalAs.ArraySubType);

            attributeNamedArgumentArray1[index1] = attributeNamedArgument1;
            CustomAttributeNamedArgument[] attributeNamedArgumentArray2 = array;
            int index2 = num4;
            int num5   = 1;
            int num6   = index2 + num5;
            CustomAttributeNamedArgument attributeNamedArgument2 = new CustomAttributeNamedArgument((MemberInfo)type.GetField("SizeParamIndex"), (object)marshalAs.SizeParamIndex);

            attributeNamedArgumentArray2[index2] = attributeNamedArgument2;
            CustomAttributeNamedArgument[] attributeNamedArgumentArray3 = array;
            int index3 = num6;
            int num7   = 1;
            int num8   = index3 + num7;
            CustomAttributeNamedArgument attributeNamedArgument3 = new CustomAttributeNamedArgument((MemberInfo)type.GetField("SizeConst"), (object)marshalAs.SizeConst);

            attributeNamedArgumentArray3[index3] = attributeNamedArgument3;
            CustomAttributeNamedArgument[] attributeNamedArgumentArray4 = array;
            int index4 = num8;
            int num9   = 1;
            int num10  = index4 + num9;
            CustomAttributeNamedArgument attributeNamedArgument4 = new CustomAttributeNamedArgument((MemberInfo)type.GetField("IidParameterIndex"), (object)marshalAs.IidParameterIndex);

            attributeNamedArgumentArray4[index4] = attributeNamedArgument4;
            CustomAttributeNamedArgument[] attributeNamedArgumentArray5 = array;
            int index5 = num10;
            int num11  = 1;
            int num12  = index5 + num11;
            CustomAttributeNamedArgument attributeNamedArgument5 = new CustomAttributeNamedArgument((MemberInfo)type.GetField("SafeArraySubType"), (object)marshalAs.SafeArraySubType);

            attributeNamedArgumentArray5[index5] = attributeNamedArgument5;
            if (marshalAs.MarshalType != null)
            {
                array[num12++] = new CustomAttributeNamedArgument((MemberInfo)type.GetField("MarshalType"), (object)marshalAs.MarshalType);
            }
            if (marshalAs.MarshalTypeRef != (Type)null)
            {
                array[num12++] = new CustomAttributeNamedArgument((MemberInfo)type.GetField("MarshalTypeRef"), (object)marshalAs.MarshalTypeRef);
            }
            if (marshalAs.MarshalCookie != null)
            {
                array[num12++] = new CustomAttributeNamedArgument((MemberInfo)type.GetField("MarshalCookie"), (object)marshalAs.MarshalCookie);
            }
            if (marshalAs.SafeArrayUserDefinedSubType != (Type)null)
            {
                CustomAttributeNamedArgument[] attributeNamedArgumentArray6 = array;
                int index6 = num12;
                int num13  = 1;
                int num14  = index6 + num13;
                CustomAttributeNamedArgument attributeNamedArgument6 = new CustomAttributeNamedArgument((MemberInfo)type.GetField("SafeArrayUserDefinedSubType"), (object)marshalAs.SafeArrayUserDefinedSubType);
                attributeNamedArgumentArray6[index6] = attributeNamedArgument6;
            }
            this.m_namedArgs = (IList <CustomAttributeNamedArgument>)Array.AsReadOnly <CustomAttributeNamedArgument>(array);
        }
        private void Init(MarshalAsAttribute marshalAs)
        {
            Type type = typeof(MarshalAsAttribute);
            m_ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0];
            m_typedCtorArgs = Array.AsReadOnly(new CustomAttributeTypedArgument[]
            {
                new CustomAttributeTypedArgument(marshalAs.Value),
            });

            int i = 3; // ArraySubType, SizeParamIndex, SizeConst
            if (marshalAs.MarshalType != null) i++;
            if (marshalAs.MarshalTypeRef != null) i++;
            if (marshalAs.MarshalCookie != null) i++;
            CustomAttributeNamedArgument[] namedArgs = new CustomAttributeNamedArgument[i];

            i = 0;
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("ArraySubType"), marshalAs.ArraySubType);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SizeParamIndex"), marshalAs.SizeParamIndex);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SizeConst"), marshalAs.SizeConst);
            if (marshalAs.MarshalType != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalType"), marshalAs.MarshalType);
            if (marshalAs.MarshalTypeRef != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalTypeRef"), marshalAs.MarshalTypeRef);
            if (marshalAs.MarshalCookie != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalCookie"), marshalAs.MarshalCookie);

            m_namedArgs = Array.AsReadOnly(namedArgs);
        }
Пример #12
0
 private CommonNamedArgument GetCommonNamedArgument(CustomAttributeNamedArgument argument)
 {
     return new CommonNamedArgument(argument.MemberInfo.Name, GetCommonType(argument.TypedValue.ArgumentType), GetArgumentValue(argument.TypedValue));
 }
Пример #13
0
        private void Init(MarshalAsAttribute marshalAs)
        { 
            Type type = typeof(MarshalAsAttribute); 
            m_ctor = type.GetConstructors(BindingFlags.Public | BindingFlags.Instance)[0];
            m_typedCtorArgs = Array.AsReadOnly(new CustomAttributeTypedArgument[] 
            {
                new CustomAttributeTypedArgument(marshalAs.Value),
            });
 
            int i = 3; // ArraySubType, SizeParamIndex, SizeConst
            if (marshalAs.MarshalType != null) i++; 
            if (marshalAs.MarshalTypeRef != null) i++; 
            if (marshalAs.MarshalCookie != null) i++;
#if FEATURE_COMINTEROP 
            i++; // IidParameterIndex
            i++; // SafeArraySubType
            if (marshalAs.SafeArrayUserDefinedSubType != null) i++;
#endif // FEATURE_COMINTEROP 
            CustomAttributeNamedArgument[] namedArgs = new CustomAttributeNamedArgument[i];
 
            i = 0; 
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("ArraySubType"), marshalAs.ArraySubType);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SizeParamIndex"), marshalAs.SizeParamIndex); 
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SizeConst"), marshalAs.SizeConst);
#if FEATURE_COMINTEROP
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("IidParameterIndex"), marshalAs.IidParameterIndex);
            namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SafeArraySubType"), marshalAs.SafeArraySubType); 
#endif // FEATURE_COMINTEROP
            if (marshalAs.MarshalType != null) 
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalType"), marshalAs.MarshalType); 
            if (marshalAs.MarshalTypeRef != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalTypeRef"), marshalAs.MarshalTypeRef); 
            if (marshalAs.MarshalCookie != null)
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("MarshalCookie"), marshalAs.MarshalCookie);
#if FEATURE_COMINTEROP
            if (marshalAs.SafeArrayUserDefinedSubType != null) 
                namedArgs[i++] = new CustomAttributeNamedArgument(type.GetField("SafeArrayUserDefinedSubType"), marshalAs.SafeArrayUserDefinedSubType);
#endif // FEATURE_COMINTEROP 
 
            m_namedArgs = Array.AsReadOnly(namedArgs);
        } 
Пример #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="argument"></param>
 /// <returns></returns>
 public IMetadataNamedArgument GetExpression(CustomAttributeNamedArgument argument) {
   return new MetadataNamedArgumentWrapper(this, argument);
 }