Exemplo n.º 1
0
        // Token: 0x06001277 RID: 4727 RVA: 0x00069290 File Offset: 0x00067490
        public SDK_DescriptionAttribute(Type typeToCopyExistingDescriptionFrom, int index = 0)
        {
            if (typeToCopyExistingDescriptionFrom == null)
            {
                VRTK_Logger.Fatal(new ArgumentNullException("typeToCopyExistingDescriptionFrom"));
                return;
            }
            Type typeFromHandle = typeof(SDK_DescriptionAttribute);

            SDK_DescriptionAttribute[] descriptions = SDK_DescriptionAttribute.GetDescriptions(typeToCopyExistingDescriptionFrom);
            if (descriptions.Length == 0)
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("typeToCopyExistingDescriptionFrom", typeToCopyExistingDescriptionFrom, string.Format("'{0}' doesn't specify any SDK descriptions via '{1}' to copy.", typeToCopyExistingDescriptionFrom.Name, typeFromHandle.Name)));
                return;
            }
            if (descriptions.Length <= index)
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("index", index, string.Format("'{0}' has no '{1}' at that index.", typeToCopyExistingDescriptionFrom.Name, typeFromHandle.Name)));
                return;
            }
            SDK_DescriptionAttribute sdk_DescriptionAttribute = descriptions[index];

            this.prettyName   = sdk_DescriptionAttribute.prettyName;
            this.symbol       = sdk_DescriptionAttribute.symbol;
            this.vrDeviceName = sdk_DescriptionAttribute.vrDeviceName;
            this.index        = index;
        }
        /// <summary>
        /// Creates a new attribute by copying from another attribute on a given type.
        /// </summary>
        /// <param name="typeToCopyExistingDescriptionFrom">The type to copy the existing SDK_DescriptionAttribute from. `null` is not allowed.</param>
        /// <param name="index">The index of the description to copy from the the existing SDK_DescriptionAttribute.</param>
        public SDK_DescriptionAttribute(Type typeToCopyExistingDescriptionFrom, int index = 0)
        {
            if (typeToCopyExistingDescriptionFrom == null)
            {
                VRTK_Logger.Fatal(new ArgumentNullException("typeToCopyExistingDescriptionFrom"));
                return;
            }

            Type descriptionType = typeof(SDK_DescriptionAttribute);

            SDK_DescriptionAttribute[] descriptions = GetDescriptions(typeToCopyExistingDescriptionFrom);
            if (descriptions.Length == 0)
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("typeToCopyExistingDescriptionFrom", typeToCopyExistingDescriptionFrom, string.Format("'{0}' doesn't specify any SDK descriptions via '{1}' to copy.", typeToCopyExistingDescriptionFrom.Name, descriptionType.Name)));
                return;
            }

            if (descriptions.Length <= index)
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("index", index, string.Format("'{0}' has no '{1}' at that index.", typeToCopyExistingDescriptionFrom.Name, descriptionType.Name)));
                return;
            }

            SDK_DescriptionAttribute description = descriptions[index];

            prettyName   = description.prettyName;
            symbol       = description.symbol;
            vrDeviceName = description.vrDeviceName;
            this.index   = index;
#if UNITY_EDITOR
            buildTargetGroup = description.buildTargetGroup;
#endif
        }
Exemplo n.º 3
0
        // Token: 0x06001B22 RID: 6946 RVA: 0x0008E028 File Offset: 0x0008C228
        private void SetUp(Type baseType, Type fallbackType, string actualTypeName, int descriptionIndex)
        {
            if (baseType == null || fallbackType == null)
            {
                return;
            }
            if (!baseType.IsSubclassOf(typeof(SDK_Base)))
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("baseType", baseType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", baseType.Name, typeof(SDK_Base).Name)));
                return;
            }
            if (!fallbackType.IsSubclassOf(baseType))
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("fallbackType", fallbackType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", fallbackType.Name, baseType.Name)));
                return;
            }
            this.baseTypeName     = baseType.FullName;
            this.fallbackTypeName = fallbackType.FullName;
            this.typeName         = actualTypeName;
            if (string.IsNullOrEmpty(actualTypeName))
            {
                this.type = fallbackType;
                this.originalTypeNameWhenFallbackIsUsed = null;
                this.descriptionIndex = -1;
                this.description      = new SDK_DescriptionAttribute(typeof(SDK_FallbackSystem), 0);
                return;
            }
            Type type = Type.GetType(actualTypeName);

            if (type == null)
            {
                this.type = fallbackType;
                this.originalTypeNameWhenFallbackIsUsed = actualTypeName;
                this.descriptionIndex = -1;
                this.description      = new SDK_DescriptionAttribute(typeof(SDK_FallbackSystem), 0);
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SDK_NOT_FOUND, new object[]
                {
                    actualTypeName,
                    fallbackType.Name
                }));
                return;
            }
            if (!type.IsSubclassOf(baseType))
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("actualTypeName", actualTypeName, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", actualTypeName, baseType.Name)));
                return;
            }
            SDK_DescriptionAttribute[] descriptions = SDK_DescriptionAttribute.GetDescriptions(type);
            if (descriptions.Length <= descriptionIndex)
            {
                VRTK_Logger.Fatal(new ArgumentOutOfRangeException("descriptionIndex", descriptionIndex, string.Format("'{0}' has no '{1}' at that index.", actualTypeName, typeof(SDK_DescriptionAttribute).Name)));
                return;
            }
            this.type = type;
            this.originalTypeNameWhenFallbackIsUsed = null;
            this.descriptionIndex = descriptionIndex;
            this.description      = descriptions[descriptionIndex];
        }
