|
Don't spoil my fun yet; I still need to bring up proper XML-documentation, FXCop and StyleCop
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The Car does implement an action (set the speed value), but that is irrelevant. Bottom line, the Car needs to be a Vehicle and as a vehicle in must be able to perform an action but the action is dependent of the type of vehicle:
Vehicle<Actions> myVehicle = new Car();
Vehicle<Actions> myVehicle2 = new Airplane
myVehicle.PerformActions();
myVehicle2.PerformActions();
|
|
|
|
|
I can get it to work compile this way:
IVehicle<IActions> aCar = (IVehicle<IActions>) new Car();
But it won't run successfully.
And, you'll need to instantiate the actions as well:
IVehicle<IActions> aCar = (IVehicle<IActions>) new Car() { actions = new CarActions() } ;
This just in! Made major changes to your code, but it works.
public interface IVehicle<TActions> where TActions : IActions
{
IActions actions { get; set; }
}
public class Vehicle<TActions> : IVehicle<TActions> where TActions : IActions
{
public IActions actions { get ; set; }
}
public class Car : Vehicle<CarActions> , IVehicle<IActions>
{
public int Wheels { get; set; }
}
public class Airplane : Vehicle<AirplaneActions> , IVehicle<IActions>
{
}
modified 12-Oct-17 0:16am.
|
|
|
|
|
Thanks for the suggestions.
|
|
|
|
|
It looks like you need to use generic covariance:
Covariance and Contravariance in Generics | Microsoft Docs[^]
You'll need to use the IVehicle<T> interface instead of the Vehicle<T> class, since generic covariance doesn't work with classes.
You'll also need to remove the setter for the actions property, since that would break the rules for covariance.
The changes you need:
public interface IVehicle<out TActions> where TActions : IActions
{
TActions actions { get; }
}
public abstract class Vehicle<TActions> : IVehicle<TActions> where TActions : Actions
{
public abstract TActions actions { get; }
}
public class Car : Vehicle<CarActions>
{
public int Wheels { get; set; }
public override CarActions actions { get; } = new CarActions();
}
public class Airplane : Vehicle<AirplaneActions>
{
public override AirplaneActions actions { get; } = new AirplaneActions();
}
...
static void Main(string[] args)
{
IVehicle<IActions> aCar = new Car();
IVehicle<Actions> anAirplane = new Airplane();
List<IVehicle<IActions>> list = new List<Vehicle<Actions>>
{
aCar,
anAirplane
};
foreach (var vehicle in list)
{
vehicle.actions.ID = "any";
vehicle.actions.PerformAction();
}
Console.WriteLine("Good");
}
The sample still won't do anything useful, but it should get you started.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard
That did the trick!
|
|
|
|
|
I knew it needed covariance, but I had never needed to mess with that.
I got it working today.
|
|
|
|
|
How to upload file in mongodb using gridFS and Windows Form application? Please give a working example source code. I am beginner with mongodb.
|
|
|
|
|
We aren't here as a code-to-order service: for that you would need Freelancer.com.
But be aware: you get what you pay for. Pay peanuts, get monkeys.
The idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
So either pay someone to do it, or learn how to write it yourself. We aren't here to do it for you.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
So tell me how can I do that job.
|
|
|
|
|
Read what I said.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Mongo provides some decent documentation.
GridFS
Right off their main C# driver documentation.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I want to import a spanish dictionary in my c# program
Thanks
Carlos
|
|
|
|
|
carlos read the 2 sticky messages at the top of this page and try again.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Excellent. This means that you have the beginnings of a specification for what you want your program to do. Now, you need to take this a step further and start to break this down into a more refined set of specifications. For instance, do you want to bundle the dictionary itself into your program, or do you want to use some form of RESTful API to do the lookups? Is this dictionary going to allow the user to add words? Once you have a fuller specification, and have some idea what it is that you are really trying to do, please feel free to come back at that point and ask for more information.
This space for rent
|
|
|
|
|
You have my full permission to do that. You may carry on to the next stage.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Did he fill our form "permit 838[^]"?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In triplicate! Countersigned by an officer of rank 65E/44 or higher, and with the tax stamp applied.
First time I've seen that in a beginner. Hmm. I think we have a mole in the department...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Bueno !
«While I complain of being able to see only a shadow of the past, I may be insensitive to reality as it is now, since I'm not at a stage of development where I'm capable of seeing it. A few hundred years later another traveler despairing as myself, may mourn the disappearance of what I may have seen, but failed to see.» Claude Levi-Strauss (Tristes Tropiques, 1955)
|
|
|
|
|
I need to add authentication to my Web API, so user must add token, or password to access the Web API.
Under Controller folder i have :
[AcceptVerbs("GET")]
public Reservation RPCStyleMethodFetchFirstEmployees()
{
return listEmp.FirstOrDefault();
}
[HttpGet]
[ActionName("GetReservation")]
public List<reservation> Get()
{
string source = System.Configuration.ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection conn = new SqlConnection(source);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
string sql = "Select s.Id,a.Room_No ,s.Room_Description,s.Room_Capacity, b.Description, s.Location,s.Start_Date,s.Start_Time,CONVERT(VARCHAR(20),CONVERT(Varchar(50),( Concat(CONVERT(VARCHAR, s.Start_Date, 126),'T',CONVERT(VARCHAR, s.End_Time, 127)) ),105),131)+'.00Z',s.End_Time,s.Meeting_Title,s.Reservation_Reason, s.Status,s.Attendance,s.Remarks,s.Mail_To,s.Mail_CC, s.Created_User, s.Created_Password, s.Created_Access_Key from Reservation s , Rooms a, Room_Type b Where s.Room_No = a.ID And s.Room_Type = b.ID";
cmd.CommandText = sql;
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
Reservation emp = null;
conn.Open();
reader = cmd.ExecuteReader();
List<reservation> emps = new List<reservation>();
while (reader.Read())
{
emp = new Reservation();
emp.Id = Convert.ToInt32(reader.GetValue(0));
emp.Room_No = reader.GetValue(1).ToString();
emp.Room_Description = reader.GetValue(2) as string;
emp.Room_Capacity = (reader.GetValue(3) as int?) ?? 0;
emp.Room_Type = reader.GetValue(4) as string;
emp.Location = reader.GetValue(5) as string;
emp.Start_Date = reader.GetValue(6).ToString();
emp.Start_Time = reader.GetValue(7).ToString();
emp.Start_Date_Time = reader.GetValue(8).ToString();
emp.End_Time = reader.GetValue(9).ToString();
emp.Meeting_Title = reader.GetValue(10) as string;
emp.Reservation_Reason = reader.GetValue(11) as string;
emp.Status = reader.GetValue(12) as string;
emp.Attendance = (reader.GetValue(13) as int?) ?? 0;
emp.Remarks = reader.GetValue(14) as string;
emp.Mail_To = reader.GetValue(15) as string;
emp.Mail_CC = reader.GetValue(16) as string;
emp.Created_User = reader.GetValue(17) as string;
emp.Created_Password = reader.GetValue(18) as string;
emp.Created_Access_Key = reader.GetValue(19) as string;
emps.Add(emp);
}
conn.Close();
return emps;
}
and under Models i have
public class Reservation
{
public int Id { get; set; }
public string Room_No { get; set; }
public string Room_Description { get; set; }
public int Room_Capacity { get; set; }
public string Room_Type { get; set; }
public string Location { get; set; }
public string Start_Date { get; set; }
public string Start_Time { get; set; }
public string Start_Date_Time { get; set; }
public string End_Time { get; set; }
public string Meeting_Title { get; set; }
public string Reservation_Reason { get; set; }
public string Status { get; set; }
public int Attendance { get; set; }
public string Remarks { get; set; }
public string Mail_To { get; set; }
public string Mail_CC { get; set; }
public string Created_User { get; set; }
public string Created_Password { get; set; }
public string Created_Access_Key { get; set; }
}
How to add Authentication before they start get the data
Please i don't have clear information about classes and authentication, also i don't have startup.cs
please i need easy way
|
|
|
|
|
Hello, everyone
I am trying to create a program that can click button with its name of an form automatically to submit an form.
For example: There is a page that includes input-fields username and password, and two input buttons with the same tag "input" and same type "submit", but different names like "reset" and "authorize".
I am using the class IHtmlFormElement to get the HTML Form and use one of the input buttons to submit that form.
Here is my code:
IHTMLFormElement form = GetForm(0);
if (form.item("authorize", 0) != null)
{
var authorizeSubmit = form.item("authorize", 0);
}
form.submit();
My Question is, how could i tell the compiler to click the submit button with name "authorize" not "reset"? It there another way to do it better?
Thank you very much!
Carvin
|
|
|
|
|
Hello!
I want to represent a WPF-Menu based on a XML-file.
The file looks like this:
<menues>
<menu title="One">
<item title="USB-Stick" value="1234" />
</menu>
<menu title="Two">
<item title="CD" value="4321" />
</menu>
<menu title="Three">
<item title="USB-Stick" value="9876" />
<item title="Diskette" value="5667" />
<menu title="CC">
<item title="Test1" value="3234" />
<item title="Test2" value="2332" />
<item title="Test3" value="3213" />
</menu>
</menu>
</menues>
The goal is to be able to expand the menu at any time.
I hope someone can help me.
Best regards!
|
|
|
|
|
Help with what exactly? Reading XML, generating a menu, or all of it?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Preferably all of it.
I know, how to read a XML-file, but I cant display the data as a menu.
So I don't know the connection of these things ...
|
|
|
|
|
Member 13100573 wrote: Preferably all of it. In that case you'd be asking for a developer for hire.
Member 13100573 wrote: I know, how to read a XML-file, but I cant display the data as a menu. Creating a menu dynamically isn't that hard in WinForms, so I would expect it not to be too hard in WPF either. You could search for an example and give it a try - if you get stuck and have a specific question we can help.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|