当前位置: 首页>>代码示例>>C#>>正文


C# Property.GetType方法代码示例

本文整理汇总了C#中Property.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# Property.GetType方法的具体用法?C# Property.GetType怎么用?C# Property.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Property的用法示例。


在下文中一共展示了Property.GetType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: calculateMortgage

        //calculate the mortage value
        public virtual decimal calculateMortgage(Property property)
        {
            decimal dMortgagePrice = 0;
            //Get types of properties
            //REFERENCE -> getting property type code retrieved from https://msdn.microsoft.com/en-us/library/58918ffs.aspx
            System.Type residential = typeof(Residential);
            System.Type utility = typeof(Utility);
            System.Type transport = typeof(Transport);

            if (property.GetType() == residential)
            {
                //cast the property as Residential
                Residential residentialProperty = (Residential)property;
                dMortgagePrice = residentialProperty.getPrice();
            }
            else if (property.GetType() == utility)
            {
                //cast the property as Utility
                Utility utilityProperty = (Utility)property;
                dMortgagePrice = utilityProperty.getPrice();
            }
            else if (property.GetType() == transport)
            {
                //cast the property as Transport
                Transport transportProperty = (Transport)property;
                dMortgagePrice = transportProperty.getPrice();
            }

            return dMortgagePrice * 80 / 100;
        }
开发者ID:Michael67Thornton,项目名称:Monopoly_Game,代码行数:31,代码来源:TradeableProperty.cs

示例2: WriteXml

        public static void WriteXml(XmlWriter writer, string key, Property value)
        {
            writer.WriteStartElement("PropertyEntry");

            writer.WriteAttributeString("Key", key);

            var type = value.GetType();
            try
            {
                var ser = GetSerializer(type);
                writer.WriteAttributeString("Type", type.AssemblyQualifiedName);
                ser.Serialize(writer, value);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Serialization failed: " + ex.Message);
                Console.WriteLine("Property Key: " + key);
                Console.WriteLine("Property Value: " + value);
                Console.WriteLine("Property Type Name: " + type.Name);
                Console.WriteLine("Property Type Qualified Name: " + type.AssemblyQualifiedName);
                Console.WriteLine("Stacktrace: " + ex.StackTrace);
            }

            writer.WriteEndElement();
        }
开发者ID:OronDF343,项目名称:Sky-Jukebox,代码行数:25,代码来源:PropertyEntryMultiSerializer.cs

示例3: GetClassMapping

 public IPersistentClassInformation GetClassMapping(string path)
 {
     var rc = new RootClass();
     foreach (string p in probe.GetProperties(path))
     {
         var ser = new JavaScriptSerializer();
         var obj = ser.DeserializeObject(p) as IDictionary<string,object>;
         var prop = new Property();
         prop.Value = NHValueJSonHelper.JSonDeserialize(prop.GetType().Assembly, obj["Value"] as IDictionary<string,object>) as IValue;
         prop.Name = obj["Name"] as string;
         rc.AddProperty( prop);
     }
     return ConfigurationMapper.MapClass(rc);
 }
开发者ID:mausch,项目名称:NHWorkbench,代码行数:14,代码来源:ProjectPresenter.cs

示例4: HandleLanding

        private void HandleLanding(Property propertyLandedOn , Player player)
        {
            // If it's a residential property we need to parse it so we can get the colour and display it to the user
            // otherwise they won't be aware of colour the property is at any point.
            var propertyAsRes = propertyLandedOn.GetType() == typeof (Residential) ? (Residential) propertyLandedOn : null;
           
            // When landing on chance or community chest we need the behavour to be
            // slightly different, i.e. get a card and display what the card is
            if (propertyLandedOn.GetName().Contains("Chance") && (Board.Access().GetChanceCards().Count > 0))
            {
                Console.WriteLine(Board.Access().GetChanceCard().LandOn(ref player));
            }
            else if (propertyLandedOn.GetName().Contains("Community Chest") && (Board.Access().GetCommunityChestCards().Count > 0))
            {
                Console.WriteLine(Board.Access().GetCommunityChestCard().LandOn(ref player));
            }
            else
            {
                // Landon property and output to console
                // In the case that they've landed on a chance or community chest but there 
                // aren't any cards left we must make them aware of this.
                var isChance = propertyLandedOn.GetName().Contains("Chance");
                var isCommunityChest = propertyLandedOn.GetName().Contains("Community Chest");

                Console.WriteLine("{0}{1}{2}",
                    propertyLandedOn.LandOn(ref player),/*{0}*/
                    isChance ? " No more Chance cards." : isCommunityChest ? " No more Community Chest cards." : "",/*{1}*/
                    propertyAsRes != null ? " (Colour: " + propertyAsRes.GetHouseColour() + ")" : "");/*{2}*/
            }
        }
开发者ID:ITfanatic,项目名称:IT7302_Assignment3_Monopoly,代码行数:30,代码来源:Monopoly.cs


注:本文中的Property.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。