|
|
In addition to the CP article that Pete cited, also see: [^], [^].
«When I consider my brief span of life, swallowed up in an eternity before and after, the little space I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which know me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.» Blaise Pascal
|
|
|
|
|
Thank you very much BillWoodruff .Can you please tell em how to pass our own custom attributes .
|
|
|
|
|
Question: what is the scale/scope of the code base you wish to monitor/log ? Multi-threading involved ? Team project with multiple code repositories ?
Also see this recent article: [^].yeswanthkumar wrote: Can you please tell em how to pass our own custom attributes While I am a registered owner of PostSharp, I do not have the expertise to comment on any other method/tool, and I have never tried to explore creating custom attributes in PostSharp: however their documentation/support are very good, and I expect if the need arose, it could be done: [^].
imho, the task of IL-weaving/AOP is an extremely technically deep subject, and experimenting with "rolling your own" potentially risky in terms of technical "cost."
Have you looked at Spring.NET: [^] ?
cheers, Bill
«When I consider my brief span of life, swallowed up in an eternity before and after, the little space I fill, and even can see, engulfed in the infinite immensity of spaces of which I am ignorant, and which know me not, I am frightened, and am astonished at being here rather than there; for there is no reason why here rather than there, now rather than then.» Blaise Pascal
|
|
|
|
|
OK, here's a real mind-twister. I can't figure out how to declare the parameter of a function as deriving from a generic class.
Here's the code:
public class BusinessObjectBase
{
}
public class BusinessObjectList<T> : List<T> where T : BusinessObjectBase
{}
public class BusinessObjectDataSet : DataSet
{
protected BusinessObjectList<BusinessObjectBase>[] _BusinessObjectListArray = null;
public virtual void AddBusinessObjectList(BusinessObjectList<BusinessObjectBase> List)
{
}
}
I want to specify the variable as type BusinessObjectList<T> where T derives from BusinessObjectBase.
The code above compiles fine, but when I go to use the classes, that's the problem:
private class MyBusinessObject : BusinessObjectBase
{
public MyBusinessObject()
{
}
}
private class MyBusinessObjectList<MyBusinessObject> : BusinessObjectList<T> where T : BusinessObjectBase
{
}
BusinessObjectDataSet Set = new BusinessObjectDataSet();
MyBusinessObject Bo = new MyBusinessObject();
MyBusinessObjectList<MyBusinessObject> BoList = new MyBusinessObjectList<MyBusinessObject>();
Set.AddBusinessObjectList(BoList);
What am I doing wrong?
Thank you for taking the time to grok this.
EDIT: Fixed an omission in the code. Revised the question that I'm asking.
The difficult we do right away...
...the impossible takes slightly longer.
modified 29-May-17 16:14pm.
|
|
|
|
|
The problem is that the two lists aren't covariant.
What that basically means is that if you construct collections:
class Animal {...}
class Ape : Animal {...}
class Feline : Animal {...}
List<Ape> apes = new List<Ape>();
List<Feline> cats = new List<Feline>();
List<Animal> animals = new List<Animal>(); Then because an Ape is an Animal, you can add a new species to either collection:
Ape newSpecies = new Ape("Pans Sapiens");
apes.Add(newSpecies);
animals.Add(newSpecies);
But if you try to add it to the Felines:
cats.Add(newSpecies);
You will get a compilation error:
Argument 1: cannot convert from 'GeneralTesting.frmMain.Ape' to 'GeneralTesting.frmMain.Feline'
And that is what you would expect.
But ... if you could do what you want, you could do this:
Ape newSpecies = new Ape("Pans Sapiens");
animals = cats;
animals.Add(newSpecies);
And you would have an Ape in your Feline collection - which means your application will crash later on when you try to use it.
What you are passing to the AddBusinessObjectList is not a BusinessObjectList<BusinessObjectBase> - it's a derived list of a derived class.
I'm not sure exactly what you can do about this - it may be possible to construct a cast operator, but I'm not sure if that would work without some serious head scratching!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
OriginalGriff wrote: I'm not sure exactly what you can do about this
Yes, thank you for taking the time to answer. If the suggestion from Pete doesn't work I think I may have to redesign this.
I'm very sorry that generics are invariant, as I now see it says in the documentation.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
The issue is down to the harder constraint you have in place in AddBusinessObjectList. Try changing it to this instead:
public virtual void AddBusinessObjectList<T>(BusinessObjectList<T> List) where T : BusinessObjectBase Oh, and change your definition of MyBusinessObjectList to this:
private class MyBusinessObjectList<T> : BusinessObjectList<T> where T : BusinessObjectBase
This space for rent
|
|
|
|
|
Thank you for taking the time to answer. If your suggestion doesn't work, I'll try redesigning everything to make it simpler.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
private class MyBusinessObjectList<MyBusinessObject> : BusinessObjectList<T> where T : BusinessObjectBase
is not a valid statement (T "not found" syntax error); while
private class MyBusinessObjectList<MyBusinessObject> :
BusinessObjectList<BusinessObjectBase>
compiles and runs the rest successfully.
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thanks. I think I may have tried that. But it's possible I'm wrong, so I'll doublecheck.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I can't describe the problem very clearly
I want to do taskbar thumbnails with windows API code packs that can be displayed normally but move to main window already loaded state; i do not know how to fix
I'm just implementing the thumbnail image, but this move to the thumbnail window becomes the loading state
using Microsoft.WindowsAPICodePack.Taskbar;
private TabbedThumbnail customThumbnail;
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
customThumbnail = new TabbedThumbnail(this.Handle, this.Handle);
TaskbarManager.Instance.TabbedThumbnail.AddThumbnailPreview(customThumbnail);
customThumbnail.TabbedThumbnailBitmapRequested += customThumbnail_TabbedThumbnailBitmapRequested;
}
private Bitmap GenerateBitmap()
{
Bitmap bitmap = new Bitmap(150, 150);
using (var g = Graphics.FromImage(bitmap))
{
g.DrawImage(Properties.Resources.tx, new Rectangle(0,0,150,150));
}
return bitmap;
}
void customThumbnail_TabbedThumbnailBitmapRequested(object sender, TabbedThumbnailBitmapRequestedEventArgs e)
{
var bitmap = GenerateBitmap();
customThumbnail.SetImage(bitmap);
ThreadPool.QueueUserWorkItem(c =>
{
Thread.Sleep(2000);
this.Invoke(new MethodInvoker(InvalidateThumbnail));
});
}
private void InvalidateThumbnail()
{
customThumbnail.InvalidatePreview();
}
modified 29-May-17 10:35am.
|
|
|
|
|
|
Your question made no sense at all.
|
|
|
|
|
Hi all,
i have declared a string below which will be a switch to a command.
string prnportpatha=@"\\servername\apps\Utilities\AddPrinter\prnport.vbs";
how do i call the variable in a command as per below
proc.StartInfo.FileName=("cmd.exe");
proc.StartInfo.Arguments=("/k cscript " + prnportpatha);
this doesnt seem to work, i get the error:
the name prnportpatha does not exist inthe current context.
|
|
|
|
|
When you get an error message like:
the name prnportpatha does not exist inthe current context. What the compiler is saying is "I looked for something called 'prnportpatha' everywhere that I can, but I can't find it".
Normally there are two reasons for this:
1) You spelled it wrong. Check: C# is case sensitive, so "prnportpatha" is not the same as "prnPortPatha".
2) It's not in scope. This is complicated, but if you declare a variable, you can't use it outside the same set of curly brackets:
if (myCondition)
{
string s = "hello";
Console.WriteLine(s);
}
Console.WriteLine(s);
This applies to all declarations: fields, properties, methods, events, delegates, ... everything. Once it goes out of scope, you can't access it directly. There are ways to access public (and protected, and internal) items via the class name (for static items, or via an instance (for non-static items) but generally speaking, unless it is in the same scope (or set of curly brackets, basically) you can't access it.
If you can't work it out from that, you need to post the relevant code fragments and we will look at them.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
here is the code fragment.
static void Main()
{
string prnportpatha=@"\\servername\apps\Utilities\AddPrinter\prnport.vbs";
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents=false;
proc.StartInfo.FileName=("cmd.exe");
proc.StartInfo.Arguments=("/k cscript prnportpatha, " -a -r IP_"+ip+" -h "+ip+" -o raw -n 9100");
proc.Start();
MessageBox.Show("Printer Installed");
}
|
|
|
|
|
In your sample-code the string belongs (only) to the Main-method.
As OG has told you (in his sample-code) : the string is outside the Main-method not existant for other methods.
So you should declare it outside the Main-method and see what happens ...
|
|
|
|
|
And the definition is inside the curly brackets for the main method: which means it's scope is that method, and that method only - it isn't available outside at all.
You could try declaring it outside the method:
private string prnportpatha=@"\\auoa1ws1001\apps\Utilities\AddPrinter\prnport.vbs";
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
.... But it's a bad idea to "hard-code" strings anyway - the actual string you set it to should be in a configuration file that is loaded in your main method so you don't have to recompile your application when it changes (and it will, it will...)
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
You have two problems here:
1. Your string is declared in method Main , so it is not visible in method button1_Click .
2. You have included the name prnportpatha inside quotes in your setting of proc.StartInfo.Arguments .
You need to move the string declaration outside of Main so it is visible to all methods of your Form class. Also you need to fix your parameters so it creates the correctly formatted argument string.
|
|
|
|
|
I know how to say:
public class MyClass<T>
{
}
But is it possible to specify that T must have a certain base class? What is the syntax for that?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
|
Thanks so much, Griff.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
No problem!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Message Closed
modified 28-May-17 16:30pm.
|
|
|
|