|
Not sure that would work, since the flag would be Disposed at the same time as the rest of it. At best, it would risk problems with consistency once the GC kicked in, wouldn't it?
He could get away with encapsulating a Bitmap, and Disposing that without disposing the outer object, but...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You're right. I guess I didn't engage the brain before the fingers.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
On second thought, I thought the purpose of Dispose is to release unmanaged resources.
The managed memory of an object would remain valid until it goes out of scope, no?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I was thinking about all this when I went to bed last night, and it's really quite nasty. And yes, you are absolutely right: Disposed objects are not deallocated until they go out of scope - My mistake
So I thought Id give it a try today. And got real problems trying to derive a class and dispose it. Until I finally twigged: You can't derive from a Bitmap anyway: it's a sealed class...http://msdn.microsoft.com/en-us/library/system.drawing.bitmap%28v=vs.110%29.aspx[^]
You can derive from non-sealed disposable classes, and add variables (which you are absolutely right, won't be deallocated until they go out of scope), but...MSDN says you shouldn't!
"An ObjectDisposedException is thrown when you try to access a member of an object that implements the IDisposable interface, and that object has been disposed. Typically, this exception is caused by one of the following conditions:" http://msdn.microsoft.com/en-us/library/system.objectdisposedexception(v=vs.110).aspx[^]
So the way I read it is that if an object is Disposed, you should get an exception whenever you try to use it again - I know you don't, but technically you should.
And the OP is back to encapsulation!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
OriginalGriff wrote: Until I finally twigged: You can't derive from a Bitmap anyway: it's a sealed class...
Ahem![^]
Richard Deeming wrote:
The only problem is, you can't write a class derived from Bitmap, as it's sealed.
That'll learn ya to ignore your notifications!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Everyone knows I can't read...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I probably will do something like this. I have some static functions working on Bitmaps in a framework dll anyway. I could Encapsulate a Bitmap object in there that can handle the dispose and hold the bool indicating this.
Not my favorite solution, but for now the best option
|
|
|
|
|
I have a C# project in Visual Studio which has several classes under it. I am trying to run each class separately but when ever I hit the start or debug buttons,only one of the classes (the first one I created) runs.I tried right-clicking the other classes but they don't have the run option. I am using Visual Studio Express 2013
|
|
|
|
|
Let me see if I understood this correctly, you have a console application with a few classes you added on your own ?
If so, you should call functions from your classes in the console application's main function.
Edit: if you have multiple projects, you can just set one as a startup project and run that one.
|
|
|
|
|
|
You can't execute classes. Methods CAN be executed. A console-app will have one (1) method that gets executed when the application starts. From there, you can create other classes and call methods on them.
I'd recommend the book "Head First C#".
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I attempted to create an extension method for a list of my data. For example:
public static class MyExtensions
{
public static List<Foo> GetModified(this List<Foo> list)
{
if ((list == null) || (list.Count == 0))
{
return null;
}
else
{
return list.Where(r => r.IsDirty).ToList();
}
}
}
The code was compiled without any error. The problem is how to consume the feature. The following code does not compile since the extension method can’t be found:
fooList.GetModified();
It appears I need to create a class to wrap up the List of Foo, which is what I try to avoid and keep my code simple. Does anyone know how to call this extension method without create a list wrapper? If not, why doesn’t the compiler present a message for the extension mothed? Is the extension method just syntax correct but can’t be invoked? Sounds odd?
|
|
|
|
|
Add reference and using for the assembly containing the extension method...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
I might be mistaken, but I don't think you can create extension methods for a specific generic type. You need to create it for the generic itself (List<T>) and then add a constraint.
public static List<T> GetModified<T>(this List<T> list)
where T : Foo
{
}
something like that... the IDE will filter intellisense on the constraint as well.
|
|
|
|
|
You are mistaken.
https://dotnetfiddle.net/IzJQpY[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Oh well .
My way is better anyways since you can constraint against multiple interfaces at the same time. You'd have to write a specific exception for each type if you did it your way.
|
|
|
|
|
Interesting, I can't reproduce your compile error in FrameWork 4.5.1. I note the apparently strange fact that you are not assigning the result of the call to 'GetModified to any variable, so the result goes into outer-space.
This works for me:
public static class Extensions
{
public static List<Foo> GetModified(this List<Foo> list)
{
if ((list == null) || (list.Count == 0)) return null;
return list.Where(r => r.GetThisFooDirty()).ToList();
}
}
public class Foo
{
public string Name { private set; get; }
private bool ThisFooIsDirty { set; get; }
public bool GetThisFooDirty() { return ThisFooIsDirty; }
public void SetThisFooDirty(bool dirtyness) { ThisFooIsDirty = dirtyness; }
public Foo(string fooName)
{
Name = fooName;
ThisFooIsDirty = false;
}
} Test:
List<Foo> fooList = new List<Foo>
{
new Foo("foo1"),
new Foo("Foo2"),
new Foo("Foo3")
};
fooList[1].SetThisFooDirty(true);
fooList[2].SetThisFooDirty(true);
var whoIsDirty = fooList.GetModified(); Now, I'm going to go wash my mouth out with soap.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
modified 12-Dec-14 0:09am.
|
|
|
|
|
BillWoodruff wrote: I can't reproduce your compile error in FrameWork 4.5.1.
BillWoodruff wrote: This works for me: That's because from where you have written your "Test" code, the Extensions class is accessible (and so is the extension method).
Your time will come, if you let it be right.
|
|
|
|
|
That's certainly a logical hypothesis: to assume the problem is no-access because (probably) the NameSpace qualifier is missing, and the calling context did not 'import a valid reference that would allow the method to be used without full qualification.
It is true, though, that classes can be defined outside of any 'named NameSpace, and the compiler will stick them in the "global" default NameSpace, although I'd consider any code that used that as probably "smelling"
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Hello all,
I have applied EF Code-First to Existing Database like this :
1- Created an ADO.NET Entity Data Model
2- Chose Code First from Database
All of the classes generated correctly, except there are a lot of [Key] tags before most of the properties. Should I remove them from unnecessary ones?
Another question is, how can I be sure that EF kept the one-to-many or many-to-many relationships? There is nothing like :
public virtual ICollection<Post> Posts { get; set; }
Thanks in advance.
|
|
|
|
|
|
HI,
I want to superimpose two picture boxes and make the top picture box image transparent.
Thanks in advance
|
|
|
|
|
What type of bitmap is in each of the two PictureBoxes: .png with transparency ? or ... ?
There are several ways you can approach this, and I suggest you start by reading/studying this CodeProject article: [^].
And, then, read the discussion here: [^].
If these references don't assist you to get what you want, then please post more details here, and describe what you've tried, and any error messages.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Looking for a simple example (with how to) for a USB plug in and unplug condition. I think I use VID PID?
|
|
|
|