|
It sounds like your close to the correct understanding. Be aware though, this is NOT a normal situation in coding. The only reason you would ever use new is that the member is NOT virtual and you need to override its functionality. Because the method is virtual, there is really no need to shadow it with new . Typically shadowing can get you into a lot of confusion if you're not careful, hence why when its not necessary it is strictly avoided.
As an example of why its not needed, if you change the definition of the method in C to:
class C : B
{
public override void M() { Console.WriteLine("C"); }
}
It'll print out four "D"s.
As for interfaces, they don't represent a class you can create (eg. new IList() ), but rather just an expected contract of functionality.
I mention explicit implementation of interfaces because they represent something similar to the behavior seen in the code you posted. Basically, how you reference an object determines exactly what functionality is called.
When you down cast class D to C, that is an implicit cast (ie. .NET assumes you mean to do that). It'd be exactly the same as if you had typed:
C c = (C)d;
Ok, he comes some really confusing stuff, hopefully it won't make things worse.
If you look at the reflected IL code of the Main method, you'll see this:
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] class Example.D d,
[1] class Example.C c,
[2] class Example.B b,
[3] class Example.A a)
L_0000: nop
L_0001: newobj instance void Example.D::.ctor()
L_0006: stloc.0
L_0007: ldloc.0
L_0008: stloc.1
L_0009: ldloc.1
L_000a: stloc.2
L_000b: ldloc.2
L_000c: stloc.3
L_000d: ldloc.0
L_000e: callvirt instance void Example.C::M()
L_0013: nop
L_0014: ldloc.1
L_0015: callvirt instance void Example.C::M()
L_001a: nop
L_001b: ldloc.2
L_001c: callvirt instance void Example.A::M()
L_0021: nop
L_0022: ldloc.3
L_0023: callvirt instance void Example.A::M()
L_0028: nop
L_0029: ret
}
I've underlined the calls to d.M(), c.M(), etc. You'll notice that its going back to the class that defines the original signature of the method. Because of the 'new' keyword, that inheritance starts over so to speak. So, from a code perspective, it'll burrow its way through the currently defined type you're referencing it as, until it finds a 'new' keyword or the 'virtual' keyword. From there, it'll find the furthest up the inheritance chain it can go before it reaches the real type of the class or another 'new' keyword. By using 'new', you break all inheritance hence forth.
I hope that helps you, rather than confuses you.
|
|
|
|
|
hi,
as i told in recent post, i need to a way to place generated serial number into my application. but i build my application using msbuild, bcoz of dynammic build i cant change the source code to place serial number in it, is there any way to place serial number of software without changing source code manually??? or a way to define serial of software?
note: I need this serial number to be checked in my hardlock validation routine!
|
|
|
|
|
Well, you could write a utility to patch the executable, but what about obfuscation? Are you going to obfuscate your code? If so (and believe me you should), you have to do it AFTER you patch the exe because (decent) obfuscation utilities typically encrypt strings.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
thanx for ur answer! u mean there isn't any way to add serial number to software? could u explain how obfuscate my code?
|
|
|
|
|
I figured you didn't want to spend the money on a commercial solution.
Obfuscation makes it difficult/impossible to reverse engineer your code (which is easy to do on a .net assembly). Google ".Net Obfuscation tools" to find a list of viable candidates.
BTW, Visual Studio comes with an obfuscation tool, but it's so featureless as to be completely worthless. You have to actually spend money on a 3rd party product, and this can cost from $150 to THOUSANDS of dollars. If your app written in WPF or Silverlight, there's only one obfuscator that can obfuscate it, but I don't remember what the name of it is.
As far as a serial number tool, you may be able to find one that can work on obfuscated assemblies, but I dont' know. Again, google is your friend.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hellow i m new to C# and i have a project to find duplicate values in two or more Excel files.
to ope the files i use the :
Microsoft.Jet.OLEDB.4.0
and afther the conection i get a dataTable.
the DataTable is inserten in tow a data set that contains all my "files"
Hope this dose the write thing....
i m stuck at finding the duplicates....
can someone point me in the write direction?
10x
|
|
|
|
|
|
Hi all,
I want to use WebBrowser control as a file viewer, but my files are stored in database.
I can open files by WebBrowser control using WebBrowse.Navigate() method.
But,
I want to load my files directly from database to WebBrowser control, instead of saving them to hard disk then loading to WebBrowser control using WebBrowse.Navigate() method.
Can I pass binary data of a file from database to WebBrowser control?
please help...
|
|
|
|
|
With WebBrowser, you either provide a URL to the Navigate() method, which causes the Control to go fetch the corresponding web page, or you provide an HTML document to its DocumentText property, so you provide the page content directly, nothing gets fetched.
The DocumentText also accepts non-HTML documents very much like Internet Explorer does. If you set it to "aha" it will show the word in a default font, size, color, etc. And probably, not tested, if you feed it a PDF document (the binary content of a PDF file) it will display that too, assuming your system has the necessary code to do so, i.e. Internet Explorer is doing that too.
You should experiment a bit.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
OK thank you Luc ...
Now, how to:
Luc Pattyn wrote: feed it a PDF document (the binary content of a PDF file)
|
|
|
|
|
You can set the DocumentStream property of the control. The specified stream will be used to read the data that will be rendered.
|
|
|
|
|
Thank you Giorgi, but it works perfectly with images only
I tried .doc and .pdf files but a garbage data is displayed
i'm using MemoryStream
|
|
|
|
|
you could always fill a memorystream with legal HTML code, then feed that stream to WebBrowser.DocumentStream. HTML knows how to package an image, a PDF, etc; web servers do it all the time, e.g. when you browse to http://www.codeproject.com/App_Themes/Std/Img/logo225x90.gif you well get Bob, because the CP server sends the correct HTML head and body stuff.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thanks again Luc,
But.............
what is the HTML code you are talking about?????
what is the HTML code that represent file's binary data??
You may mean < embed ... ???
if so, I must save file to hard disk that is I do NOT want to do
this is my question
|
|
|
|
|
You don't need a physical file; most file operations also exist as stream operations (see e.g. Image.FromFile and Image.FromStream), and a MemoryStream is a Stream. So WebBrowser.DocumentStream should be your friend.
For HTTP, there are a number of classes in .NET; and there is the full HTML specification. I have done some on server side (mostly PHP, where lots of library functions are available, which hide the details); I also once found Sample HTTP Server Skeleton in C#[^] quite interesting. It may actually be what you want: it allows you to hide a web server inside your app, so your WebBrowser (or any external browser on your machine) could see its web pages, which do not exist outside your process.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Luc Pattyn wrote: you could always fill a memorystream with legal HTML code
Are you really certain for that?In that case if you want to diplay pdf file you need web server to handle requests to the database.WebBrowser control has a property DocumentType , which contains mime type of the document.And if we need pdf we could just set it to "application/pdf" and IE will understand that this is pdf file, not html page.
[Edit]It's read only unfortunately.After after googling I've found that.[/EDIT]
Life is a stage and we are all actors!
modified on Thursday, June 10, 2010 12:52 PM
|
|
|
|
|
Not sure what your question is. To the OP, I see two possible paths:
1. feed an entire MemoryStream to WebBrowser.DocumentStream, by synthesizing a valid HTML response;
2. or provide an embedded HTML server, and use WebBrowser.Navigate().
In both cases, the data could be provided by any means available, such as a database.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
My post means that you can't display pdf in web browser control from binary data, loaded from a database for example.And the forum thread said that you can't set DocumentType property but you could work around that by hooking IE session.I believe it's ultimate hack.
Life is a stage and we are all actors!
|
|
|
|
|
I'm pretty sure it can be done, as I have said several times already.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|
Luc Pattyn wrote: to prove it (for an image; a PDF would be similar).
Yes if the pdf is located somewhere on the web.But if it's binary data loaded from local db there's only one way, which is closer to dirty hacks instead of normal logic.
Life is a stage and we are all actors!
|
|
|
|
|
What is wrong with you? simply copy whatever binary data you have from the database to a memory stream, then feed the WebBrowser; it will consume everything it understands (HTML; XML; plain text; lots of image formats; PDF).
PDF will only work well if you thaught Internet Explorer to handle PDF files (e.g. with an Adobe component); if it doesn't, neither will WebBrowser.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Luc Pattyn wrote: PDF will only work well if you thaught Internet Explorer to handle PDF files
Yes you are right only for images handing.It't NOT working with PDFs as it was already mentioned.Simply try that and see with your own eyes what is displayed-the pdf file or something else:
byte[] binarydata = File.ReadAllBytes(@"C:\somefile.pdf");
MemoryStream str = new MemoryStream(binarydata);
webBrowser1.DocumentStream = str;
The problem is that you can't set DocumentType property and IE can't handle Content-Type header automatically.You need to set it somewhere, but you are not able using DocumentStream property only.
Life is a stage and we are all actors!
|
|
|
|
|
Yes, you are right, PDF is different after all. Some research indicates PDF is harder than images, but doable. I'll try to demonstrate when time allows me.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
|