Lukas00990 2021-09-16 17:54 采纳率: 40.8%
浏览 83
已结题

C#如何构建对象,get 还是 new object

请问下,下面这个类如何构建对象呢?

#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}

  • 写回答

2条回答 默认 最新

  • dark9spring 2021-09-16 18:43
    关注

    单例需要找到并调用类内实例,在类里面已经声明好了对象且构造函数已经私有化。

        [Serializable]
        public sealed class MySingleton : Singleton<MySingleton>
        {
            public int Value { get; set; }
    
            private MySingleton()
            {
            }
        }
    

    需要new的类无构造函数或构造函数权限不为private。
    看你放出的代码没有构造函数,就是用编译器自动生成的无参构造函数,所以是需要new的。

    评论

报告相同问题?

问题事件

  • 系统已结题 9月24日
  • 创建了问题 9月16日

悬赏问题

  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 用matlab 实现通信仿真
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档