//-------------------------------------- // Properties //-------------------------------------- // GETTER / SETTER ///<summary> /// This is a sample getter/setter property. ///</summary> // PUBLIC ///<summary> /// This is a sample public property. ///</summary> // PUBLIC STATIC ///<summary> /// This is a sample public static property. ///</summary> // PRIVATE ///<summary> /// This is a sample private property. ///</summary> // PRIVATE STATIC ///<summary> /// This is a sample private static property. ///</summary> //-------------------------------------- // Methods //-------------------------------------- ///<summary> /// Use this for initialization ///</summary> void Start() { //********************************************************************* // // UNITY WITH COCKTAILS THEME: BEER // //********************************************************************* // DECLARE Beer budweiser_beer = new Beer("Budweiser", Beer.CONTAINER_TYPE_BOTTLE); // USE Debug.Log("--------------"); Debug.Log("budweiser_beer" + budweiser_beer); Beer.SamplePublicStaticMethod("calling public static method"); budweiser_beer.samplePublicMethod("calling public method"); // REFLECTION Debug.Log(" type : "+ budweiser_beer.GetType()); Debug.Log(" typeof : " + typeof(Beer)); Debug.Log(" (budweiser_beer is Beer): : "+ (budweiser_beer is Beer)); Debug.Log(" (budweiser_beer is Beverage) : "+ (budweiser_beer is Beverage)); // POLYMOPHISM, WE CAN TREAT BEER AND SODA INSTANCES IN A SIMILAR WAY (SOMETIMES) Soda cocaCola_soda = new Soda("CocaCola"); // Debug.Log("--------------"); Debug.Log(" beer.name : "+ budweiser_beer.name + " with calories " + budweiser_beer.calories); Debug.Log(" soda.name : "+ cocaCola_soda.name); }
static void UdskrivBeer(Beer beer) { foreach (var prop in beer.GetType().GetFields()) { Console.WriteLine(prop.Name + ": " + prop.GetValue(beer)); } }
public IActionResult Update(long id, [FromBody] Beer item) { if (item == null || item.Id != id) { return(BadRequest()); } var beer = _beerRepository.Find(id); if (beer == null) { return(NotFound()); } foreach (var prop in item.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)) { //if(prop.GetValue(item, null) != null) prop.SetValue(beer, prop.GetValue(item, null)); } _beerRepository.Update(beer); return(new NoContentResult()); }
//-------------------------------------- // Properties //-------------------------------------- // GETTER / SETTER ///<summary> /// This is a sample getter/setter property. ///</summary> // PUBLIC ///<summary> /// This is a sample public property. ///</summary> // PUBLIC STATIC ///<summary> /// This is a sample public static property. ///</summary> // PRIVATE ///<summary> /// This is a sample private property. ///</summary> // PRIVATE STATIC ///<summary> /// This is a sample private static property. ///</summary> //-------------------------------------- // Methods //-------------------------------------- ///<summary> /// Use this for initialization ///</summary> void Start() { //********************************************************************* // // UNITY WITH COCKTAILS THEME: BEER // //********************************************************************* // DECLARE Beer budweiser_beer = new Beer("budweiser", Beer.CONTAINER_TYPE_BOTTLE); // USE Debug.Log("--------------"); Debug.Log("budweiser_beer" + budweiser_beer); Beer.SamplePublicStaticMethod("calling public static method"); budweiser_beer.samplePublicMethod("calling public method"); // REFLECTION Debug.Log(" type : "+ budweiser_beer.GetType()); Debug.Log(" typeof : " + typeof(Beer)); Debug.Log(" (budweiser_beer is Beer): : "+ (budweiser_beer is Beer)); Debug.Log(" (budweiser_beer is Beverage) : "+ (budweiser_beer is Beverage)); }
public async Task <IActionResult> Update(long id, [FromBody] Beer item) { if (item == null || id == 0) { return(BadRequest()); } var beer = _context.Beer.FirstOrDefault(b => b.id == id); if (beer == null) { return(NotFound()); } if (item.style.id != item.styleId) { item.style = _context.Style.FirstOrDefault(s => s.id == item.styleId); } foreach (PropertyInfo prop in item.GetType().GetProperties()) { if (prop.Name != "id" && prop.Name != "label" && prop.Name != "style") { prop.SetValue(beer, prop.GetValue(item)); } } _context.Beer.Update(beer); _context.SaveChanges(); await _menuHubContext.Clients.All.SendAsync("BeerUpdated", item); return(Ok(new { message = "Beer is updated successfully." })); }
//-------------------------------------- // Properties //-------------------------------------- // GETTER / SETTER ///<summary> /// This is a sample getter/setter property. ///</summary> // PUBLIC ///<summary> /// This is a sample public property. ///</summary> // PUBLIC STATIC ///<summary> /// This is a sample public static property. ///</summary> // PRIVATE ///<summary> /// This is a sample private property. ///</summary> // PRIVATE STATIC ///<summary> /// This is a sample private static property. ///</summary> //-------------------------------------- // Methods //-------------------------------------- ///<summary> /// Use this for initialization ///</summary> void Start () { //********************************************************************* // // UNITY WITH COCKTAILS THEME: BEER // //********************************************************************* // DECLARE Beer budweiser_beer = new Beer ("Budweiser", Beer.CONTAINER_TYPE_BOTTLE); // USE Debug.Log ("--------------"); Debug.Log ("budweiser_beer" + budweiser_beer); Beer.SamplePublicStaticMethod ("calling public static method"); budweiser_beer.samplePublicMethod ("calling public method"); // REFLECTION Debug.Log (" type : " + budweiser_beer.GetType()); Debug.Log (" typeof : " + typeof(Beer)); Debug.Log (" (budweiser_beer is Beer): : " + (budweiser_beer is Beer) ); Debug.Log (" (budweiser_beer is Beverage) : " + (budweiser_beer is Beverage) ); // POLYMOPHISM, WE CAN TREAT BEER AND SODA INSTANCES IN A SIMILAR WAY (SOMETIMES) Soda cocaCola_soda = new Soda ("CocaCola"); // Debug.Log ("--------------"); Debug.Log (" beer.name : " + budweiser_beer.name + " with calories " + budweiser_beer.calories); Debug.Log (" soda.name : " + cocaCola_soda.name); }
//-------------------------------------- // Properties //-------------------------------------- // GETTER / SETTER ///<summary> /// This is a sample getter/setter property. ///</summary> // PUBLIC ///<summary> /// This is a sample public property. ///</summary> // PUBLIC STATIC ///<summary> /// This is a sample public static property. ///</summary> // PRIVATE ///<summary> /// This is a sample private property. ///</summary> // PRIVATE STATIC ///<summary> /// This is a sample private static property. ///</summary> //-------------------------------------- // Methods //-------------------------------------- ///<summary> /// Use this for initialization ///</summary> void Start() { //********************************************************************* // // UNITY WITH COCKTAILS THEME: BEER // //********************************************************************* // DECLARE Beer budweiser_beer = new Beer ("budweiser", Beer.CONTAINER_TYPE_BOTTLE); // USE Debug.Log ("--------------"); Debug.Log ("budweiser_beer" + budweiser_beer); Beer.SamplePublicStaticMethod ("calling public static method"); budweiser_beer.samplePublicMethod ("calling public method"); // REFLECTION Debug.Log (" type : " + budweiser_beer.GetType()); Debug.Log (" typeof : " + typeof(Beer)); Debug.Log (" (budweiser_beer is Beer): : " + (budweiser_beer is Beer) ); Debug.Log (" (budweiser_beer is Beverage) : " + (budweiser_beer is Beverage) ); }