internal static bool IsDefined(RuntimeType type, RuntimeType caType, bool inherit)
 {
     if (type.GetElementType() != null)
     {
         return(false);
     }
     if (PseudoCustomAttribute.IsDefined(type, caType))
     {
         return(true);
     }
     if (CustomAttribute.IsCustomAttributeDefined(type.GetRuntimeModule(), type.MetadataToken, caType))
     {
         return(true);
     }
     if (!inherit)
     {
         return(false);
     }
     type = (type.BaseType as RuntimeType);
     while (type != null)
     {
         if (CustomAttribute.IsCustomAttributeDefined(type.GetRuntimeModule(), type.MetadataToken, caType, 0, inherit))
         {
             return(true);
         }
         type = (type.BaseType as RuntimeType);
     }
     return(false);
 }
Ejemplo n.º 2
0
        private static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType)
        {
            int num1 = (int)CustomAttributeData.TypeToCustomAttributeEncoding(parameterType);
            CustomAttributeEncoding attributeEncoding1 = CustomAttributeEncoding.Undefined;
            CustomAttributeEncoding attributeEncoding2 = CustomAttributeEncoding.Undefined;
            string str  = (string)null;
            int    num2 = 29;

            if (num1 == num2)
            {
                parameterType      = (RuntimeType)parameterType.GetElementType();
                attributeEncoding1 = CustomAttributeData.TypeToCustomAttributeEncoding(parameterType);
            }
            int num3 = 85;

            if (num1 == num3 || attributeEncoding1 == CustomAttributeEncoding.Enum)
            {
                attributeEncoding2 = CustomAttributeData.TypeToCustomAttributeEncoding((RuntimeType)Enum.GetUnderlyingType((Type)parameterType));
                str = parameterType.AssemblyQualifiedName;
            }
            int    num4     = (int)attributeEncoding1;
            int    num5     = (int)attributeEncoding2;
            string enumName = str;

            return(new CustomAttributeType((CustomAttributeEncoding)num1, (CustomAttributeEncoding)num4, (CustomAttributeEncoding)num5, enumName));
        }
 internal static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
 {
     if (type.GetElementType() != null)
     {
         if (!caType.IsValueType)
         {
             return(CustomAttribute.CreateAttributeArrayHelper(caType, 0));
         }
         return(EmptyArray <object> .Value);
     }
     else
     {
         if (type.IsGenericType && !type.IsGenericTypeDefinition)
         {
             type = (type.GetGenericTypeDefinition() as RuntimeType);
         }
         int         i = 0;
         Attribute[] customAttributes = PseudoCustomAttribute.GetCustomAttributes(type, caType, true, out i);
         if (!inherit || (caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited))
         {
             object[] customAttributes2 = CustomAttribute.GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, i, caType, !CustomAttribute.AllowCriticalCustomAttributes(type));
             if (i > 0)
             {
                 Array.Copy(customAttributes, 0, customAttributes2, customAttributes2.Length - i, i);
             }
             return(customAttributes2);
         }
         List <object> list = new List <object>();
         bool          mustBeInheritable = false;
         Type          elementType       = (caType == null || caType.IsValueType || caType.ContainsGenericParameters) ? typeof(object) : caType;
         while (i > 0)
         {
             list.Add(customAttributes[--i]);
         }
         while (type != (RuntimeType)typeof(object) && type != null)
         {
             object[] customAttributes3 = CustomAttribute.GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, 0, caType, mustBeInheritable, list, !CustomAttribute.AllowCriticalCustomAttributes(type));
             mustBeInheritable = true;
             for (int j = 0; j < customAttributes3.Length; j++)
             {
                 list.Add(customAttributes3[j]);
             }
             type = (type.BaseType as RuntimeType);
         }
         object[] array = CustomAttribute.CreateAttributeArrayHelper(elementType, list.Count);
         Array.Copy(list.ToArray(), 0, array, 0, list.Count);
         return(array);
     }
 }
        internal static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
        {
            if (type.GetElementType() != null)
            {
                if (!caType.IsValueType)
                {
                    return(CreateAttributeArrayHelper(caType, 0));
                }
                return(new object[0]);
            }
            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                type = type.GetGenericTypeDefinition() as RuntimeType;
            }
            int count = 0;

            Attribute[] sourceArray = PseudoCustomAttribute.GetCustomAttributes(type, caType, true, out count);
            if (!inherit || (caType.IsSealed && !GetAttributeUsage(caType).Inherited))
            {
                object[] objArray = GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, count, caType, !AllowCriticalCustomAttributes(type));
                if (count > 0)
                {
                    Array.Copy(sourceArray, 0, objArray, objArray.Length - count, count);
                }
                return(objArray);
            }
            List <object> derivedAttributes = new List <object>();
            bool          mustBeInheritable = false;
            Type          elementType       = (((caType == null) || caType.IsValueType) || caType.ContainsGenericParameters) ? typeof(object) : caType;

            while (count > 0)
            {
                derivedAttributes.Add(sourceArray[--count]);
            }
            while ((type != ((RuntimeType)typeof(object))) && (type != null))
            {
                object[] objArray2 = GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, 0, caType, mustBeInheritable, derivedAttributes, !AllowCriticalCustomAttributes(type));
                mustBeInheritable = true;
                for (int i = 0; i < objArray2.Length; i++)
                {
                    derivedAttributes.Add(objArray2[i]);
                }
                type = type.BaseType as RuntimeType;
            }
            object[] destinationArray = CreateAttributeArrayHelper(elementType, derivedAttributes.Count);
            Array.Copy(derivedAttributes.ToArray(), 0, destinationArray, 0, derivedAttributes.Count);
            return(destinationArray);
        }