Exemplo n.º 4
0
        // Token: 0x06001B1F RID: 6943 RVA: 0x0008DF58 File Offset: 0x0008C158
        public static VRTK_SDKInfo[] Create <BaseType, FallbackType>(Type actualType) where BaseType : SDK_Base where FallbackType : BaseType
        {
            string fullName = actualType.FullName;

            SDK_DescriptionAttribute[] descriptions = SDK_DescriptionAttribute.GetDescriptions(actualType);
            if (descriptions.Length == 0)
            {
                VRTK_Logger.Fatal(string.Format("'{0}' doesn't specify any SDK descriptions via '{1}'.", fullName, typeof(SDK_DescriptionAttribute).Name));
                return(new VRTK_SDKInfo[0]);
            }
            List <VRTK_SDKInfo> list = new List <VRTK_SDKInfo>(descriptions.Length);

            foreach (SDK_DescriptionAttribute sdk_DescriptionAttribute in descriptions)
            {
                VRTK_SDKInfo vrtk_SDKInfo = new VRTK_SDKInfo();
                vrtk_SDKInfo.SetUp(typeof(BaseType), typeof(FallbackType), fullName, sdk_DescriptionAttribute.index);
                list.Add(vrtk_SDKInfo);
            }
            return(list.ToArray());
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates new SDK infos for a type.
        /// </summary>
        /// <typeparam name="BaseType">The SDK base type. Must be a subclass of SDK_Base.</typeparam>
        /// <typeparam name="FallbackType">The SDK type to fall back on if problems occur. Must be a subclass of `BaseType.</typeparam>
        /// <param name="actualType">The SDK type to use. Must be a subclass of `BaseType.</param>
        /// <returns>Multiple newly created instances.</returns>
        public static VRTK_SDKInfo[] Create <BaseType, FallbackType>(Type actualType) where BaseType : SDK_Base where FallbackType : BaseType
        {
            string actualTypeName = actualType.FullName;

            SDK_DescriptionAttribute[] descriptions = SDK_DescriptionAttribute.GetDescriptions(actualType);
            if (descriptions.Length == 0)
            {
                VRTK_Logger.Fatal(string.Format("'{0}' doesn't specify any SDK descriptions via '{1}'.", actualTypeName, typeof(SDK_DescriptionAttribute).Name));
                return(new VRTK_SDKInfo[0]);
            }

            HashSet <VRTK_SDKInfo> sdkInfos = new HashSet <VRTK_SDKInfo>();

            foreach (SDK_DescriptionAttribute description in descriptions)
            {
                VRTK_SDKInfo sdkInfo = new VRTK_SDKInfo();
                sdkInfo.SetUp(typeof(BaseType), typeof(FallbackType), actualTypeName, description.index);
                sdkInfos.Add(sdkInfo);
            }

            return(sdkInfos.ToArray());
        }
Exemplo n.º 6
0
        private void SetUp(Type baseType, Type fallbackType, string actualTypeName)
        {
#if NETFX_CORE
            if (!baseType.GetTypeInfo().IsSubclassOf(typeof(SDK_Base)))
#else
            if (!baseType.IsSubclassOf(typeof(SDK_Base)))
#endif
            {
                throw new ArgumentOutOfRangeException("baseType", baseType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", baseType.Name, typeof(SDK_Base).Name));
            }

#if NETFX_CORE
            if (!fallbackType.GetTypeInfo().IsSubclassOf(baseType))
#else
            if (!fallbackType.IsSubclassOf(baseType))
#endif
            {
                throw new ArgumentOutOfRangeException("fallbackType", fallbackType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", fallbackType.Name, baseType.Name));
            }

            baseTypeName = baseType.FullName;
            fallbackTypeName = fallbackType.FullName;
            typeName = actualTypeName;

            if (string.IsNullOrEmpty(actualTypeName))
            {
                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = null;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

            Type actualType = Type.GetType(actualTypeName);
            if (actualType == null)
            {
                VRTK_Logger.Error(VRTK_Logger.GetCommonMessage(VRTK_Logger.CommonMessageKeys.SDK_NOT_FOUND, new string[] { actualTypeName, fallbackType.Name }));

                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = actualTypeName;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }
#if NETFX_CORE
            if (!actualType.GetTypeInfo().IsSubclassOf(baseType))
#else
            if (!actualType.IsSubclassOf(baseType))
#endif
            {
                throw new ArgumentOutOfRangeException("actualTypeName", actualTypeName, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", actualTypeName, baseType.Name));
            }

            string fallbackNamespace = typeof(SDK_FallbackSystem).Namespace;
            string fallbackNamePrefix = typeof(SDK_FallbackSystem).Name.Replace("System", "");
            if (actualType.Namespace == fallbackNamespace && actualType.Name.StartsWith(fallbackNamePrefix, StringComparison.Ordinal))
            {
                type = actualType;
                originalTypeNameWhenFallbackIsUsed = null;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

#if NETFX_CORE
            // https://stackoverflow.com/a/12814920
            var actualDescription = (SDK_DescriptionAttribute)actualType.GetTypeInfo().GetCustomAttributes<SDK_DescriptionAttribute>().FirstOrDefault();
#else
            var actualDescription = (SDK_DescriptionAttribute)actualType.GetCustomAttributes(typeof(SDK_DescriptionAttribute), false).FirstOrDefault();
#endif
            if (actualDescription == null)
            {
                throw new ArgumentException(string.Format("'{0}' doesn't specify an SDK description via '{1}'.", actualTypeName, typeof(SDK_DescriptionAttribute).Name), "actualTypeName");
            }

            type = actualType;
            originalTypeNameWhenFallbackIsUsed = null;
            description = actualDescription;
        }
Exemplo n.º 7
0
        private void SetUp(Type baseType, Type fallbackType, string actualTypeName)
        {
            if (!baseType.IsSubclassOf(typeof(SDK_Base)))
            {
                throw new ArgumentOutOfRangeException("baseType", baseType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", baseType.Name, typeof(SDK_Base).Name));
            }

            if (!fallbackType.IsSubclassOf(baseType))
            {
                throw new ArgumentOutOfRangeException("fallbackType", fallbackType, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", fallbackType.Name, baseType.Name));
            }

            baseTypeName     = baseType.FullName;
            fallbackTypeName = fallbackType.FullName;
            typeName         = actualTypeName;

            if (string.IsNullOrEmpty(actualTypeName))
            {
                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = null;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

            Type actualType = Type.GetType(actualTypeName);

            if (actualType == null)
            {
                Debug.LogError(string.Format("The SDK '{0}' doesn't exist anymore. The fallback SDK '{1}' will be used instead.", actualTypeName, fallbackType.Name));

                type = fallbackType;
                originalTypeNameWhenFallbackIsUsed = actualTypeName;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

            if (!actualType.IsSubclassOf(baseType))
            {
                throw new ArgumentOutOfRangeException("actualTypeName", actualTypeName, string.Format("'{0}' is not a subclass of the SDK base type '{1}'.", actualTypeName, baseType.Name));
            }

            string fallbackNamespace  = typeof(SDK_FallbackSystem).Namespace;
            string fallbackNamePrefix = typeof(SDK_FallbackSystem).Name.Replace("System", "");

            if (actualType.Namespace == fallbackNamespace && actualType.Name.StartsWith(fallbackNamePrefix, StringComparison.Ordinal))
            {
                type = actualType;
                originalTypeNameWhenFallbackIsUsed = null;
                description = SDK_DescriptionAttribute.Fallback;

                return;
            }

            var actualDescription = (SDK_DescriptionAttribute)actualType.GetCustomAttributes(typeof(SDK_DescriptionAttribute), false).FirstOrDefault();

            if (actualDescription == null)
            {
                throw new ArgumentException(string.Format("'{0}' doesn't specify an SDK description via '{1}'.", actualTypeName, typeof(SDK_DescriptionAttribute).Name), "actualTypeName");
            }

            type = actualType;
            originalTypeNameWhenFallbackIsUsed = null;
            description = actualDescription;
        }