473,657 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using "My" in C#

I've tried following the simple instructions to be able to use MyServices
within C#...Add a project reference to Microsoft.Visua lBasic.dll and add:
"using Microsoft.Visua lBasic.MyServic es;" to the code module. After that, I
expected to be able to use MyClock or MyComputerInfo, but none of the "My"
stuff appears in the intellisense. I've tried rebuilding (after adding the
reference and the using statement) and still no luck.

What am I doing wrong?

-Scott
Dec 11 '07 #1
8 4727
Scott M. <sm**@nospam.no spamwrote:
I've tried following the simple instructions to be able to use MyServices
within C#...Add a project reference to Microsoft.Visua lBasic.dll and add:
"using Microsoft.Visua lBasic.MyServic es;" to the code module. After that, I
expected to be able to use MyClock or MyComputerInfo, but none of the "My"
stuff appears in the intellisense. I've tried rebuilding (after adding the
reference and the using statement) and still no luck.

What am I doing wrong?
The easiest way to find out what the VB code would do is to compile
some VB and then look at it in ILDASM or Reflector.

However, I've seen that certainly you could use the
Microsoft.Visua lBasic.Devices namespace and create a new instance of
ComputerInfo, for example.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 11 '07 #2
Ah, I see. The article I was looking at indicated that you need an import
to "MyServices ", not "Devices"

http://www.programmersheaven.com/2/C-Sharp-2-Name-Space

Now, it works.

Thanks.


"Jon Skeet [C# MVP]" <sk***@pobox.co mwrote in message
news:MP******** *************@m snews.microsoft .com...
Scott M. <sm**@nospam.no spamwrote:
>I've tried following the simple instructions to be able to use MyServices
within C#...Add a project reference to Microsoft.Visua lBasic.dll and add:
"using Microsoft.Visua lBasic.MyServic es;" to the code module. After
that, I
expected to be able to use MyClock or MyComputerInfo, but none of the
"My"
stuff appears in the intellisense. I've tried rebuilding (after adding
the
reference and the using statement) and still no luck.

What am I doing wrong?

The easiest way to find out what the VB code would do is to compile
some VB and then look at it in ILDASM or Reflector.

However, I've seen that certainly you could use the
Microsoft.Visua lBasic.Devices namespace and create a new instance of
ComputerInfo, for example.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Dec 11 '07 #3
Liz

"Scott M." <sm**@nospam.no spamwrote in message
news:uU******** ******@TK2MSFTN GP05.phx.gbl...
Ah, I see. The article I was looking at indicated that you need an import
to "MyServices ", not "Devices"

http://www.programmersheaven.com/2/C-Sharp-2-Name-Space

Now, it works.

using My = Microsoft.Visua lBasic.Devices;

My.Keyboard kb = new My.Keyboard();

for those who like that "My" feel ...
Dec 11 '07 #4
Am I correct in noticing that the one big difference between using the "My"
keyword/namespace in VB .NET and using the classes within the Devices
namespace in C# is that in C#, you must make an instance of the class before
you can use it, while in VB .NET you don't?
"Liz" <li*@tiredofspa m.comwrote in message
news:u7******** ******@TK2MSFTN GP04.phx.gbl...
>
"Scott M." <sm**@nospam.no spamwrote in message
news:uU******** ******@TK2MSFTN GP05.phx.gbl...
>Ah, I see. The article I was looking at indicated that you need an
import to "MyServices ", not "Devices"

http://www.programmersheaven.com/2/C-Sharp-2-Name-Space

Now, it works.


using My = Microsoft.Visua lBasic.Devices;

My.Keyboard kb = new My.Keyboard();

for those who like that "My" feel ...