Ejemplo n.º 5
0
        internal static object[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool inherit)
        {
            if (type.GetElementType() != (Type)null)
            {
                if (!caType.IsValueType)
                {
                    return(CustomAttribute.CreateAttributeArrayHelper((Type)caType, 0));
                }
                return(EmptyArray <object> .Value);
            }
            if (type.IsGenericType && !type.IsGenericTypeDefinition)
            {
                type = type.GetGenericTypeDefinition() as RuntimeType;
            }
            int count = 0;

            Attribute[] customAttributes1 = PseudoCustomAttribute.GetCustomAttributes(type, caType, true, out count);
            if (!inherit || caType.IsSealed && !CustomAttribute.GetAttributeUsage(caType).Inherited)
            {
                object[] customAttributes2 = CustomAttribute.GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, count, caType, !CustomAttribute.AllowCriticalCustomAttributes(type));
                if (count > 0)
                {
                    Array.Copy((Array)customAttributes1, 0, (Array)customAttributes2, customAttributes2.Length - count, count);
                }
                return(customAttributes2);
            }
            List <object> objectList        = new List <object>();
            bool          mustBeInheritable = false;
            Type          elementType       = (caType == (RuntimeType)null || caType.IsValueType ? 1 : (caType.ContainsGenericParameters ? 1 : 0)) != 0 ? typeof(object) : (Type)caType;

            while (count > 0)
            {
                objectList.Add((object)customAttributes1[--count]);
            }
            for (; type != (RuntimeType)typeof(object) && type != (RuntimeType)null; type = type.BaseType as RuntimeType)
            {
                object[] customAttributes2 = CustomAttribute.GetCustomAttributes(type.GetRuntimeModule(), type.MetadataToken, 0, caType, mustBeInheritable, (IList)objectList, !CustomAttribute.AllowCriticalCustomAttributes(type));
                mustBeInheritable = true;
                for (int index = 0; index < customAttributes2.Length; ++index)
                {
                    objectList.Add(customAttributes2[index]);
                }
            }
            object[] attributeArrayHelper = CustomAttribute.CreateAttributeArrayHelper(elementType, objectList.Count);
            Array.Copy((Array)objectList.ToArray(), 0, (Array)attributeArrayHelper, 0, objectList.Count);
            return(attributeArrayHelper);
        }
