Category: confusing

Non (Coding Standards)

 

What do you say when you see this code?

 
Console.WriteLine(((ThirdEnum)(new Task<string>(() => 
{ 
    return ((FirstEnum)((Func<string>)(() => 
    { 
        return "Hello World"; 
    })).Invoke().Invoke()).Invoke(); 
})).Await().ContinueWith((@string) => 
{ 
    return ((SecondEnum)(@string.ContinueWith((@return) => 
    { 
        return ((FirstEnum)(@return.Result.Invoke() + 3)).Invoke(); 
    }).Result.Invoke())).Invoke(); 
}).GetAwaiter().GetResult().Invoke()));

Console.ReadKey();
 
namespace ConfusingCode
{
    public static class Things
    {
        public static int Invoke(this string invokedItem)
        {
            lock (Program.key)
            {
                Console.Write(invokedItem.Length == 1 ? invokedItem + (invokedItem == ((SecondEnum)invokedItem.Length - 1).Invoke() ? invokedItem : "") : "");
            }
            return invokedItem.Length > 0 ? 0 : 0;
        }
        public static Task<string> Await(this Task<string> taskToAwait)
        {
            taskToAwait.Start();
            return taskToAwait;
        }
        public static string Invoke(this FirstEnum val)
        {
            return ((Enum)val).Invoke();
        }
        public static string Invoke(this SecondEnum val)
        {
            return ((Enum)val).Invoke();
        }
        public static string Invoke(this ThirdEnum val)
        {
            return ((Enum)val).Invoke();
        }
        public static string Invoke(this Enum @enum)
        {
            return @enum.ToString();
        }
    }
    public enum FirstEnum
    {
        P = 0,
        I = 3,
    }
    public enum SecondEnum
    {
        Z = 0,        
    }
    public enum ThirdEnum
    {
        A = 0
    }
}

And what should be added to the coding standards in order to not permit this … code ?
( Credits to Stefan Petrini for the code )

ASP.NET MVC–find error

I am moderator and a frequent answerer at forums.asp.net . Mostly of time the error is in thinking that database connection errors belong to MVC – or other things that are part of the .NET framework, not of MVC . However , I must write here the most confusing problem  that I have encountered:

<start quoting>

“I have an XML file, whose contents I want to display on the browser window using ASP drop down list and LINQ to XML. I am using Visual Studio MVC 4 for this purpose. In the model folder I have created a file to access the XML file, whose contents are :

[… not important code]

In the view folder, I have a asp file as shown

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="MvcApplication7.Controllers.QueryController" CodeBehind="~/Controllers/QueryController.cs" %>


<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <div id="updatePanel">
        <asp:DropDownList runat="server" ID="fragment">
        </asp:DropDownList>

    </div>

</asp:Content>
 

And finally in the Controller folder, I have

 namespace MvcApplication7.Controllers
    {
        public class QueryController : System.Web.UI.Page
        {
            //
            // GET: /Query/

        protected void Page_Load(object sender, EventArgs e)
        {
                fragment.DataSource = MvcApplication7.Models.fragmentNameModels.GetFragmentName();
                fragment.DataTextField = "id";
                fragment.DataValueField = "id";
                fragment.DataBind();
        }
 }
}
 

The ID given to the drop down list is "fragment", but when i use it my controller file I get the following error message :

Error 1 The name 'fragment' does not exist in the current context “

 

<end quoting>

Could you spot the error?

Then re-read the post and found the confusing things that will make assumption that is MVC ( including original poster words, comments and code)

 

( And , if not, the answer is here http://forums.asp.net/t/1974367.aspx?The+name+________+does+not+exist+error+Advice+needed+ASAP+ )