在内联C#中编写functoid脚本中使用LINQ概念 [英] Using the LINQ concept in scripting functoid inside inline C#

查看:66
本文介绍了在内联C#中编写functoid脚本中使用LINQ概念的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好, 

hi all, 

我有一个要求,我必须从配置文件中获取电子邮件地址。配置文件存在于公共位置。所以我必须首先阅读它,然后根据键获取属性的值。 

I have a requirement, where i have to fetch the email address from the config file. The config file is present in the common location. So i have to read it first and then fetch the value of the attribute based on the key. 

我已经在使用LINQ的Console应用程序中尝试了它并且它起作用了。 

This i have tried in the Console application using LINQ and it worked. 

现在,我必须在地图中使用它,因为作业在那里发生。 

Now, i have to use this in the map as the assignment happens there. 

我也添加了System.Xml.Linq参考。 

I have added System.Xml.Linq reference as well. 

我收到错误提示""当前上下文中不存在名称'XDocument'"和"无法找到类型或命名空间名称'XDocument'"

我可以使用内联c#并提供我在那里使用的相同代码。

Can i use inline c# and give the same code i used there.

我的代码如下:

public string GetConfig()

{

XDocument xdoc = XDocument.Load(@" D:\Config \ ApplicationApptings.config");
$


var levels =来自xdoc.Elements中的level1 ("配置")。元素("ApplicationSettings")。后代("添加")

                       选择新的$
                        {

                            key = level.Attribute(" key")。Value,

                            value = level.Attribute(" value")。值

                       };

            string myvalue = string.Empty;

            foreach(级别中的var级别)

        {

        if(level.key ==" Mail")

                                        {myvalue = level.value;}

                         }

返回myvalue;

}

public string GetConfig()
{
XDocument xdoc = XDocument.Load(@"D:\Config\ApplicationSettings.config");

var levels = from level1 in xdoc.Elements("configuration").Elements("ApplicationSettings").Descendants("add")
                       select new
                       {
                           key = level.Attribute("key").Value,
                           value = level.Attribute("value").Value
                       };
            string myvalue = string.Empty;
           foreach (var level in levels)
       {
       if(level.key =="Mail")
                                        {myvalue=level.value;}
                         }
return myvalue;
}

请在这方面帮助我。如果可以以简单的方式完成,我不想使用外部装配。

Kindly help me in this regard. I dont want to use external assembly if it can be done in simple way.

谢谢和问候, 

Thanks and Regards, 

Veena Handadi

Veena Handadi







推荐答案

你不会在内联脚本下使用它。

You wont be ablt to have this under inline scripts.

你能做什么do在类中使用此方法,然后在scrpting functoid中使用外部程序集/方法调用。

What u can do is have this method in a class and then use external assembly/method call in the scrpting functoid.





这篇关于在内联C#中编写functoid脚本中使用LINQ概念的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