I have 6 XDocuments:
XDocument parametersXDoc = new XDocument(new XElement(file.Root.Element("ArrayOfParameter")));
XDocument criteriaXDoc = new XDocument(new XElement(file.Root.Element("ArrayOfCriteria")));
XDocument sortfieldsXDoc = new XDocument(new XElement(file.Root.Element("ArrayOfSortField")));
XDocument selectedfieldsXDoc = new XDocument(new XElement(file.Root.Element("ArrayOfSelectedField")));
XDocument reportlayoutXDoc = new XDocument(new XElement(file.Root.Element("ReportLayout")));
XDocument dictionaryXDoc = new XDocument(new XElement(file.Root.Element("Dictionary")));
I want to pass them all to a method as an argument. I could pass them as an array, but then I would need to know the position/index of the XDocument I require - this seems messy.
Is it possible to create a temporary wrapper object on the fly (with properties) that point to each of the XDocument variables and pass this instead?
NET Framework 4.0 có khả năng đơn giản hóa viết ứng dụng bằng việc cung cấp các thành phần có sẵn. NET Framework 4.0 về máy để khám phá và trải nghiệm nhiều chức năng hấp dẫn. 1. Giới thiệu về .Net frame work 4.0 2. Tính năng chính của Microsoft.NET Framework 3. So sánh NET Farmework 4.0 với phiên bản khác
The Microsoft .NET Framework 4 web installer package downloads and installs the .NET Framework components required to run on the target machine architecture and OS. An Internet connection is required during the installation. The Client Profile is used to run most client applications that target the .NET Framework 4.
The Microsoft .NET Framework 4 redistributable package installs the .NET Framework runtime and associated files that are required to run and develop applications to target the .NET Framework 4. The .NET Framework is Microsoft's comprehensive and consistent programming model for building applications that have visually stunning user experiences, ...
The Microsoft .NET Framework 4 Client Profile provides a subset of features from the .NET Framework 4. The Client Profile is designed to run client applications and to enable the fastest possible deployment for Windows Presentation Foundation (WPF) and Windows Forms technology.
You can create and manipulate dynamic objects on the fly, using the dynamic
keyword or ExpandoObject in .NET4.0. The dynamic keyword is extremely powerful.
An OpenSource example of how it can be used successfully in a data-access layer can be found in the PetaPoco micro-ORM.
From MSDN:
Visual C# 2010 introduces a new type, dynamic. The type is a static type, but an object of type dynamic bypasses static type checking. In most cases, it functions like it has type object. At compile time, an element that is typed as dynamic is assumed to support any operation
ExpandoObject Code example
using System;
using System.Dynamic;
using System.Xml.Linq;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Creation and population of the ExpandoObject
// Add as many or few properties as you like.
// Property Types are set at runtime and for the lifetime of the
// property
// Expando objects also support dynamic methods.
dynamic wrapper = new ExpandoObject();
wrapper.FirstProperty = "Hello";
wrapper.SecondProperty = "Dynamic";
wrapper.AnotherProperty = "World!";
wrapper.AnyTypeProperty = 1234;
wrapper.XDocumentProperty = new XDocument();
// etc
// Passing of ExpandoObject
PassWrapperToFunction(wrapper);
Console.ReadLine();
}
// ..
// Function signature of recipient
private static void PassWrapperToFunction(dynamic wrapper)
{
Console.WriteLine("{0} {1} {2} {3}\n",
wrapper.FirstProperty,
wrapper.SecondProperty,
wrapper.AnotherProperty,
wrapper.AnyTypeProperty);
Console.WriteLine("Parameter types:\n{0}\n{1}\n{2}\n{3}\n{4}",
wrapper.FirstProperty.GetType(),
wrapper.SecondProperty.GetType(),
wrapper.AnotherProperty.GetType(),
wrapper.AnyTypeProperty.GetType(),
wrapper.XDocumentProperty.GetType());
}
}
}
Output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With