我有以下型号:
namespace WebQuoter.Models
{
public class Chiller
{
public class GeneralInformation
{
public string AssemblyID { get; set; }
public string Model { get; set; }
public string Series { get; set; }
public string Revision { get; set; }
public string Application { get; set; }
public string PreviousAssyID { get; set; }
public bool AvailbleInQuoter { get; set; }
public bool NeedsUpdates { get; set; }
public bool Obsolete { get; set; }
public string EngineeringWorkRequestNo { get; set; }
public string Customer { get; set; }
public string CustomerMachineModel { get; set; }
public string CustomerPartNumber { get; set; }
public string PrimaryVoltage { get; set; }
public string SecondaryVoltage { get; set; }
public string GeneralNotes { get; set; }
public string ChillerNotes { get; set; }
}
public class Cooling
{
public string Refrigerant { get; set; }
public string RefrigerantCapacity { get; set; }
public string CompressorType { get; set; }
public string CompressorHP { get; set; }
public string CondenserType { get; set; }
public string Fan { get; set; }
}
public class FluidCircuit
{
public class PrimaryCircuit
{
public string CoolingCapacity { get; set; }
public string FlowRate { get; set; }
public string PumpPressure { get; set; }
}
public class SecondaryCircuit
{
public string CoolingCapacity { get; set; }
public string FlowRate { get; set; }
public string PumpPressure { get; set; }
}
public string FluidTemperature { get; set; }
public string TemperatureStability { get; set; }
public string SensorLocation { get; set; }
public string PumpHorsePower { get; set; }
public string CoolingMedium { get; set; }
public string TankCapacity { get; set; }
public string TankMaterialOfConstruction { get; set; }
public string TankType { get; set; }
public string FluidConnections { get; set; }
public string FluidConnectionsSize { get; set; }
public string FluidConnectionsUnitOfMeasure { get; set; }
public string WettedComponentMaterial { get; set; }
public string Evaporator { get; set; }
public string GaugeType { get; set; }
}
public class ClimateData
{
public string SiteOfInstallation { get; set; }
public string AmbientConditions { get; set; }
public string SoundLevel { get; set; }
}
public class Controller
{
public class PrimaryVoltage
{
public string Voltage { get; set; }
public string Phases { get; set; }
public string Frequency { get; set; }
public string ControlVoltage { get; set; }
}
public class SecondaryVoltage
{
public string Voltage { get; set; }
public string Phases { get; set; }
public string Frequency { get; set; }
}
public class CertificationsStandards
{
public string UL1995 { get; set; }
public string CE { get; set; }
public string NFPA79 { get; set; }
public string CSA { get; set; }
public string UL508A { get; set; }
public string AdditionalCertifications { get; set; }
}
public string FullLoadedAmps { get; set; }
public string DisconnectFuseSize { get; set; }
public string FalseSignalAlarm { get; set; }
public string ControllerType { get; set; }
}
public class AdditionalData
{
public string WidthAirInletSideWithIncludedOptions { get; set; }
public string DepthWithIncludedOptions { get; set; }
public string HeightWithIncludedOptions { get; set; }
public string Finish { get; set; }
public string CratedWeight { get; set; }
public string WetWeight { get; set; }
public string ExportWeight { get; set; }
}
public class Features
{
public string BypassType { get; set; }
public string FluidFilter { get; set; }
public string FlowSwitch { get; set; }
public string FluidLevelSwitch { get; set; }
public string AutoMakeUp { get; set; }
public string CapacityControl { get; set; }
public string AntiBackFlow { get; set; }
public string FluidHeater { get; set; }
public string RefrigerantSightGlass { get; set; }
public string AmbientTracking { get; set; }
public string FeetCasters { get; set; }
public string FillPort { get; set; }
public string TankLevelSightGlass { get; set; }
public string RefrigerantFilterDryer { get; set; }
public string AirFilter { get; set; }
public string WireConnection { get; set; }
public string RemoteControls { get; set; }
public string SpecialFeatures { get; set; }
public string NominalCondensorSize { get; set; }
public string FluidSetPointRange { get; set; }
public string NominalCoilSize { get; set; }
public string NomalBTUPerHour { get; set; }
public string CabinetType { get; set; }
public string Tank { get; set; }
public string SaltwaterPackage { get; set; }
public string HeaderSize { get; set; }
public string PanelType { get; set; }
public string SwitchoverType { get; set; }
public string Pump { get; set; }
public string PumpCurve { get; set; }
public string HeatRejectionType { get; set; }
public string NumberOfFluidCircuits { get; set; }
}
}
}
以下控制器代码访问此模型:
using Jitbit.Utils;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using WebQuoter.Models;
namespace WebQuoter.BusinessLayer
{
public Chiller ParseValues(List<string> Values)
{
Chiller retVal = new Chiller();
foreach(string value in Values)
{
string[] seperated = Regex.Split(value, "{EPDMSEPERATOR}");
switch (seperated[0])
{
case "07":
retVal.GeneralInformation.AssemblyID = "";
break;
}
}
return retVal;
}
}
}
在以下行中:
retVal.GeneralInformation.AssemblyID = "";
我收到错误:
&#39; GeneralInformation&#39;:不能通过表达式引用类型; 尝试WebQuoter.Models.Chiller.GeneralInformation&#39;代替。
我所看到的每个地方都说不要使用关键字Static。我没有在任何地方使用静态引用这个自定义类。
非常感谢任何帮助!
答案 0 :(得分:0)
这里的问题是您有嵌套类但没有实例,例如:
public class TopLevel
{
public class InsideClass
{
public string SomeProperty { get; set; }
}
}
除非InsideClass
为static
,否则您无法访问SomeProperty
。您需要创建该类的实例:
public class TopLevel
{
public class InsideClass
{
public string SomeProperty { get; set; }
}
public InsideClass MyInsideClass { get; set; }
public TopLevel()
{
MyInsideClass = new InsideClass();
}
}
现在您可以通过实例访问SomeProperty
:
var myOutside = new TopLevel();
myOutside.MyInsideClass.SomeProperty = "Some Value";
创建嵌套类不会自动使嵌套类成为外部类的Member
。