Ejemplo n.º 6
0
        // Token: 0x06004416 RID: 17430 RVA: 0x000F97C4 File Offset: 0x000F79C4
        private static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType)
        {
            CustomAttributeEncoding customAttributeEncoding  = CustomAttributeData.TypeToCustomAttributeEncoding(parameterType);
            CustomAttributeEncoding customAttributeEncoding2 = CustomAttributeEncoding.Undefined;
            CustomAttributeEncoding encodedEnumType          = CustomAttributeEncoding.Undefined;
            string enumName = null;

            if (customAttributeEncoding == CustomAttributeEncoding.Array)
            {
                parameterType            = (RuntimeType)parameterType.GetElementType();
                customAttributeEncoding2 = CustomAttributeData.TypeToCustomAttributeEncoding(parameterType);
            }
            if (customAttributeEncoding == CustomAttributeEncoding.Enum || customAttributeEncoding2 == CustomAttributeEncoding.Enum)
            {
                encodedEnumType = CustomAttributeData.TypeToCustomAttributeEncoding((RuntimeType)Enum.GetUnderlyingType(parameterType));
                enumName        = parameterType.AssemblyQualifiedName;
            }
            return(new CustomAttributeType(customAttributeEncoding, customAttributeEncoding2, encodedEnumType, enumName));
        }
