Exemple #1
0
 public EnumFieldHandler(Type enumType)
 {
     if (!IsCompatibleWith(enumType)) throw new ArgumentException("enumType");
     _enumType = enumType;
     var ec = new EnumConfiguration(enumType);
     _signed = ec.Signed;
     _configuration = ec.ToConfiguration();
 }
Exemple #2
0
 public EnumFieldHandler(byte[] configuration)
 {
     _configuration = configuration;
     var ec = new EnumConfiguration(configuration);
     _signed = ec.Signed;
 }
Exemple #3
0
 public bool Equals(EnumConfiguration other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return other._flags.Equals(_flags)
         && _names.SequenceEqual(other._names)
         && _values.SequenceEqual(other._values);
 }
Exemple #4
0
 public bool IsSubsetOf(EnumConfiguration targetCfg)
 {
     if (_flags != targetCfg._flags) return false;
     var targetDict =
         targetCfg.Names.Zip(targetCfg.Values, (k, v) => new KeyValuePair<string, ulong>(k, v))
         .ToDictionary(p => p.Key, p => p.Value);
     for (int i = 0; i < _names.Length; i++)
     {
         ulong targetValue;
         if (!targetDict.TryGetValue(_names[i], out targetValue)) return false;
         if (_values[i] != targetValue) return false;
     }
     return true;
 }
        //────────────────────────────────────────
        /// <summary>
        /// ノード名を指定して、直近の親ノードを取得したい。
        /// </summary>
        /// <param name="sName"></param>
        /// <param name="enumConf">「Configuration_Node」「Configurationtree_Node」のいずれか。</param>
        /// <param name="bRequired">偽を指定した時は、不一致の時ヌルを返す。</param>
        /// <param name="log_Reports"></param>
        /// <returns></returns>
        public virtual Configuration_Node GetParentByNodename(
            string sName, EnumConfiguration enumConf, bool bRequired, Log_Reports log_Reports)
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);
            log_Method.BeginMethod(Info_Syntax.Name_Library, this, "GetParentByNodename", log_Reports);
            //
            //
            Configuration_Node result;

            Configuration_Node err_Parent_Conf;
            if (log_Reports.Successful)
            {
                if (null != this.Parent)
                {
                    // 親要素があるとき

                    if (sName == this.Parent.Name)
                    {
                        // ノード名が一致
                        result = this.Parent;
                    }
                    else
                    {
                        // ノード名が一致しないとき
                        result = this.Parent.GetParentByNodename(sName, enumConf, bRequired, log_Reports);
                    }
                }
                else
                {
                    // 親要素がないとき

                    result = null;
                    err_Parent_Conf = null;
                    goto gt_Error_NotFoundParent;
                }
            }
            else
            {
                // 既にエラーが出ているとき

                result = null;
            }

            if (enumConf == EnumConfiguration.Tree)
            {
                if (!(result is Configurationtree_Node))
                {
                    //エラー
                    goto gt_Error_AnotherClass;
                }
            }
            else if (enumConf == EnumConfiguration.Unknown)
            {
                if (!(result is Configuration_Node))
                {
                    //エラー
                    goto gt_Error_AnotherClass;
                }
            }
            else
            {
                //エラー
                goto gt_Error_UnsupportedConfigurationType;
            }

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_NotFoundParent:
            if (log_Reports.CanCreateReport)
            {
                if (bRequired)
                {
                    Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                    r.SetTitle("▲エラー501!", log_Method);

                    Log_TextIndented s = new Log_TextIndentedImpl();
                    s.Append("親要素の取得に失敗しました。");
                    s.Newline();

                    s.Append("指定ノード名[");
                    s.Append(sName);
                    s.Append("]");
                    s.Newline();

                    s.Append("親要素はヌルです。");
                    s.Newline();

                    if (null != err_Parent_Conf)
                    {
                        s.Append("親要素ノード名[");
                        s.Append(err_Parent_Conf.Name);
                        s.Append("]");
                        s.Newline();
                    }

                    // ヒント
                    s.Append(r.Message_Configuration(this));

                    r.Message = s.ToString();
                    log_Reports.EndCreateReport();
                }
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_AnotherClass:
            if (log_Reports.CanCreateReport)
            {
                if (bRequired)
                {
                    Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                    r.SetTitle("▲エラー502!", log_Method);

                    Log_TextIndented s = new Log_TextIndentedImpl();
                    s.Append("(内部プログラム・エラー)取得した親要素は、指定のクラスとは異なりました。");
                    s.Newline();

                    s.Append("指定コンフィグ形[");
                    s.Append(enumConf);
                    s.Append("]");
                    s.Newline();

                    s.Append("取得した親要素のクラス名[");
                    s.Append(result.GetType().Name);
                    s.Append("]");
                    s.Newline();

                    // ヒント
                    s.Append(r.Message_Configuration(this));

                    r.Message = s.ToString();
                    log_Reports.EndCreateReport();
                }
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_UnsupportedConfigurationType:
            if (log_Reports.CanCreateReport)
            {
                if (bRequired)
                {
                    Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                    r.SetTitle("▲エラー503!", log_Method);

                    Log_TextIndented s = new Log_TextIndentedImpl();
                    s.Append("(内部プログラム・エラー)コンフィグ・クラスの指定に対応できませんでした。");
                    s.Newline();

                    s.Append("指定コンフィグ形[");
                    s.Append(enumConf);
                    s.Append("]");
                    s.Newline();

                    //s.Append("取得した親要素のクラス名[");
                    //s.Append(result.GetType().Name);
                    //s.Append("]");
                    //s.Newline();

                    // ヒント
                    s.Append(r.Message_Configuration(this));

                    r.Message = s.ToString();
                    log_Reports.EndCreateReport();
                }
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return result;
        }