当前位置: 首页>>代码示例>>C#>>正文


C# ExpandoObject类代码示例

本文整理汇总了C#中System.Dynamic.ExpandoObject的典型用法代码示例。如果您正苦于以下问题:C# ExpandoObject类的具体用法?C# ExpandoObject怎么用?C# ExpandoObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExpandoObject类属于System.Dynamic命名空间,在下文中一共展示了ExpandoObject类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1:

sampleObject.test = "Dynamic Property";
Console.WriteLine(sampleObject.test);
Console.WriteLine(sampleObject.test.GetType());
开发者ID:.NET开发者,项目名称:System.Dynamic,代码行数:3,代码来源:ExpandoObject

输出:

Dynamic Property
System.String

示例2:

sampleObject.number = 10;
sampleObject.Increment = (Action)(() => { sampleObject.number++; });

// Before calling the Increment method.
Console.WriteLine(sampleObject.number);

sampleObject.Increment();

// After calling the Increment method.
Console.WriteLine(sampleObject.number);
开发者ID:.NET开发者,项目名称:System.Dynamic,代码行数:10,代码来源:ExpandoObject

输出:

10
11

示例3: Main

class Program
{
    static void Main(string[] args)
    {
        dynamic employee, manager;

        employee = new ExpandoObject();
        employee.Name = "John Smith";
        employee.Age = 33;

        manager = new ExpandoObject();
        manager.Name = "Allison Brown";
        manager.Age = 42;
        manager.TeamSize = 10;

        WritePerson(manager);
        WritePerson(employee);
    }
    private static void WritePerson(dynamic person)
    {
        Console.WriteLine("{0} is {1} years old.",
                          person.Name, person.Age);
        // The following statement causes an exception
        // if you pass the employee object.
        // Console.WriteLine("Manages {0} people", person.TeamSize);
    }
}
开发者ID:.NET开发者,项目名称:System.Dynamic,代码行数:27,代码来源:ExpandoObject

输出:

John Smith is 33 years old.
Allison Brown is 42 years old.

示例4: ExpandoObject

dynamic employee = new ExpandoObject();
employee.Name = "John Smith";
employee.Age = 33;

foreach (var property in (IDictionary<String, Object>)employee)
{
    Console.WriteLine(property.Key + ": " + property.Value);
}
开发者ID:.NET开发者,项目名称:System.Dynamic,代码行数:8,代码来源:ExpandoObject

输出:

Name: John Smith
Age: 33

示例5: ExpandoObject

dynamic employee = new ExpandoObject();
employee.Name = "John Smith";
((IDictionary<String, Object>)employee).Remove("Name");
开发者ID:.NET开发者,项目名称:System.Dynamic,代码行数:3,代码来源:ExpandoObject

示例6: Test

// Add "using System.ComponentModel;" line 
// to the beginning of the file.
class Program
{
    static void Test()
    {
        dynamic employee = new ExpandoObject();
        ((INotifyPropertyChanged)employee).PropertyChanged +=
            new PropertyChangedEventHandler(HandlePropertyChanges);
        employee.Name = "John Smith";
    }

    private static void HandlePropertyChanges(
        object sender, PropertyChangedEventArgs e)
    {
        Console.WriteLine("{0} has changed.", e.PropertyName);
    }
}
开发者ID:.NET开发者,项目名称:System.Dynamic,代码行数:18,代码来源:ExpandoObject


注:本文中的System.Dynamic.ExpandoObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。