|
Yes I did. See comments in code
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You might not be using the right interface. An object's full name includes its namespace.
Assembly #1:
namespace AssemblyGetTypeTest
{
class Program
{
static void Main(string[] args)
{
Assembly a = Assembly.LoadFrom(@"TestTypeLib.dll");
Type testInterface = a.GetType("TestTypeLib.ITestInterface");
foreach (Type t in a.GetTypes())
{
if (testInterface.IsAssignableFrom(t))
Console.WriteLine($"Success on type {t.Name} in namespace {testInterface.Namespace}");
if (typeof(ITestInterface).IsAssignableFrom(t))
Console.WriteLine($"Success on type {t.Name} in namespace AssemblyGetTypeTest.");
}
Console.ReadKey();
}
}
public interface ITestInterface
{
void Test();
}
}
Assembly #2:
namespace TestTypeLib
{
public interface ITestInterface
{
void Test();
}
public class Class1 : ITestInterface
{
public void Test(){ }
}
}
Output:
Success on type ITestInterface in namespace TestTypeLib
Success on type Class1 in namespace TestTypeLib
The interfaces TestTypeLib.ITestInterface and AssemblyGetTypeTest.ITestInterface are different.
|
|
|
|
|
Can I ask why you're reinventing the wheel here? Why not just use MEF which is included in the framework by default, and is as feature rich as you could possibly want?
This space for rent
|
|
|
|
|
IsInstanceOfType instead of IsAssignableFrom ?
|
|
|
|
|
Hi,
I was wondering if someone could show what i am doing wrong here I have a combobox with about 20 items listed. Now when someone selects an item from the combobox i need that Item to be "Inserted" into the table column named "Mode".
Here is what i have tried to far but to no prevail
MyCommand.Parameters.Add("@Mode", System.Data.SqlDbType.Text);
MyCommand.Parameters["@Mode"].Value = Convert.ToInt32(cbModePicker.SelectedItem.ToString());
|
|
|
|
|
rattlerrFx wrote: doing wrong here
Well, it looks to me that you are defining a parameter of type string, then taking a string value and converting it to an integer and trying to stuff the integer into a string parameter. Does that make sense to you?
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
lol no it does not make sense but that is why i came here, to figure out the correct way. I have never tried to insert data from a selected item in a combobox into a database table column.
|
|
|
|
|
How about:
MyCommand.Parameters.AddWithValue("@Mode", cbModePicker.SelectedItem);
If that doesn't work, you'll need to tell us what the error message says, and what value the cbModePicker.SelectedItem has.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: No mapping exists from object type System.Windows.Controls.ComboBoxItem to a known managed provider native type.
Total of 3 ComboBoxItems [0], [1], [2]
|
|
|
|
|
So use the SelectedValue property[^] instead:
MyCommand.Parameters.AddWithValue("@Mode", cbModePicker.SelectedValue);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am getting error while saving outlook file in folder and when i am opening out look file i am getting error
cannot start Microsoft outlook outlook.Cannot open file.How to upload save... The file may not exist,you may not have permission to open it,or it may be open in another program.Right click the folder that contains file,and then click properties to check your permissions for that folder
|
|
|
|
|
So, this looks like one of those special cases where the fix for the issue is in the text of the error.
Check the permissions of the Security Context that your software is running under.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
In the below code snippet, Ring() method defined in Classes "SmartPhone", "BasicPhone" etc is returning a custom datatype called "Sound". As far as I have read few topics, custom datatypes can be implemented using Classes, Structures etc.Normally, I have worked with methods returning in-built datatypes like int,string etc but have no idea about methods returning custom datatypes like "Sound" as per mentioned example. So, how should I write/define the Class "Sound" for the above program to work
OR (an other explanation w.r.t the question asked)
If code execution calls "Phone.Ring()" statement in the foreach loop defined Main() method , let's say a message "MP3 music is playing" for Smartphone, "Polyphonic music is playing" for SemiSmartPhone, "8BitMusic is playing" for BasicPhone to be displayed on the console screen.
Let me know if you need more details.To be honest, had posted in other forums, but couldn't get an answer yet.As far as I remember, this code example has been picked from codeproject.com I believe. Thanks
My Program on hold:
class Sound
{
???
}
interface IRingable
{
public Sound Ring();
}
class SmartPhone : IRingable
{
public Sound Ring()
{
return PlayMp3Music();
}
}
class SemiSmartPhone : IRingable
{
public Sound Ring()
{
return PolyPhonicMusic();
}
}
class BasicPhone : IRingable
{
public Sound Ring()
{
return 8BitMusic();
}
}
class Main
{
public static void Main(string[] args)
{
List<IRingable> phones = new List<IRingable>();
IRingable htc = new SmartPhone();
phones.Add(htc);
IRingable samsung = new SemiSmartPhone();
phones.Add(samsung);
IRingable nokia = new BasicPhone();
phones.Add(nokia);
foreach (IRingable phone in phones)
{
phone.Ring();
}
}
}
|
|
|
|
|
Some of your code is okay but you seem to be running into a little bit of a misunderstanding about what Sound would be doing. Basically, your Sound idea would suggest that you would have only one Sound class and somehow it would be able to satisfy the different sounds, be they polyphonic, etc. The reality is, you would need multiple Sound classes, and you would use an appropriate one of these.
So, the question you have here is, how would you declare these classes and how would you use them? To answer this, you are first going to have to decide whether Sound contains any functionality at all, or whether it is merely a contract. If it's merely a contract, then you would get rid of the Sound class altogether, and just have an interface that the different sound classes would play. Let's assume, though, that the Sound class has some functionality that is common across the different implementations - it could be that the Sound class is responsible for loading a sound in and then playing it, and the only difference in your implementations is which sound it brings in. In this case, you would make your Sound class abstract and you would inherit from this. This might give you something like this:
public abstract class Sound
{
public void PlaySound()
{
SoundPlayer soundPlayer = new SoundPlayer(SoundName);
soundPlayer.Play();
}
protected abstract string SoundName { get; }
} Now, in this code, we can see that the SoundName property is marked as abstract which means that derived classes must provide an implementation. So, let's create an appropriate derived class here
public class PolyphonicSound()
{
protected virtual string SoundName { get { return "MySoundFile.wav"; } }
} Now, with this in place, any time you want to use a polyphonic sound, you would use an instance of this class. As an example, you would change SemiSmartPhone to return the PolyphonicSound class like this:
class SemiSmartPhone : IRingable
{
public Sound Ring()
{
return new PolyphonicSound();
}
} Now, the final bit that needs to be sorted out (other than adding the other appropriate sound classes), is to sort out your foreach. Your current implementation has a return value that it does nothing with. We know that Ring will return the appropriate Sound implementation and that they have a PlaySound method that we need to call, so change this instead to be:
foreach (IRingable phone in phones)
{
Sound sound = phone.Ring();
sound.PlaySound();
}
This space for rent
|
|
|
|
|
Thank you Pete O'Hanlon. I was able to understand your explanation & was quite useful. The question which I posted was from an article of code project. The link for the same is Why do we need Interfaces?[^]
The said example is under the section "Interfaces Treat different types in the Same Way". I was unable to run that example as "Sound" in the code is behaving like a custom datatype (correct me if I am wrong) and the Ring() in all classes was returning "Sound". There was no implementation for "Sound" class or structure in that program. So, just wanted to know from experts as how would a "Sound" class be defined for that program to run successfully. Any ways, thanks a lot & appreciate for taking time in replying.
|
|
|
|
|
Member 12984275 wrote: What should the implementation of this class be for the program It should be whatever is necessary to do whatever you want it to do. If you do not understand how to create a C# class then take a look at Classes and Structs (C# Programming Guide)[^].
|
|
|
|
|
i saw couple of sample code searching google and people said we can run ppt slide show inside webbrowser controls. so i did the same.
here is my code
webBrowser1.Dock = DockStyle.Fill;
webBrowser1.Navigate("about.blank");
webBrowser1.Navigate(@"e:\Presentations-Tips.ppt");
when i run the code then a dialog come which ask me to choose one option out of 3 and i select open option. after selection open option power point apps open but no slide show run in my webbrowser control.
here is the screen shot url [screenshot]
i want to run ppt slide show inside my browser controls and i want also no dialog should come with 3 options and also ppt app should not run.
so guide me how could i run ppt slide show in my browser control without opening power point application. thanks
tbhattacharjee
|
|
|
|
|
|
please guide me what argument i need to pass with ppt files name when run with Process.Start as a result ppt slide should start automatically
System.Diagnostics.Process.Start("pptfilename.pptx")
thanks
tbhattacharjee
|
|
|
|
|
Did you even TRY to Google for "PowerPoint command line arguments" before you posted this?
It's called "reading the documentation".
|
|
|
|
|
|
So did you keep reading all the way down the article, like to where it mentions the /N# switch? Apparently not.
Research is a skill you MUST have to survive doing this job.
|
|
|
|
|
He's a help vampire
This space for rent
|
|
|
|
|
yes i googled it but face some problem. i use the below code
webBrowser1.Dock = DockStyle.Fill;
webBrowser1.Navigate("about.blank");
webBrowser1.Navigate(@"e:\Presentations-Tips.ppt");
when i run the code then a dialog come which ask me to choose one option out of 3 and i select open option. after selection open option power point apps open but no slide show run in my webbrowser control.
[here is the screen shot url]
the problem is when i run the above code then first power point application is open which i do not want. also nothing start showing in web browser controls.
basically i want to run ppt slide show in web browser controls but power point application will not run. now tell me how it will be possible and what code i need to use. thanks
tbhattacharjee
|
|
|
|
|
That's not your original code.
You don't have the control over which slide is shown using the webbrowser control method.
|
|
|
|