|
MyPluginDllClass
{
MyClass _myClass {get; set} = new(this);
public MyPluginDllClass
{
}
public void Test1()
{
}
}
public MyClass
{
MyPluginDllClass _instanceMyPluginDllClass;
public MyClass(MyPluginDllClass param)
{
_instanceMyPluginDllClass = param;
}
public void Test2()
{
_instanceMyPluginDllClass.Test1();
}
}
Hello,
for being able to see all properties in the UI of MyPluginDllClass I would have to instantiate MyClass
as shown above in the properties area of MyPluginDllClass as follows:
MyClass _myClass {get; set} = new(this);
But this does not work, "this" seems to be unknown at this moment in time.
The goal is to use all member functions and properties of MyPluginDllClass within MyClass and to make all properties of MyClass visible in the property grid of the UI of the main application.
Any Ideas, hints what I am doing wrong or why this is the case.
I do not have access to the code of the main application.
MyPluginDllClass ist the interface to the main application.
|
|
|
|
|
You can't use new(this) in a property initializer as the initializer would require the whole object to be initialised by that point, and that cannot be the case because the constructor has not been called yet. And obviously, the constructor can't be called until all property and field initializers are complete!
So you would end up with a deadlock: the instance can't be created because to create the instance you need access to the fully constructed instance!
What you can do is move the initializer to the constructor:
public class Bar
{
public Bar(Foo foo) { }
}
public class Foo
{
public Bar bar {get; set;}
public Foo ()
{
bar = new(this);
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
While I appreciate all the syntactic shortcuts Anders and friends are giving us in the C# language, I feel it's getting a bit ridiculous. We're quickly approaching a point where the shortcuts are making the code unreadable and harder to understand for noobs in favor of making it faster to type.
I suspect the new shortcut is giving the OP trouble in understanding what's going on.
|
|
|
|
|
I agree - the same thing happened to C++ to the point where it's almost unreadable now.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
LOL. I think that's the primary reason why I don't do C++ anymore. That and someone has to pick up my code and maintain it after I'm gone and it's easier to find a C# dev (or Java dev we can convert) than it is to find a C++ dev for the team I'm on.
|
|
|
|
|
Is there a way to exclusively identify email-enabled public folders using Microsoft.Office.Interop.Outlook? EWS or PowerShell should not be used. The program should run on the workstation and utilize the installed Outlook.
Once I've found an email-enabled public folder, I should list the emails contained within it.
So far, I'm encountering difficulties. For instance, I have the following method:
static void ListPublicFolders(Outlook.Folder? folder, string indent)
{
if (folder != null)
{
foreach (object obj in folder.Folders)
{
if (obj is Outlook.Folder)
{
Outlook.Folder? subFolder = obj as Outlook.Folder;
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
{
Outlook.MAPIFolder? parentFolder = subFolder.Parent as Outlook.MAPIFolder;
string parentName = parentFolder != null ? parentFolder.Name : "Parent folder not found";
Console.WriteLine($"{indent}- {subFolder.Name}: {parentName}");
if (parentFolder != null)
{
Marshal.ReleaseComObject(parentFolder);
}
}
ListPublicFolders(subFolder, indent + " ");
if (subFolder != null)
{
Marshal.ReleaseComObject(subFolder);
}
}
}
}
}
The query
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
fails because subFolder.DefaultItemType returns the value Outlook.OlItemType.olPostItem, even though the public folder was set up as an email-enabled folder in Exchange.
Specifically, this is in Microsoft 365. In the Exchange admin center, when creating the folder, I explicitly checked the box for "Email-enabled." This action resulted in two additional options: "Delegation" and "Email properties." In "Email properties," I can specify an alias and a display name. By default, both fields are set to "Orders." Now, I expect the public folder to be email-enabled, with the email address orders@domain.tld.
I don't understand why Outlook is treating the folder incorrectly (I can only create posts and not send emails).
Perhaps someone can help me figure this out.
Thank you and best regards,
René
|
|
|
|
|
Hi All,
Stupid Question time. If a value is read to a textbox it is a String, to convert it to a value in the past I have done:
int Value = 0;
Value = Convert.ToInt16(textBox1.Text) I'm sure of it and then done maths and operations on the Value such as:
if(Value > 1000)
{
MessageBox.Show("Here!");
} But it won't run in VS2022 it returns a System.Format.Exception error. What have I done?
Glenn
modified 9-May-24 10:29am.
|
|
|
|
|
Don't use Convert as any error in the format of the input string will cause an exception.
Instead use int.Parse because you can check the result of the parse operation to see if you have entered a valid or invalid string.
From memory you should do the following
if (int.Parse(textBox1.Text, out int result))
{
}
else
{
}
|
|
|
|
|
You mean TryParse ; Parse returns the parsed value or throws an exception.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I checked that twice and still missed that (Doh)
|
|
|
|
|
What value is in the textbox? If it can't be parsed as a short using the current culture settings, then Convert.ToInt16 will throw an exception.
You should use TryParse[^] rather than the Convert method to avoid the "can't parse this" exception:
if (int.TryParse(textBox1.Text, out int value))
{
if (value > 1000)
{
MessageBox.Show("Here!");
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hmmm, I'm reading back a sensor, it's giving values all over the show!
private void button1_Click(object sender, EventArgs e)
{
if (int.TryParse(textBox1.Text, out int value))
{
if (value > 1000)
{
MessageBox.Show("Here!");
}
MessageBox.Show(value.ToString());
}
MessageBox.Show(value.ToString());
}
value is taken as 0, despite textBox1.Text having 1234.56...
|
|
|
|
|
glennPattonWork3 wrote: despite textBox1.Text having 1234.56... But 1234.56 is a Float/Double not an Int ; the two are quite different.
|
|
|
|
|
You are right, but even if make 1234 it still returns a 0...
|
|
|
|
|
Come on Glen, you need to show us the exact code, and the exact text that you are using.
|
|
|
|
|
Hi,
This is the code I have been trying to get all afternoon!
private void button1_Click(object sender, EventArgs e)
{
float ForceVal = 0;
<pre>
decimal.TryParse(weightTxt.Text, out decimal value);
if (value > 1000)
{
MessageBox.Show("Here!");
}
MessageBox.Show(value.ToString());
}
I think that should do it. I'm hacking together a test program that interfaces to a Phidget load cell in trying to measure a value that needs to converted to Newtons from Grams (I think!). I hate the fact I wasted so much time trying to get the value to be used out of a darned label. I haven't really done much Windows code (I'm an embedded guy really) since VS2008 was the new kid on the block and times like these it shows!
|
|
|
|
|
Did the TryParse call succeed, return true?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Sort of I had to:
decimal.TryParse(weightTxt.Text, out decimal value);
as I was messing with a floating point number, haven't coded in Windows for a while, man it shows!
|
|
|
|
|
Maybe try decimal.TryParse()? as the input is not an int.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Thanks, that appears to work!
|
|
|
|
|
Good news!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
I have tried to pass command line arguments to IrfanView to rotate a image, the code is below, the commented code works without a problem. The problem is the uncommented code, when the process is started, there are no errors but no changes are made to the image. I have tried the proper syntax code in VB.NET and it works as expected, any insight as to what's wrong?
//args = file1 + " " + "/rotate_r " + "/convert=" + file2 + "/killmesoftly";
//args = " " + file1 + " " + "/rotate_r " + "/jpgq=100" + "/convert=" + file2 + "/killmesoftly";
args = " " + file1 + " " + "/jpg_rotate=(3,1,0,1,0,0,0,0)" + "/killmesoftly";
|
|
|
|
|
I don't know why newbs always insist on breaking up what should be a single string into a bunch of string concatenations, making it harder to debug your code. You can do this all in one string:
args = $"{file1} /jpg_rotate=(3,1,0,1,0,0,0,0) /killmesoftly";
Take a closer look at your uncommented code:
args = " " + file1 + " " + "/jpg_rotate=(3,1,0,1,0,0,0,0)" + "/killmesoftly";
This will result in an arguments string that looks like this:
[file1]
Notice there is no space before the /killmosoftly switch. That will probably generate an error for the Irfan command.
modified 7-May-24 23:37pm.
|
|
|
|
|
Dave;
Thank you for responding, unfortunately the image was not rotated. As I stated previously the string works in Excel VBA & VB.NET with the correct file location syntax.
Thanks again for your help
|
|
|
|
|
I didn't say I knew anything about Irfan, only that your code is unnecessarily complicated, making it harder to debug.
|
|
|
|