コード例 #1
0
        internal static Babl Create(string name,
                                    int id,
                                    int bits,
                                    string doc = "")
        {
            var value = db.Exists(id, name);

            if (id is not 0 && value is null && db.Exists(name) is not null)
            {
                Fatal.AlreadyRegistered(name, nameof(BablType));
            }

            if (value is not null)
            {
                // There is an instance already registerd by the required id/name,
                // returning the preexistent one instead if it doesn't differ.
                if (!((BablType)value).Equals(bits))
                {
                    Fatal.ExistsAsDifferentValue(name, nameof(BablType));
                }
                return(value);
            }

            value = new BablType()
            {
                Name = name,
                Id   = id,
                Bits = bits,
                Doc  = doc
            };
            db.Insert(value);
            return(value);
        }
コード例 #2
0
ファイル: BablComponent.cs プロジェクト: stefanrbk/babl.net
        internal static Babl Create(string name,
                                    int id,
                                    bool hasLuma   = false,
                                    bool hasChroma = false,
                                    bool hasAlpha  = false,
                                    string doc     = "")
        {
            var value = db.Exists(id, name);

            if (id is not 0 && value is null && db.Exists(name) is not null)
            {
                Fatal.AlreadyRegistered(name, nameof(BablComponent));
            }

            if (value is not null)
            {
                // There is an instance already registerd by the required id/name,
                // returning the preexistent one instead if it doesn't differ.
                if (!((BablComponent)value).Equals(hasLuma, hasChroma, hasAlpha))
                {
                    Fatal.ExistsAsDifferentValue(name, nameof(BablComponent));
                }
                return(value);
            }
            value = new BablComponent(name, id, hasLuma, hasChroma, hasAlpha, doc);

            // Since there is not an already registered instance by the required
            // id/name, inserting newly created class into database.
            db.Insert(value);
            return(value);
        }