FindTypeByName() public static méthode

public static FindTypeByName ( string name ) : Type
name string
Résultat System.Type
Exemple #1
0
        public static bool ReadType(XmlElement xml, string attribute, ref Type value, bool mandatory)
        {
            string s = GetAttribute(xml, attribute, mandatory);

            if (s == null)
            {
                return(false);
            }

            Type type;

            try
            {
                type = ScriptCompiler.FindTypeByName(s, false);
            }
            catch
            {
                Console.WriteLine("Could not parse Type attribute '{0}' in element '{1}'", attribute, xml.Name);
                return(false);
            }

            if (type == null)
            {
                Console.WriteLine("Could not find Type '{0}'", s);
                return(false);
            }

            value = type;
            return(true);
        }
        public static bool ActionOnSpawner(ISpawner spawner, Type typeCheck, string lineCheck, string exempt, Action <ISpawner> action, bool inherits)
        {
            string[] list = GetSpawnList(spawner);

            if (list == null)
            {
                return(false);
            }

            foreach (var str in list)
            {
                if (string.IsNullOrEmpty(str))
                {
                    continue;
                }

                string spawnObject = str.ToLower();

                if (typeCheck != null)
                {
                    Type t;

                    if (spawner is Spawner)
                    {
                        t = ScriptCompiler.FindTypeByName(spawnObject);
                    }
                    else
                    {
                        t = ScriptCompiler.FindTypeByName(BaseXmlSpawner.ParseObjectType(spawnObject));
                    }

                    if (t == typeCheck || (t != null && inherits && t.IsSubclassOf(typeCheck)))
                    {
                        if (action != null)
                        {
                            action(spawner);
                        }

                        return(true);
                    }
                }
                else
                {
                    string lookFor = lineCheck != null?lineCheck.ToLower() : null;

                    if ((lookFor == null || spawnObject.IndexOf(lookFor) >= 0) && (exempt == null || spawnObject.IndexOf(exempt.ToLower()) <= 0))
                    {
                        if (action != null)
                        {
                            action(spawner);
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #3
0
        public static bool HasParent(this Item item, string typeName)
        {
            if (item == null || String.IsNullOrWhiteSpace(typeName))
            {
                return(false);
            }

            Type t = Type.GetType(typeName, false, false) ??
                     ScriptCompiler.FindTypeByFullName(typeName, false) ?? ScriptCompiler.FindTypeByName(typeName, false);

            return(HasParent(item, t));
        }
Exemple #4
0
        private static Type FindType(string value)
        {
            Type type = Type.GetType(value, false);

            if (type != null)
            {
                return(type);
            }

            if (value.IndexOf('.') < 0)
            {
                return(ScriptCompiler.FindTypeByName(value));
            }

            return(ScriptCompiler.FindTypeByFullName(value));
        }
        public static Type ReadType(this GenericReader reader)
        {
            if (!reader.ReadBool())
            {
                return(null);
            }

            bool   full = reader.ReadBool();
            string name = reader.ReadString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            Type type = Type.GetType(name, false) ??
                        (full ? ScriptCompiler.FindTypeByFullName(name) : ScriptCompiler.FindTypeByName(name));

            return(type);
        }
        private static bool CheckSmartSpawn(XmlSpawner spawner, Type check, bool subclasses)
        {
            foreach (var obj in spawner.SpawnObjects)
            {
                if (obj.TypeName != null)
                {
                    var t = ScriptCompiler.FindTypeByName(BaseXmlSpawner.ParseObjectType(obj.TypeName));

                    if (t != null && (t == check || (subclasses && t.IsSubclassOf(check))))
                    {
                        spawner.SmartSpawning = false;

                        if (spawner.CurrentCount == 0)
                        {
                            spawner.DoRespawn = true;
                        }

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #7
0
        public static Type ReadType(this GenericReader reader)
        {
            if (!reader.ReadBool())
            {
                return(null);
            }

            // Peek preamble for upgrade support
            if (reader.PeekInt() == 0x0C0FFEE0 && reader.ReadInt() == 0x0C0FFEE0)
            {
                return(_Types.GetValue(reader.ReadInt()));
            }

            var full = reader.ReadBool();
            var name = reader.ReadString();

            if (String.IsNullOrWhiteSpace(name))
            {
                return(null);
            }

            return(Type.GetType(name, false) ??
                   (full ? ScriptCompiler.FindTypeByFullName(name) : ScriptCompiler.FindTypeByName(name)));
        }
		private static BaseDoor DeserializeDoor(XmlElement node)
		{
			var t = node.GetAttribute("type");

			var type = ScriptCompiler.FindTypeByName(t, true) ?? //
					   ScriptCompiler.FindTypeByFullName(t, true) ?? //
					   Type.GetType(t, false, true);

			BaseDoor door;

			try
			{
				door = (Activator.CreateInstance(type, _ImportArgs) ?? Activator.CreateInstance(type)) as BaseDoor;
			}
			catch
			{
				return null;
			}

			if (door == null)
			{
				return null;
			}

			var x = XmlConvert.ToInt32(node.GetAttribute("x"));
			var y = XmlConvert.ToInt32(node.GetAttribute("y"));
			var z = XmlConvert.ToInt32(node.GetAttribute("z"));

			door.Location = new Point3D(x, y, z);

			var ox = XmlConvert.ToInt32(node.GetAttribute("ox"));
			var oy = XmlConvert.ToInt32(node.GetAttribute("oy"));
			var oz = XmlConvert.ToInt32(node.GetAttribute("oz"));

			door.Offset = new Point3D(ox, oy, oz);

			door.OpenedID = XmlConvert.ToInt32(node.GetAttribute("oid"));
			door.ClosedID = XmlConvert.ToInt32(node.GetAttribute("cid"));

			door.Locked = XmlConvert.ToBoolean(node.GetAttribute("locked"));

			if (node.HasAttribute("keyval"))
			{
				door.KeyValue = XmlConvert.ToUInt32(node.GetAttribute("keyval"));
			}

			if (node.HasAttribute("osound"))
			{
				door.OpenedSound = XmlConvert.ToInt32(node.GetAttribute("osound"));
			}

			if (node.HasAttribute("csound"))
			{
				door.ClosedSound = XmlConvert.ToInt32(node.GetAttribute("csound"));
			}

			if (node.HasAttribute("hue"))
			{
				door.Hue = XmlConvert.ToInt32(node.GetAttribute("hue"));
			}

			if (door.Open)
			{
				door.ItemID = door.OpenedID;
			}
			else
			{
				door.ItemID = door.ClosedID;
			}

			return door;
		}
Exemple #9
0
 public static Type FindTypeByName(string name)
 {
     return(ScriptCompiler.FindTypeByName(name, true));
 }