Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:54:15+00:00 2026-05-31T09:54:15+00:00

sorry for my stupidity but I’m looking for a way to construct an object

  • 0

sorry for my stupidity but I’m looking for a way to construct an object from a class that connects to a service and also contains another class with methods for the service.

The problem I’m facing is trying to figure out a way to only have to connect to the service once. I refuse to use global variables and the likes.

I’m finding it difficult understanding the object concepts in C# as my programming background mainly comes from JavaScript.

Any help is most appreciated.

namespace Tests.Classes
{
    public class L
    {
        dynamic uri;
        dynamic service;
        dynamic credentials;
        dynamic proxy;

        public L L()
        {
            this.uri = new Uri("bladie bladie blah");
            this.credentials = new ClientCredentials();
            this.credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
            this.proxy = new OrganizationServiceProxy(this.uri, null, this.credentials, null);
            this.service = (IOrganizationService)this.proxy;
            return this;
        }

        public class OL
        {
            public OL OL(dynamic a)
            {
                this.service = parent.service; // <- doesn't compile
                return this;
            }
        }
    }
}

To make it clear how it’s called:

var l = new L();
l.OL("haha");

Maybe my code isn’t clear enough. This will keep the categorization fanatics at bay :P.

namespace Tests.Classes
{
    public class L
    {
        Uri uri;
        IOrganizationService service;
        ClientCredentials credentials;
        OrganizationServiceProxy proxy;

        public L L()
        {
            this.uri = new Uri("hBladie Bladie Blah");
            this.credentials = new ClientCredentials();
            this.credentials.Windows.ClientCredential = (NetworkCredential)CredentialCache.DefaultCredentials;
            this.proxy = new OrganizationServiceProxy(this.uri, null, this.credentials, null);
            this.service = (IOrganizationService)this.proxy;

            return this;
        }

        public class OL
        {
            Entity entity = new Entity();
            IOrganizationService service = null;

            public OL OL(dynamic a)
            {
                if (a is Entity)
                {
                    this.entity = a;
                }
                if (a is string)
                {
                    this.entity = new Entity(a);
                }

                return this;
            }

            public OL attr(dynamic key, dynamic value)
            {
                this.entity[key] = value;
                return this;
            }

            public Boolean save()
            {
                this.parent.service.create(this.entity); // parent does not exist
            }
        }
    }
}

I hate messy programming, I love jQuery style.

Here’s how the code has to be used:

new L().OL("haha").attr("Hello", "world").save();

or

var l = new L();
l.OL("HAHA").attr("foo", "bar").save();
l.OL("pff").attr("boppa", "deebop").save();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:54:16+00:00Added an answer on May 31, 2026 at 9:54 am

    That would have worked in Java. In C#, you need to pass L to OL’s constructor:

    public OL(dynamic O, L parent)
    {
       this.service = parent.service;
    }
    

    By the way, your constructor won’t compile, you have two OLs there, and a return.

    By the way 2, why are you using so many dynamics?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry, guys.I am quite new in mysql but I do need help from getting
Sorry for real stupid question. But it does not work either way. <html> <head>
Sorry for the simple question, but I'm trying to find an elegant way to
Sorry to ask something that others have already asked. But when I use the
sorry but Im unable to understand these example. I started learning ajax right from
Is there a way to block the mouse/keybord from .NET but System-wide? I tried
Sorry if this is a repeat, but I've been looking for an answer to
Sorry for this not being a real question, but Sometime back i remember seeing
Sorry the title isn't more help. I have a database of media-file URLs that
Sorry for my ignorance here, but when I hear the word webserver, I immediately

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.