Problem with interface in XNA game project - c#

Here is a part mof my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
.
.
.
public virtual bool CheckCollision(ICollidable i_Source)
{
bool collided = false;
ICollidable2D source = i_Source as 2DICollidable;
if (source != null)
{
collided = source.Bounds.Intersects(this.Bounds);
}
return collided;
}
For some reason, there is an error about using ICollided2D.
Why does it don't recognize this kind of variable? Do I miss any "using" statment?

Either this is a typing mistake:
ICollidable2D source = i_Source as 2DICollidable;
Or you a missing an _ before 2DICollidable, so it becomes _2DICollidable as you can't start an identifier with a number.

2DICollidable
What is this? I dont think normal identifiers can start with number. Heck even SO code-highlighter shows it in red.

Related

How to handle the unit-test assembly load issue in C#

While loading assemblies from both x64/x86, I have got exception message as System.BadImageFormatException in my unit-test project.
Below is the code and screen shot of the exception I have got while debugging the test.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Example_Addin;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using Microsoft.Office.Interop.Visio;
using Visio = Microsoft.Office.Interop.Visio;
namespace exampleProject
{
[TestClass]
public class exampleUnitTest1
{
[TestMethod]
public void Test_example()
{
try
{
Example exm_obj = new Example();
string file_path = "test.json";
string template_file = "template.vssx";
double height = 0.5;
double width = 0.5;
db_obj.read_data_shape_creation(#file_path, 0.5, 0.5, "F06", #template_file, "testing");
}
catch (Exception)
{
System.Diagnostics.Debug.WriteLine("Exception occour");
}
}
}
Here, I want to unit test my code with assembly dependencies, but after setting the assembly, I get the above snapped exception and code execution is halted. 
This issue happen due to my target framework for unit-test and my core-project are not matching. When I have correct both case it is working.

Select IFC Physical Simple Quantity of Wall

I'm using XBim IFC libraries in order to get some info of a Building model elements.
Specifically, of IfcWall entities.
I have to acces Wall Base Quantities (lenght, height, width, etc.) but I cant reach those properties from IfcWall class.
I have this class:
using Dapper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xbim.Ifc;
using Xbim.Ifc4.ActorResource;
using Xbim.Ifc4.DateTimeResource;
using Xbim.Ifc4.ExternalReferenceResource;
using Xbim.Ifc4.PresentationOrganizationResource;
using Xbim.Ifc4.GeometricConstraintResource;
using Xbim.Ifc4.GeometricModelResource;
using Xbim.Ifc4.GeometryResource;
using Xbim.Ifc4.Interfaces;
using Xbim.Ifc4.Kernel;
using Xbim.Ifc4.MaterialResource;
using Xbim.Ifc4.MeasureResource;
using Xbim.Ifc4.ProductExtension;
using Xbim.Ifc4.ProfileResource;
using Xbim.Ifc4.PropertyResource;
using Xbim.Ifc4.QuantityResource;
using Xbim.Ifc4.RepresentationResource;
using Xbim.Ifc4.SharedBldgElements;
namespace ProcesadorPremoldeado.IFC
{
public class IFCCalculos
{
public void CalculoPlacas(string fileName, XbimEditorCredentials editor)
{
using (var model = IfcStore.Open(fileName, editor))
{
using (var transaction = model.BeginTransaction("Quick start transaction"))
{
//get all Walls in the model
var ifcWallsList = model.Instances.OfType<IfcWall>();
foreach (var wall in ifcWallsList)
{
var prop = wall.PhysicalSimpleQuantities.Where(x=>x.Name=="Height");
}
transaction.Commit();
}
}
}
}
}
That lambda expression return me a row, correctly filtered by Name parameter, as this property is accessible.
But I cant access the property call "LengthValue", the strange thing is that the property is visible during debbugin if I put a breakpoint, under "prop" list in the foreach loop.
Anyone could give me an idea of what could be happening?
Thanks in advance!
This is because LengthValue is a property of IfcQuantityLength, but PhysicalSimpleQuantities are of supertype IfcPhysicalQuantity. You just need to select quantities of the right type
var height = wall.PhysicalSimpleQuantities
.OfType<IfcQuantityLength>()
.Where(x=>x.Name=="Height")?
.LengthValue;

Dapper 'Query' not recognised

The 'connection.Query' does not prompt for Dapper using statement. Dapper has been installed several times. I've tried entering the using statement 'using Dapper' but it's underlined in red saying:
Dapper namespace could not be found
Why is it happening?
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
namespace DataAccessLibrary
{
public class SQLDataAccess
{
public List<T> LoadData<T, U>(string sqlStatement, U parameters, string connectionString)
{
using (IDbConnection connection = new SqlConnection(connectionString))
{
List<T> rows = connection.Query<T>(sqlStatement, parameters).ToList();
}
}
}
}
I'm embarrassed to say i installed Dapper into the wrong project in my application. I assumed (never assume, always check) wrongly that the installation would be seen throughout my app.
Problem solved.

Selecting image error using selenium c#

I'm running a basic c# test below. My test is essentially going to go onto www.asos.com then search for a specific item. When the search results are loaded I want to click on the first item that's returned. I tried to use CSS selector to click on the first imagine but I get an exception. Invalid selector.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Interactions;
using System.Threading;
namespace Exercise1
{
class Exercise_2
{
static void Main(string[] args)
{
IWebDriver webDriver = new ChromeDriver();
webDriver.Navigate().GoToUrl("http://www.asos.com/men/");
webDriver.Manage().Window.Maximize();
webDriver.FindElement(By.XPath(".//input[#data-testid='search-input']")).SendKeys("Polo Ralph Lauren Oxford Shirt In Regular Fit Blue");
webDriver.FindElement(By.XPath(".//button[#data-testid='search-button-inline']")).Click();
//*[#id="product-6153807"]/a/div[1]/img Xpath of the image to be clicked on
webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
webDriver.FindElement(By.CssSelector("6153807")).Click();
}
}
}
use the following css selector.
article img
in code,
webDriver.FindElement(By.CssSelector("article img")).Click();

Windows.Storage error: the type of namespace Storage does not exist in namespace windows

I am very new to C#, visual studio, and related Microsoft work. So it is very likely that I messed something up and I hope some one can help me a bit on this.
I create an Console application and I am trying to run some tutorial C# code. There is a red line under when I try to load Windos.Storage.Pickers and all namespaces after it. I attempt to add the references, but I can't find what I need there.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.Graphics.Imaging;
using Windows.Media.FaceAnalysis;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Shapes;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
FaceDetector faceDetector;
IList<DetectedFace> detectedFaces;
FileOpenPicker photoPicker = new FileOpenPicker();
photoPicker.ViewMode = PickerViewMode.Thumbnail;
photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
photoPicker.FileTypeFilter.Add(".jpg");
photoPicker.FileTypeFilter.Add(".jpeg");
photoPicker.FileTypeFilter.Add(".png");
photoPicker.FileTypeFilter.Add(".bmp");
StorageFile photoFile = await photoPicker.PickSingleFileAsync();
if (photoFile == null)
{
return;
}
}
}
}
the namespace you are tying to use is use for UWP development.
The problem is that you are trying to use it in Console Development.
Read about it here

Categories

Resources