コード例 #1
0
        public void RegisterFactory(Type type, string category = "")
        {
            if (!type.IsSubclassOf(typeof(Object)))
            {
                throw new ArgumentException("Type must be subclass of Object.");
            }

            _factoryTypes[StringHash.Calculate(type.Name)] = type;

            // Find a wrapper base type.
            var baseType = type.BaseType;

            while (baseType != null && baseType.Assembly != typeof(Context).Assembly)
            {
                baseType = baseType.BaseType;
            }

            if (baseType == null)
            {
                throw new InvalidOperationException("This type can not be registered as factory.");
            }

            Urho3D_Context_RegisterFactory(getCPtr(this), type.Name, StringHash.Calculate("SwigDirector_" + baseType.Name), category);
            if (type.IsSubclassOf(typeof(Serializable)))
            {
                using (var serializable = (Serializable)Activator.CreateInstance(type, new object[] { Context.Instance }))
                {
                    serializable.RegisterAttributes();
                }
            }
        }
コード例 #2
0
ファイル: Context.cs プロジェクト: yazici/rbfx
        public void RegisterFactory(Type type, string category = "")
        {
            if (!type.IsSubclassOf(typeof(Object)))
            {
                throw new ArgumentException("Type must be subclass of Object.");
            }

            _factoryTypes[StringHash.Calculate(type.Name)] = type;

            // Find a wrapper base type.
            var baseType = type.BaseType;

            while (baseType != null && baseType.Assembly != typeof(Context).Assembly)
            {
                baseType = baseType.BaseType;
            }

            if (baseType == null)
            {
                throw new InvalidOperationException("This type can not be registered as factory.");
            }

            Urho3D_Context_RegisterFactory(getCPtr(this), type.Name, StringHash.Calculate("SwigDirector_" + baseType.Name), category);
        }