本文整理汇总了C#中Thing.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Thing.GetType方法的具体用法?C# Thing.GetType怎么用?C# Thing.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thing
的用法示例。
在下文中一共展示了Thing.GetType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddThing
//===================================================================//
// Actions //
//===================================================================//
/// <summary>
/// This override ensures that only <see cref="Clothing"/> can be added to the Clothes.
/// </summary>
/// <param name="item">the item to be added</param>
public override void AddThing(Thing item)
{
if (!typeof(Clothing).IsAssignableFrom(item.GetType())) {
throw new WearingSomethingBesidesClothingException(); }
else {
base.AddThing(item); }
}
示例2: CreateObject
public object CreateObject(string line, List<string> headers)
{
string[] values = line.Split(';');
Thing thing = new Thing();
foreach (var property in thing.GetType().GetProperties())
{
string FileColumnsName = GetFileColumnsNameFromMappage(property, "Thing");//Recuperation du nom de la colonne Dans le fichier Importé depuis le mappage
int IndexColumnsInFile = FileColumnsName != null ? GetIndexColumnsInFile(FileColumnsName, headers) : -1;//Recuperation de l'index colonne Dans le fichier Importé
object toInsert = null;
if (IndexColumnsInFile != -1)
{
switch (property.PropertyType.Name)
{
case "DateTime":
toInsert = DateTime.Parse(values[IndexColumnsInFile]);
break;
default:
DateTime TestOfString;
toInsert = string.IsNullOrEmpty(values[IndexColumnsInFile]) ? null : values[IndexColumnsInFile];
bool isDate = DateTime.TryParse(values[IndexColumnsInFile],out TestOfString);
if (isDate)
{
toInsert = TestOfString;
}
break;
}
}
property.SetValue(thing, toInsert, null);
}
if (string.IsNullOrEmpty(thing.Name))
{
throw new Exception("Name is mandatory");
}
return thing;
}
示例3: PutInto
/// <summary>
/// Has the <see cref="Actor"/> try to put
/// a given <see cref="Thing"/> into a given
/// <see cref="Container"/>.
/// </summary>
/// <param name="item">the <see cref="Thing"/> to place</param>
/// <param name="container">the <see cref="Container"/> to put it into</param>
public void PutInto(Thing item, Thing container)
{
// if the actor can't see the item, throw an exception
if(!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the actor can't see the container, throw an exception
if(!GameManager.CanSee(this, container)) {
throw new InteractingWithUnseenThingException(); }
// if the container is not actually a Container, throw an exception
if(!typeof(Container).IsAssignableFrom(container.GetType())) {
throw new PuttingIntoNonContainerException(); }
// if the item is already in the containter, throw an exception
if (item.GetLocation() == container) {
throw new PuttingItemAlreadyInsideException(); }
// if the item is the container, throw an exception
if (item == container) {
throw new PuttingItemIntoItselfException(); }
// if the actor isn't carrying the item, try taking it instead
if(!this.Carries(item)) {
// if the actor is the player, report the auto-correction
if (GameManager.IsPlayer(this)) {
GameManager.ReportIfVisible(this, "((You aren't carrying " + item.GetSpecificName() + ". Trying to take it instead...))"); }
this.Take(item);
return; }
// if the container is closed, try to open it instead
if (typeof(OpenableContainer).IsAssignableFrom(container.GetType()) && !((OpenableContainer)container).IsOpen()) {
// if the actor is the player, report the auto-correction
if (GameManager.IsPlayer(this)) {
GameManager.ReportIfVisible(this, "((" + StringManipulator.CapitalizeFirstLetter(container.GetSpecificName()) + " is currently closed. Trying to open it instead..."); }
this.Open(container);
return; }
// TODO: Should actors automatically try to unlock containers?
// if nothing went wrong, execute normally
item.GetLocation().RemoveThing(item);
((Container)container).AddThing(item);
item.SetLocation((Container)container);
GameManager.ReportIfVisible(this, VerbSet.ToPut, item, " into ", container);
}
示例4: Open
/// <summary>
/// Has the <see cref="Actor"/> try to open
/// a given <see cref="Thing"/>.
/// </summary>
/// <param name="item">the <see cref="Thing"/> to open</param>
/// <exception cref="InteractingWithUnseenThingException">
/// if the <see cref="Actor"/> cannot see the <see cref="Thing"/>
/// </exception>
/// <exception cref="OpeningSomethingBesidesOpenableException">
/// if the <see cref="Thing"/> is not <see cref="Openable"/>
/// </exception>
public void Open(Thing item)
{
// if the item is not visible, throw an exception
if (!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the item is not openable, throw an exception
else if (!typeof(Openable).IsAssignableFrom(item.GetType())) {
throw new OpeningSomethingBesidesOpenableException(); }
// the item is visible and openable; execute as normal
else {
// TODO: Make sure the item being opened isn't someone else's clothing.
((Openable)item).Open();
GameManager.ReportIfVisible(this, this.GetSpecificName() + ' ' + this.GetConjugatedVerb(VerbSet.ToOpen) + ' ' + item.GetSpecificName() + '.'); }
}
示例5: Close
/// <summary>
/// Has the <see cref="Actor"/> try to close
/// a given <see cref="Thing"/>.
/// </summary>
/// <param name="item">the <see cref="Thing"/> to close</param>
/// <exception cref="InteractingWithUnseenThingException">
/// if the <see cref="Actor"/> cannot see the <see cref="Thing"/>
/// </exception>
/// <exception cref="OpeningSomethingBesidesOpenableException">
/// if the <see cref="Thing"/> is not <see cref="Openable"/>
/// </exception>
public void Close(Thing item)
{
// if the item is not visible, throw an exception
if (!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the item is not openable, throw an exception
else if (!typeof(Openable).IsAssignableFrom(item.GetType())) {
throw new ClosingSomethingBesidesOpenableException(); }
// the item is visible and openable; execute as normal
else {
// TODO: Make sure the item being closed isn't someone else's clothing.
((Openable)item).Close();
GameManager.ReportIfVisible(this, VerbSet.ToClose, item); }
}
示例6: Wear
//===================================================================//
// Actions //
//===================================================================//
/// <summary>
/// Has the <see cref="Person"/> try to wear the given
/// <see cref="Thing"/>.
/// If the <see cref="Person"/> is not carrying the
/// <see cref="Thing"/>, it has them try to take the
/// <see cref="Thing"/> instead.
/// </summary>
///
/// <param name="item">the <see cref="Thing"/> to try wearing</param>
///
/// <exception cref="InteractingWithUnseenThingException">
/// if the <see cref="Person"/> can't see the <see cref="Thing"/>
/// </exception>
/// <exception cref="WearingSomethingAlreadyWornException">
/// if the <see cref="Person"/> is already wearing the
/// <see cref="Thing"/>
/// </exception>
/// <exception cref="WearingSomethingBesidesClothingException">
/// if the <see cref="Thing"/> is not <see cref="Clothing"/>
/// </exception>
public void Wear(Thing item)
{
// if the actor can't see the item, throw an exception
if (!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the actor is already wearing the item, throw an exception
else if (this.Wears(item)) {
throw new WearingSomethingAlreadyWornException(); }
// if the item isn't actually clothing, throw an exception
else if (!typeof(Clothing).IsAssignableFrom(item.GetType())) {
throw new WearingSomethingBesidesClothingException(); }
// if the actor is not carrying the item, try taking it instead
else if (!this.Carries(item)) {
if (GameManager.IsPlayer(this)) {
GameManager.ReportIfVisible(this, "((You aren't carrying "
+ item.GetSpecificName() + "; trying to take it instead...))");
this.Take(item); }
} // end "if the actor is not carrying the item"
// "happy path"
else {
this.clothes.AddThing(item);
item.GetLocation().RemoveThing(item);
item.SetLocation(this.clothes);
GameManager.ReportIfVisible(this, this.GetSpecificName() + ' ' + this.GetConjugatedVerb(VerbSet.ToPut) + " on " + item.GetSpecificName() + '.');
}
}
示例7: DeclaringTypeIsNotInterfaceType
public void DeclaringTypeIsNotInterfaceType()
{
var thing = new Thing();
PropertyInfo propertyInfo = thing.GetType().GetProperty("Id");
Assert.That(propertyInfo.DeclaringType, Is.Not.EqualTo(typeof(IThing)));
}
示例8: Wear
/// <summary>
/// Has the <see cref="Person"/> try to wear the given
/// <see cref="Thing"/>.
/// If the <see cref="Person"/> is not carrying the
/// <see cref="Thing"/>, it has them try to take the
/// <see cref="Thing"/> instead.
/// </summary>
///
/// <param name="item">the <see cref="Thing"/> to try wearing</param>
///
/// <exception cref="InteractingWithUnseenThingException">
/// if the <see cref="Person"/> can't see the <see cref="Thing"/>
/// </exception>
/// <exception cref="WearingSomethingAlreadyWornException">
/// if the <see cref="Person"/> is already wearing the
/// <see cref="Thing"/>
/// </exception>
/// <exception cref="WearingSomethingBesidesClothingException">
/// if the <see cref="Thing"/> is not <see cref="Clothing"/>
/// </exception>
public void Wear(Thing item)
{
// if the actor can't see the item, throw an exception
if (!GameManager.CanSee(this, item)) {
throw new InteractingWithUnseenThingException(); }
// if the actor is already wearing the item, throw an exception
if (this.Wears(item)) {
throw new WearingSomethingAlreadyWornException(); }
// if the item isn't actually clothing, throw an exception
if (!typeof(Clothing).IsAssignableFrom(item.GetType())) {
throw new WearingSomethingBesidesClothingException(); }
// if the actor is not carrying the item, try taking it instead
if (!this.Carries(item)) {
if (GameManager.IsPlayer(this)) {
GameManager.ReportIfVisible(this, "((You aren't carrying "
+ item.GetSpecificName() +
"; trying to take it instead...))"); }
this.Take(item);
return; }
// if thr actor is wearing something that can't be worn at the
// same time as the item, throw an exception
foreach(Clothing wornItem in this.clothes.GetContents()) {
if (wornItem.CannotBeWornWith((Clothing)item)) {
throw new WearingWithConflictingItemException(wornItem,
item); } }
// "happy path"
this.clothes.AddThing(item);
item.GetLocation().RemoveThing(item);
item.SetLocation(this.clothes);
GameManager.ReportIfVisible(this, this.GetSpecificName() + ' '
+ this.GetConjugatedVerb(VerbSet.ToPut) + " on " +
item.GetSpecificName() + '.');
}