[英]Conversion of C# system type in a custom type
它的 C# 類庫項目。 類只有一個返回字典的函數,
//dictionary definition
Dictionary<string, int> stockLengths = new Dictionary<string, int>();
stockLengths.Add("Length_5000", 0);
stockLengths.Add("Length_3000", 0);
//return statement
Value result = new Value(stockLengths);
return result;
系統調用類庫不接受字典並出現以下錯誤:
"使用配置器類型而不是 System.Type System.Collections.Generic.Dictionary`2[System.String,System.Int32] "
這里 Configurator = 一個自定義軟件,它調用類庫 dll...
我在這里缺少什么,可以將字典的系統類型轉換為任何自定義類型,以便主機系統可以接受返回的數據類型...
// Value struct
public struct Value : IEquatable<Value>
{
public static readonly Value Null;
public Value(string value);
public Value(decimal? value);
public Value(decimal value);
public Value(bool? value);
public Value(bool value);
public Value(IExpressionValue value);
public Value(IExpressionValueCollection value);
public Value(IExpressionValueArray value);
public Value(DataType valueType);
public Value(object value);
public object Data { get; }
public bool HasValue { get; }
public Type ValueType { get; }
public DataType Type { get; }
public IExpressionValueArray AsArray();
public bool AsBoolean();
public IExpressionValueCollection AsCollection();
public bool? AsNullableBoolean();
public decimal? AsNullableNumber();
public string AsNullableString();
public decimal AsNumber();
public string AsString();
public Value Clone();
public Value ConvertTo(DataType type);
public bool ConvertToBoolean();
public bool? ConvertToNullableBoolean();
public decimal? ConvertToNullableNumber();
public string ConvertToNullableString();
public decimal ConvertToNumber();
public string ConvertToString();
public override bool Equals(object obj);
public bool Equals(Value other);
public override int GetHashCode();
public string GetTraceString();
public override string ToString();
public static implicit operator Value(decimal? value);
public static implicit operator Value(bool value);
public static implicit operator Value(bool? value);
public static implicit operator Value(decimal value);
public static implicit operator Value(string value);
}
public interface IExpressionValueCollection : IEnumerable<IExpressionValue>, IEnumerable
{
IExpressionValue this[string key] { get; }
int Count { get; }
IEnumerable<string> Keys { get; }
bool Contains(string key);
IExpressionValue GetOrCreateElement(string key, DataType valueType);
}
public interface IExpressionValue
{
Value Value { get; }
IExpressionValue GetProperty(string identifier);
bool TryGetProperty(string identifier, out IExpressionValue property);
}
public enum DataType
{
Unassigned = 0,
Boolean = 1,
String = 2,
Number = 3,
DateTime = 4,
BooleanArray = 5,
StringArray = 6,
NumberArray = 7,
CollectionArray = 8,
Collection = 9,
UnassignedArray = 10
}
該解決方案在提供的文檔中不可用,當我聯系技術支持時,他們只提供了一個提示,然后通過更多的探索,我能夠成功地將系統數據類型轉換為主機軟件支持的“THE”數據類型......在這里,我提供解決方案,以幫助像我這樣的人:
using TDCI.BuyDesign.Configurator.Engine;
using TDCI.BuyDesign.Configurator.Engine.Expressions;
using TDCI.BuyDesign.Configurator.Engine.RuleEngine;
// sample code to return Collections
var returnCollection = new SimpleExpressionValueCollection();
returnCollection.Add("Length_5000", 5000);
returnCollection.Add("Length_3000", 3000);
Value result = new Value(returnCollection);
return result;
// sample code to return arrays
var returnArrays = new SimpleExpressionValueArray(DataType.String);
returnArrays.Add(new SimpleExpressionValue("Test Value 1"));
returnArrays.Add(new SimpleExpressionValue("Test Value 2"));
returnArrays.Add(new SimpleExpressionValue("Test Value 3"));
Value result = new Value(returnArrays);
return result;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.