Dec 11 '07 #5
Scott M. <sm**@nospam.no spamwrote:
Am I correct in noticing that the one big difference between using the "My"
keyword/namespace in VB .NET and using the classes within the Devices
namespace in C# is that in C#, you must make an instance of the class before
you can use it, while in VB .NET you don't?
I suspect (although I haven't tried it) that the difference is actually
that it's not *clear* that you're creating an instance of the class
before using it in VB - but that it's still doing it under the covers.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Dec 11 '07 #6
Here's a support file that we insert into some VB to C# conversions to cover
aspects of 'My' that aren't converted in-line:
//----------------------------------------------------------------------------------------
// Copyright © 2005 - 2007 Tangible Software Solutions Inc.
//
// This file provides classes to reproduce most of the My.Computer and My.User
// functionality in VB. Calls to My.Computer.Cli pboard,
My.Computer.Fil eSystem,
// and My.Computer.Reg istry have been converted where they were referenced.
//
// Note: My.Settings is converted elsewhere to the standard C#
Properties.Sett ings.
// Note: My.Resources is converted elsewhere to the standard C#
Properties.Reso urces.
// Note: My.Application calls are redirected to the converted
My.MyApplicatio n.
//----------------------------------------------------------------------------------------

using Microsoft.Visua lBasic.Applicat ionServices;
using Microsoft.Visua lBasic.Devices;
using System.Security .Principal;
using System.Windows. Forms;

namespace My
{
internal static class Computer
{
//Instant C# Notes:
//Calls to My.Computer.Cli pboard have been redirected to
System.Windows. Forms.Clipboard
//Calls to My.Computer.Fil eSystem have been redirected to
Microsoft.Visua lBasic.FileIO.F ileSystem
//Calls to My.Computer.Reg istry have been redirected to
Microsoft.Win32 .Registry

internal readonly static Audio Audio;
internal readonly static Clock Clock;
internal readonly static ComputerInfo Info;
internal readonly static Keyboard Keyboard;
internal readonly static Mouse Mouse;
internal readonly static string Name;
internal readonly static Network Network;
internal readonly static Ports Ports;
internal readonly static Screen Screen;

static Computer()
{
Audio = new Audio();
Clock = new Clock();
Info = new ComputerInfo();
Keyboard = new Keyboard();
Mouse = new Mouse();
Network = new Network();
Ports = new Ports();
Screen = Screen.PrimaryS creen;

ServerComputer ThisServerCompu ter = new ServerComputer( );
Name = ThisServerCompu ter.Name;
}
}

internal static class User
{
private static Microsoft.Visua lBasic.Applicat ionServices.Use r ThisUser =
new Microsoft.Visua lBasic.Applicat ionServices.Use r();

internal static IPrincipal CurrentPrincipa l
{
get
{
return ThisUser.Curren tPrincipal;
}
}
internal static bool IsAuthenticated
{
get
{
return ThisUser.IsAuth enticated;
}
}
internal static string Name
{
get
{
return ThisUser.Name;
}
}
internal static void InitializeWithW indowsUser()
{
ThisUser.Initia lizeWithWindows User();
}
internal static bool IsInRole(BuiltI nRole ThisRole)
{
return ThisUser.IsInRo le(ThisRole);
}
internal static bool IsInRole(string ThisRole)
{
return ThisUser.IsInRo le(ThisRole);
}
}
}
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
C++ to Ruby
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB or C# to C++/CLI
"Scott M." wrote:
I've tried following the simple instructions to be able to use MyServices
within C#...Add a project reference to Microsoft.Visua lBasic.dll and add:
"using Microsoft.Visua lBasic.MyServic es;" to the code module. After that, I
expected to be able to use MyClock or MyComputerInfo, but none of the "My"
stuff appears in the intellisense. I've tried rebuilding (after adding the
reference and the using statement) and still no luck.

What am I doing wrong?

-Scott
Dec 11 '07 #7
The "My" namespace is something that is VB.NET compiler specific and depends
on the (VB) project type, a Web project will have a different "My" namespace
than a Forms project for instance, "My" doesn't really exists outside the VB
IDE, that is C# projects won't see it.
That's also why "My" functionality isn't fully supported from other
languages other than VB, from C# you can refer to the Microsoft.Visua lBasic
namespaces like Devices and MyServices and use their classes, but you can't
use the My. syntax.

Willy.
"Scott M." <sm**@nospam.no spamwrote in message
news:eO******** *****@TK2MSFTNG P03.phx.gbl...
Am I correct in noticing that the one big difference between using the
"My" keyword/namespace in VB .NET and using the classes within the Devices
namespace in C# is that in C#, you must make an instance of the class
before you can use it, while in VB .NET you don't?
"Liz" <li*@tiredofspa m.comwrote in message
news:u7******** ******@TK2MSFTN GP04.phx.gbl...
>>
"Scott M." <sm**@nospam.no spamwrote in message
news:uU******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Ah, I see. The article I was looking at indicated that you need an
import to "MyServices ", not "Devices"

http://www.programmersheaven.com/2/C-Sharp-2-Name-Space

Now, it works.


using My = Microsoft.Visua lBasic.Devices;

My.Keyboard kb = new My.Keyboard();

for those who like that "My" feel ...



Dec 11 '07 #8
Thanks!
"David Anton" <Da********@dis cussions.micros oft.comwrote in message
news:62******** *************** ***********@mic rosoft.com...
Here's a support file that we insert into some VB to C# conversions to
cover
aspects of 'My' that aren't converted in-line:
//----------------------------------------------------------------------------------------
// Copyright © 2005 - 2007 Tangible Software Solutions Inc.
//
// This file provides classes to reproduce most of the My.Computer and
My.User
// functionality in VB. Calls to My.Computer.Cli pboard,
My.Computer.Fil eSystem,
// and My.Computer.Reg istry have been converted where they were
referenced.
//
// Note: My.Settings is converted elsewhere to the standard C#
Properties.Sett ings.
// Note: My.Resources is converted elsewhere to the standard C#
Properties.Reso urces.
// Note: My.Application calls are redirected to the converted
My.MyApplicatio n.
//----------------------------------------------------------------------------------------

