|
Hi there,
Could anyone point me in the right direction... I'm trying to create a simple application that uses reflection to inspect objects at runtime. I dont want to use the Property Grid because i want to save the results to a text file. I cant find any example code that shows how to do this.
Thanks
Rohan
|
|
|
|
|
Your question isn't very clear. Do you need help with reflection, an alternative to the property grid, or how to write a text file?
|
|
|
|
|
The problem is with the reflection, i want to replicate the functionallity of the property grid with respect to viewing the different properties and their values.
Thanks
Rohan
|
|
|
|
|
You can use any number of list-based controls to display your information. A ListView, DataGrid, or any similar control would work to display. You can always write your own control or inherit from an existing control to provide specific features you need. The System.Reflection namespace is rich enough that it really doesn't matter how you display an properties and values.
|
|
|
|
|
The PropertyGrid doesn't actually use reflection, but various System.ComponentModel interfaces, like the ICustomTypeDescriptor interface, which you can read[^] about in the .NET Framework SDK. If the interface isn't implement by a component, the default behavior used by the TypeDescriptor which the PropertyGrid makes calls to is to use reflection, but reflection is not used directly (otherwise most of the design-time capability you enjoy in VS.NET and other IDEs would not be possible).
If you want to bind controls to your objects using their properties, read the documentation[^] for the PropertyManager class. You can use an array of objects of the same type (if not, the first type is used for binding information) similarily to how you'd use a DataTable or DataSet to bind, only you specify property names instead of column names.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi!
I am trying to make use of the new Enterprise Library application blocks in the re-write of a legacy system. The rewrite involves being able to access new C# modules from Delphi and as a result, we have decided to use COM to allow Delphi to access the C# objects, which are registered as COM objects.
Here is the code for a C# class that 'wraps' the Enterprise Library Cryptography application block:
///
/// COM wrapper for Enterprise Library Cryptography Application Block.
///
[ClassInterface(ClassInterfaceType.AutoDual)]
public class CorpITCryption
{
public string Encrypt(string aPlainText)
{
return Cryptographer.EncryptSymmetric("symprovider", aPlainText);
//return "Hello!";
}
public string Decrypt(string aCipherText)
{
return Cryptographer.DecryptSymmetric("symprovider", aCipherText);
}
}
This library class references the Microsoft.Practises.EnterpiseLibrary.Security.Cryptography .DLL and has Register For COM Interop set to True.
Here is the Delphi code that I am using:
procedure TForm1.Button1Click(Sender: TObject);
var
V: Variant;
begin
V:= CreateOleObject('CorpITCOMCryption.CorpITCryption');
edCipher.Text := V.Encrypt(edPlain.Text);
end;
I find that if I try to use other ways of accessing the COM object (ie by calling Co...Create() ) then I get a class not registered error in Delphi. The above method seems to work most regularly.
My actual problem is that I get an error in Delphi with the above version of the C# class library. The error text is as follows:
There was an error reflecting type 'Microsoft.Practises.EnterpriseLibrary.Security.Cryptography.Configuration.CryptographySettings'.
If I swap the comments on the Encrypt method and return a basic string, there is no error at all.
What am I doing wrong? What do I need to do to fix this?
Any help would be most appreciated.
Thanks
Andrew
|
|
|
|
|
Exposing .NET Framework components to COM should not be taken lightly. Never use auto-generated interfaces, always attributes your classes and interfaces with distinct GuidAttribute values, and many more things I've said in the past, which you can find by clicking "Search comments" above and search for "com interop". You should also read Exposing .NET Components to COM[^] here on CodeProject. When not using auto-generated class interfaces (which can lead to invalid VTBL binding or using the wrong cached dispatch IDs, if appropriate) you must declare the interface yourself and implement the class interface as the first interface in the interface implementation list when declaring your class.
Once you have followed these rules, so that your CLSIDs and IIDs don't change every time you compile (it's hard to hit a moving target, which is what you're doing now), you need to run either "regasm.exe assembly" is assembly is in the GAC, or "regasm.exe /codebase assembly" if not, which registers the full path to assembly in the InProcServer32 registry key for the CLSID in the registery.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hi all,
I am new to Print data using C#.Can any body tell me how to print data Row in a Database Table using C#?.
I want to Print that data like report view.
Thanks in advance..
|
|
|
|
|
You should consider using a third-party component that can do this for you, since such components implement advanced print styles and output formats. These are relatively inexpensive most times and will probably cost you less to buy than what would be required to develop a component even close to what you'd buy. Most are also royalty free.
If you want to do this yourself, then you need to read the documentation[^] for the PrintDocument class and all linked topics. A good object-oriented design would be to extend PrintDocument with your own class, define a property that accepts, for example, a DataTable , then override OnPrintPage to enumerate each row and print the data using the PrintPageEventArgs passed to the method. A very basic example follows:
public class DataPrintDocument : PrintDocument
{
DataTable table;
Font font;
int rowsPerPage = 0;
int margin = 4;
DataRow currentRow;
public DataPrintDocument() : this(null)
{
}
public DataPrintDocument(DataTable table)
{
this.table = table;
font = new Font("Arial", 10f);
}
public Font Font
{
get { return font; }
set { font = value; }
}
protected override void OnPrintPage(PrintPageEventArgs e)
{
base.OnPrintPage(e);
Graphics g = e.Graphics;
if (rowsPerPage == 0)
{
SizeF fontSize = g.MeasureString("CAPS", font);
rowsPerPage = e.MarginBounds.Height - (fontSize.Height + margin);
}
if (table == null || table.Rows.Count == 0)
g.DrawString("No data to print.", font, Brushes.Black, e.MarginBounds.Location);
else
{
int row = 0;
foreach (currentRow in table.Rows)
{
if (row++ > rowsPerPage) break;
}
}
}
} This should be enough to get you started, but I highl recommend a third-party solution that will save you lots of development time and at a relatively low cost. Some of those third-party component houses even advertise here on CodeProject, like ActiveReports from Data Dynamics that I see while typing this reply!
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I am new to C#.
I am writing a file manipulation application and I need to know the extended file properties - those that you can see in Win XP when you right click on column header in detailed explorer view: duration, bit rate, dimension, etc.
What do I need to use in C# to get those values?
Thanks,
lil dracula
|
|
|
|
|
This is not functionality easily exposed to .NET, since it's implementation is done in COM. There are "shortcuts" to doing it that may meet your requirements. See http://www.codeproject.com/csharp/ShellID3TagReader.asp[^] for an example. This is a crude way of doing it, however, since you're relying on data provided by the shell that is specific to folders and prone to breaking if new column providers are added.
The best way is to not rely on column providers and instead read the data yourself using the OLE storage functions (which you'll have to P/Invoke) and IPropertySetStorage and IPropertyStorage interfaces. You should be familiar with COM and COM interop with .NET. Read Interoperating with UnmanagedCode[^] if not, then read about Structured Storage[^] in the Platform SDK, especially about the two COM interfaces I mentioned above.
Different file types are handled by different persistence handlers that provide a way to get properties about the file based on what file it is. The default provider stores the extended information - on NTFS only - in an alternate data stream. For Office documents, this information is stored in the documents themselves and the persistence handler for those file types knows how to extract is and expose it in the same way as others. For supported media files, ID3 tag information or other metadata is extracted by other persistence handlers. This is the only sure way - short of knowing how to read extended information from all the different file types yourself, which would be very difficult (especially with proprietary formats) - of getting extended file information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for that great info!
It is terrific that there are people like you that helps out the community!
|
|
|
|
|
I have noticed that I can drag and drop an executable into a C# .NET
Visual Studio "Solution". How would I go about using an executable I dropped into my solution?
Lets just say all I need to do is feed an executable some text from standard
in. Has anyone done something like this yet?
|
|
|
|
|
When you drag and drop a file into a project or solution, you're just copying the file to the project or solution directory (as if you did it in Windows Explorer) and adding a reference to it in the project or solution file. Nothing more than that.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
ahsoh...
I see now. Ok, so I get at this via Systems.Diagnostics.Process then right?
I hope I can redirect a stream of ascii characters to and from this exe. This shouldn't be brain-surgery I imagine.
What datatype should I use to store the contents of an email? (I will need to later pump this email through my exe's standard in)
Thanks for your input btw.
|
|
|
|
|
No process is started when you drag an executable - or any file - to the Solution Explorer. You're simply dragging and dropping a file. Again, there is no process created.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I don't think you're following me. I was tallking about doing something like this:
using System;
using System.Diagnostics;
using System.ComponentModel;
MyProcess myProcess = new MyProcess();
Process.Start("IExplore.exe", "www.northwindtraders.com");
Any tips on what data structure I should use to hold me email prior to redirecting my executables standard in?
|
|
|
|
|
No, I'm afraid you're not making any sense. Your subject is "[VS .NET] Drag & Drop into Solution Explorer?" which has nothing to do with what you're asking now. When you drag and drop a file into the Solution Explorer you merely copy the file.
Now you're asking something entirely different. You don't need to add the process to your solution to run it using Process.Start . You only need to reference the correct path of the executable or just the name if the parent directory of the executable is in the PATH environment variable.
You don't use "data structure"s to redirect standard in. If you want to know how to do this, you should read the documentation[^] for ProcessStartInfo.RedirectStandardInput in the .NET Framework SDK. I will tell you, though, that Internet Explorer is a GUI application that does not output to standard output or error, or read from standard input.
And what does this have to do with emailing anything?
Please try to be clear. Your original post only said that you copied a file to your solution, which - as I've stated - is nothing more than copying the file to the solution or project directory. You DO NOT need to add an executable to your project.
For example, the following source - compiled with "csc.exe /t:exe sourcefile.cs" - starts Calc.exe. You don't even need a VS.NET project for it - just use the C# command-line compilers in %WINDIR%\Microsoft.NET\Framework\v1.1.4322 (or whatever version directory is installed for whatever version of .NET you have installed):
using System;
using System.Diagnostics;
class Example
{
static void Main()
{
Process.Start("calc.exe");
}
} No project, no copying calc.exe to a solution or project - just simply starting a program that exists in a directory reference in the PATH environment variable.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I was wondering if anyone has figured out how to get the new Windows XP-stype ballon-tip to appear in a Tray icon type application written in C#?
The NotifyIcon object doesn't have any properties or methods to allow for that and I just can't figure out how to do it.
Does anyone have any ideas?
Thanks.
|
|
|
|
|
|
|
I am a new programmer! I have a little experiences of C# language. Can you give me some advice to learns this language well.
Thank you very much
Hello Informatics World
|
|
|
|
|
Hi,
You can learn c# 2.0 as it will be release any sooner probably this year.
Learn the C# features - e.g generics.
Learn how to use OOP + Design Patterns (Singleton) in C#.
Learn .NET Coding Best Pratices when you coding C#. Well there is a tool called FxCop. It will help you to analyze your code. It is quite useful.
Best to learn to walk before running.
Hope it helps. Cheers.
Regards,
Chua Wen Ching
Visit us at http://www.necoders.com
|
|
|
|
|
Hi,
Is it possible to wrap a dll A into another dll B, so I just need to distribute the dll B, but not the dll A? And how are there differences in
the following cases ?
1. the dll A is written in VC++, and the wrapping dll B is written in C#
2. the dll A is written in C#, and the wrapping dll B is written in C#
My concern is that I don't want others to get the original dll B when I distribute
the program. So can other people reverse engineer the wrapped dll and get the original dll out ?
Many thanks
|
|
|
|
|
No, that's not possible.
Something like this can only be done with static libraries that are linked with an executable.
With dlls you don't get code copied or linked directly, but only references to external functions.
That's the whole point of using dlls.
mav
|
|
|
|