请问下,下面这个类如何构建对象呢?
#region Assembly Siemens.Engineering, Version=16.0.0.0, Culture=neutral, PublicKeyToken=d29ec89bac048f84
// C:\Program Files\Siemens\Automation\Portal V16\PublicAPI\V16\Siemens.Engineering.dll
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Security;
namespace Siemens.Engineering.SW.Blocks
{
//
// Summary:
// Group containing Plc system blocks & Plc system block groups
[DebuggerNonUserCode]
[SecuritySafeCritical]
public sealed class PlcSystemBlockGroup : IEngineeringObject, IEngineeringCompositionOrObject, IEngineeringInstance, IInternalObjectAccess, IInternalInstanceAccess, IInternalBaseAccess, IEquatable<object>
{
//
// Summary:
// Composition of Plc system blocks
public PlcBlockComposition Blocks { get; }
//
// Summary:
// Composition of Plc system block groups
public PlcSystemBlockGroupComposition Groups { get; }
//
// Summary:
// EOM parent of this object
public IEngineeringObject Parent { get; }
//
// Summary:
// The name of the Plc system block group
public string Name { get; }
//
// Summary:
// Determines whether the specified System.Object is equal to this instance.
//
// Parameters:
// obj:
// The System.Object to compare with this instance.
//
// Returns:
// true if the specified System.Object is equal to this instance; otherwise, false.
[SecuritySafeCritical]
public override bool Equals(object obj);
//
// Summary:
// Gets a list of attributes for the given names.
//
// Parameters:
// names:
// The names of the attributes to get.
//
// Returns:
// A list of the attributes for the given names with nulls for names not found.
[SecuritySafeCritical]
public IList<object> GetAttributes(IEnumerable<string> names);
//
// Summary:
// Returns a hash code for this instance.
//
// Returns:
// A hash code for this instance, suitable for use in hashing algorithms and data
// structures like a hash table.
[SecuritySafeCritical]
public override int GetHashCode();
//
// Summary:
// Sets a list of values for the given attributes.
//
// Parameters:
// attributes:
// The attributes value list.
[SecuritySafeCritical]
public void SetAttributes(IEnumerable<KeyValuePair<string, object>> attributes);
//
// Summary:
// Returns a System.String that represents the current System.Object.
//
// Returns:
// A System.String that represents the current System.Object.
[SecuritySafeCritical]
public override string ToString();
}
}
构建的对象要满足下列条件,value是{Siemens.Engineering.SW.Blocks.PlcBlockSystemGroup}, type是 object{Siemens.Engineering.SW.Blocks.PlcBlockSystemGroup}
单例需要找到并调用类内实例,在类里面已经声明好了对象且构造函数已经私有化。
[Serializable]
public sealed class MySingleton : Singleton<MySingleton>
{
public int Value { get; set; }
private MySingleton()
{
}
}
需要new的类无构造函数或构造函数权限不为private。
看你放出的代码没有构造函数,就是用编译器自动生成的无参构造函数,所以是需要new的。
这个还是同样的问题,没有构造函数无法新建对象。有的对象是只有工厂能制造出来而不是外部能构造的。你的需求都是要不就是从xml构造(叶子结点),要不就是从树上得到(组节点)。