using Microsoft.Visua lBasic.Applicat ionServices;
using Microsoft.Visua lBasic.Devices;
using System.Security .Principal;
using System.Windows. Forms;

namespace My
{
internal static class Computer
{
//Instant C# Notes:
//Calls to My.Computer.Cli pboard have been redirected to
System.Windows. Forms.Clipboard
//Calls to My.Computer.Fil eSystem have been redirected to
Microsoft.Visua lBasic.FileIO.F ileSystem
//Calls to My.Computer.Reg istry have been redirected to
Microsoft.Win32 .Registry

internal readonly static Audio Audio;
internal readonly static Clock Clock;
internal readonly static ComputerInfo Info;
internal readonly static Keyboard Keyboard;
internal readonly static Mouse Mouse;
internal readonly static string Name;
internal readonly static Network Network;
internal readonly static Ports Ports;
internal readonly static Screen Screen;

static Computer()
{
Audio = new Audio();
Clock = new Clock();
Info = new ComputerInfo();
Keyboard = new Keyboard();
Mouse = new Mouse();
Network = new Network();
Ports = new Ports();
Screen = Screen.PrimaryS creen;

ServerComputer ThisServerCompu ter = new ServerComputer( );
Name = ThisServerCompu ter.Name;
}
}

internal static class User
{
private static Microsoft.Visua lBasic.Applicat ionServices.Use r ThisUser =
new Microsoft.Visua lBasic.Applicat ionServices.Use r();

internal static IPrincipal CurrentPrincipa l
{
get
{
return ThisUser.Curren tPrincipal;
}
}
internal static bool IsAuthenticated
{
get
{
return ThisUser.IsAuth enticated;
}
}
internal static string Name
{
get
{
return ThisUser.Name;
}
}
internal static void InitializeWithW indowsUser()
{
ThisUser.Initia lizeWithWindows User();
}
internal static bool IsInRole(BuiltI nRole ThisRole)
{
return ThisUser.IsInRo le(ThisRole);
}
internal static bool IsInRole(string ThisRole)
{
return ThisUser.IsInRo le(ThisRole);
}
}
}
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
C++ to Ruby
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: convert VB or C# to C++/CLI
"Scott M." wrote:
>I've tried following the simple instructions to be able to use MyServices
within C#...Add a project reference to Microsoft.Visua lBasic.dll and add:
"using Microsoft.Visua lBasic.MyServic es;" to the code module. After
that, I
expected to be able to use MyClock or MyComputerInfo, but none of the
"My"
stuff appears in the intellisense. I've tried rebuilding (after adding
the
reference and the using statement) and still no luck.

What am I doing wrong?

-Scott

Dec 12 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
11657
by: Chris Krasnichuk | last post by:
hello, Does anyone know how I make php work on "my" computer? I made a mistake in my last post so I fixed it here. Chris
0
1314
by: John Phelan | last post by:
It use to work. I created numerous coppies of my MS Access2003 developed application for distribution using both the new "Startup" and "Package and Deployment" wizards (that incudes "autorun" that is automatically customized for my application) that is a part of "Visual Studio Developer Extensions". After burning each CD, I used each copy to test installation on my own machine (after uninstalling each previous test-install of my...
8
4423
by: Just Me | last post by:
1)How can I find the folders like "My Recent Document", "Desktop", "My Pictures",... if I want to store a file there? 2) How can I find the icon for those files if I want to display it? Thanks in advance for any helpful suggestions
4
1538
by: papaja | last post by:
Hi, I posted this on asp.net forums already, but nobody answered it. Here is direct link: http://forums.asp.net/1124640/ShowPost.aspx. Here is the question: I'm using this code in delete command of datagrid: **************** Dataset1.DSataTable1.Rows(e.Item.ItemIndex).Delete() adp.Update(DataSet1)
4
3717
by: Leeor Chernov | last post by:
Hi , I Used the object Excell Application(COM INTEROP) and it is staying as an open process, And the owner(User Name) is ASPNET Altough I try to release it with : System.Runtime.InteropServices.Marshal.ReleaseComObject, And GC.Collect. Every time I am opening a new Excel.Application() , I get more Processes in memory. Note: I am calling the CreateExcellObj each time I am pressing a button from my web page The release Methods sometimes...
42
3131
by: Martin Jørgensen | last post by:
Hi, I'm trying to move a matlab program into c language. For those who knows matlab, this is the line I want to program in c: hx(1:nx,1:ny) = 0; % nx=10, ny=10 It works on a 2-dimensional array (size is 10*10), setting all the values inside the 10*10 matrix to zero. My C-function looks like this:
0
2673
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is mainly a wrapper class. It helps
10
6110
by: Bishoy | last post by:
Hi, In VB.NET there is a keyword called "My" which has a lot of properties collected at it. Is there any equivalent to this "My" in C#? Thank you.
4
2529
by: dougans | last post by:
Hey there, Hope someone can help me, completely stuck with immigrating from php4 to OOP based php5. == index.php -- include(database.inc.php);
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.