Ejemplo n.º 7
0
        private static CustomAttributeType InitCustomAttributeType(RuntimeType parameterType)
        {
            CustomAttributeEncoding encodedType     = TypeToCustomAttributeEncoding(parameterType);
            CustomAttributeEncoding undefined       = CustomAttributeEncoding.Undefined;
            CustomAttributeEncoding encodedEnumType = CustomAttributeEncoding.Undefined;
            string enumName = null;

            if (encodedType == CustomAttributeEncoding.Array)
            {
                parameterType = (RuntimeType)parameterType.GetElementType();
                undefined     = TypeToCustomAttributeEncoding(parameterType);
            }
            if ((encodedType == CustomAttributeEncoding.Enum) || (undefined == CustomAttributeEncoding.Enum))
            {
                encodedEnumType = TypeToCustomAttributeEncoding((RuntimeType)Enum.GetUnderlyingType(parameterType));
                enumName        = parameterType.AssemblyQualifiedName;
            }
            return(new CustomAttributeType(encodedType, undefined, encodedEnumType, enumName));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 生成。
        /// </summary>
        /// <param name="ilg">指令。</param>
        public override void Load(ILGenerator ilg)
        {
            body.Load(ilg);

            Type typeFrom = body.RuntimeType;

            if (typeFrom == RuntimeType)
            {
                return;
            }

            if (RuntimeType == typeof(void))
            {
                ilg.Emit(OpCodes.Pop);

                return;
            }

            EmitUtils.EmitConvertToType(ilg, typeFrom, RuntimeType.IsByRef ? RuntimeType.GetElementType() : RuntimeType, true);
        }
Ejemplo n.º 9
0
        protected void InitializeContentDefinition(ICustomAttributeProvider sourceInfo)
        {
            var elementAttribute   = sourceInfo.GetSingleAttribute <XmlElementAttribute>();
            var arrayAttribute     = sourceInfo.GetSingleAttribute <XmlArrayAttribute>();
            var arrayItemAttribute = sourceInfo.GetSingleAttribute <XmlArrayItemAttribute>();

            if (elementAttribute != null && (arrayAttribute != null || arrayItemAttribute != null))
            {
                throw new Exception($"Property `{this}` should not define XmlElement and XmlArray(Item) attributes at the same time.");
            }

            var runtimeName = RuntimeName;

            XName qualifiedName     = null;
            XName itemQualifiedName = null;

            if (RuntimeType.IsArray)
            {
                if (RuntimeType.GetArrayRank() > 1)
                {
                    throw new Exception($"Property `{this}` declares multi-dimensional array, which is not supported.");
                }

                var localName     = (arrayAttribute?.ElementName).GetValueOrDefault(runtimeName);
                var containerName = string.IsNullOrWhiteSpace(localName) ? null : XName.Get(localName, arrayAttribute?.Namespace ?? "");

                if (elementAttribute != null)
                {
                    itemQualifiedName = XName.Get(elementAttribute.ElementName.GetValueOrDefault(runtimeName), elementAttribute.Namespace ?? "");
                }
                else if (arrayItemAttribute != null)
                {
                    qualifiedName     = containerName;
                    itemQualifiedName = XName.Get(arrayItemAttribute.ElementName.GetValueOrDefault(runtimeName), arrayItemAttribute.Namespace ?? "");
                }
                else
                {
                    qualifiedName     = containerName;
                    itemQualifiedName = XName.Get("item", "");
                }
            }
            else
            {
                if (arrayAttribute != null || arrayItemAttribute != null)
                {
                    throw new Exception($"Property `{this}` should not define XmlArray(Item) attribute, because it's not array type.");
                }
                var name = (elementAttribute?.ElementName).GetValueOrDefault(runtimeName);
                qualifiedName = string.IsNullOrWhiteSpace(name) ? null : XName.Get(name, elementAttribute?.Namespace ?? "");
            }

            var customTypeName = (elementAttribute?.DataType).GetValueOrDefault(arrayItemAttribute?.DataType);

            Name       = qualifiedName;
            IsNullable = (elementAttribute?.IsNullable).GetValueOrDefault() || (arrayAttribute?.IsNullable).GetValueOrDefault();
            Order      = (elementAttribute?.Order).GetValueOrDefault((arrayAttribute?.Order).GetValueOrDefault());
            UseXop     = typeof(Stream).GetTypeInfo().IsAssignableFrom(RuntimeType);
            TypeName   = customTypeName != null?XName.Get(customTypeName, NamespaceConstants.XSD) : null;

            IsOptional    = sourceInfo.GetSingleAttribute <XRoadOptionalAttribute>() != null;
            State         = DefinitionState.Default;
            Documentation = sourceInfo.GetXRoadTitles().Where(title => !string.IsNullOrWhiteSpace(title.Item2)).ToArray();
            MergeContent  = sourceInfo.GetSingleAttribute <XRoadMergeContentAttribute>() != null || sourceInfo.GetSingleAttribute <XmlTextAttribute>() != null;

            if (!RuntimeType.IsArray)
            {
                return;
            }

            MergeContent = MergeContent || elementAttribute != null;

            ArrayItemDefinition = new ArrayItemDefinition(this)
            {
                Name        = itemQualifiedName,
                IsNullable  = (arrayItemAttribute?.IsNullable).GetValueOrDefault(),
                IsOptional  = elementAttribute != null && IsOptional,
                UseXop      = typeof(Stream).GetTypeInfo().IsAssignableFrom(RuntimeType.GetElementType()),
                RuntimeType = RuntimeType.GetElementType(),
            };
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 发行。
        /// </summary>
        /// <param name="ilg">指令。</param>
        public override void Load(ILGenerator ilg)
        {
            switch (Position)
            {
            case 0:
                ilg.Emit(OpCodes.Ldarg_0);
                break;

            case 1:
                ilg.Emit(OpCodes.Ldarg_1);
                break;

            case 2:
                ilg.Emit(OpCodes.Ldarg_2);
                break;

            case 3:
                ilg.Emit(OpCodes.Ldarg_3);
                break;

            default:
                if (Position < byte.MaxValue)
                {
                    ilg.Emit(OpCodes.Ldarg_S, (byte)Position);

                    break;
                }

                ilg.Emit(OpCodes.Ldarg, Position);
                break;
            }

            if (IsByRef)
            {
                var type = RuntimeType.GetElementType();

                if (type.IsValueType && type.IsEnum)
                {
                    type = Enum.GetUnderlyingType(type);
                }

                if (type.IsPrimitive && type != typeof(IntPtr) && type != typeof(UIntPtr))
                {
                    switch (Type.GetTypeCode(type))
                    {
                    case TypeCode.Boolean:
                    case TypeCode.Byte:
                    case TypeCode.SByte:
                        ilg.Emit(OpCodes.Ldind_I1);
                        break;

                    case TypeCode.Char:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                        ilg.Emit(OpCodes.Ldind_I2);
                        break;

                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                        ilg.Emit(OpCodes.Ldind_I4);
                        break;

                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                        ilg.Emit(OpCodes.Ldind_I8);
                        break;

                    case TypeCode.Single:
                        ilg.Emit(OpCodes.Ldind_R4);
                        break;

                    case TypeCode.Double:
                        ilg.Emit(OpCodes.Ldind_R8);
                        break;

                    case TypeCode.Empty:
                    case TypeCode.DBNull:
                    case TypeCode.Decimal:
                    case TypeCode.DateTime:
                    case TypeCode.String:
                    case TypeCode.Object:
                    default:
                        if (type.IsValueType)
                        {
                            ilg.Emit(OpCodes.Ldobj, type);
                        }
                        else
                        {
                            ilg.Emit(OpCodes.Ldind_Ref);
                        }
                        break;
                    }
                }
                else if (type.IsValueType || type.IsGenericParameter)
                {
                    ilg.Emit(OpCodes.Ldobj, type);
                }
                else
                {
                    ilg.Emit(OpCodes.Ldind_Ref);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 加载数据。
        /// </summary>
        /// <param name="ilg">指令。</param>
        public override void Load(ILGenerator ilg)
        {
            methodAst.Load(ilg);

            if (instanceAst is null)
            {
                ilg.Emit(OpCodes.Ldnull);
            }
            else
            {
                instanceAst.Load(ilg);
            }

            arguments.Load(ilg);

            ilg.Emit(OpCodes.Callvirt, InvokeMethod);

            if (RuntimeType != typeof(object))
            {
                if (RuntimeType == typeof(void))
                {
                    ilg.Emit(OpCodes.Pop);
                }
                else
                {
                    EmitUtils.EmitConvertToType(ilg, typeof(object), RuntimeType.IsByRef ? RuntimeType.GetElementType() : RuntimeType, true);
                }
            }
        }
Ejemplo n.º 12
0
        internal static Attribute[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool includeSecCa, out int count)
        {
            count = 0;
            bool flag = caType == (RuntimeType)typeof(object) || caType == (RuntimeType)typeof(Attribute);

            if (!flag && PseudoCustomAttribute.s_pca.GetValueOrDefault(caType) == null && !PseudoCustomAttribute.IsSecurityAttribute(caType))
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();

            if (flag || caType == (RuntimeType)typeof(SerializableAttribute))
            {
                Attribute customAttribute = SerializableAttribute.GetCustomAttribute(type);
                if (customAttribute != null)
                {
                    list.Add(customAttribute);
                }
            }
            if (flag || caType == (RuntimeType)typeof(ComImportAttribute))
            {
                Attribute customAttribute = ComImportAttribute.GetCustomAttribute(type);
                if (customAttribute != null)
                {
                    list.Add(customAttribute);
                }
            }
            if (includeSecCa && (flag || PseudoCustomAttribute.IsSecurityAttribute(caType)) && !type.IsGenericParameter && type.GetElementType() == null)
            {
                if (type.IsGenericType)
                {
                    type = (RuntimeType)type.GetGenericTypeDefinition();
                }
                object[] array;
                PseudoCustomAttribute.GetSecurityAttributes(type.Module.ModuleHandle.GetRuntimeModule(), type.MetadataToken, false, out array);
                if (array != null)
                {
                    foreach (object obj in array)
                    {
                        if (caType == obj.GetType() || obj.GetType().IsSubclassOf(caType))
                        {
                            list.Add((Attribute)obj);
                        }
                    }
                }
            }
            count = list.Count;
            return(list.ToArray());
        }
Ejemplo n.º 13
0
        internal static Attribute[] GetCustomAttributes(RuntimeType type, RuntimeType caType, bool includeSecCa, out int count)
        {
            count = 0;
            bool flag = (caType == ((RuntimeType)typeof(object))) || (caType == ((RuntimeType)typeof(Attribute)));

            if ((!flag && (s_pca.GetValueOrDefault(caType) == null)) && !IsSecurityAttribute(caType))
            {
                return(new Attribute[0]);
            }
            List <Attribute> list = new List <Attribute>();
            Attribute        item = null;

            if (flag || (caType == ((RuntimeType)typeof(SerializableAttribute))))
            {
                item = SerializableAttribute.GetCustomAttribute(type);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            if (flag || (caType == ((RuntimeType)typeof(ComImportAttribute))))
            {
                item = ComImportAttribute.GetCustomAttribute(type);
                if (item != null)
                {
                    list.Add(item);
                }
            }
            if ((includeSecCa && (flag || IsSecurityAttribute(caType))) && (!type.IsGenericParameter && (type.GetElementType() == null)))
            {
                object[] objArray;
                if (type.IsGenericType)
                {
                    type = (RuntimeType)type.GetGenericTypeDefinition();
                }
                GetSecurityAttributes(type.Module.ModuleHandle.GetRuntimeModule(), type.MetadataToken, false, out objArray);
                if (objArray != null)
                {
                    foreach (object obj2 in objArray)
                    {
                        if ((caType == obj2.GetType()) || obj2.GetType().IsSubclassOf(caType))
                        {
                            list.Add((Attribute)obj2);
                        }
                    }
                }
            }
            count = list.Count;
            return(list.ToArray());
        }