Ejemplo n.º 1
0
 static bool P_TryParse(string metadataPathName, out string validationMessage, out string parsedValue, out MetadataName[] parsedComponents)
 {
     if (!(metadataPathName is null))
     {
         if (P_TryGetFromCache(metadataPathName, out var fromCacheInstance))
         {
             validationMessage = null;
             parsedValue       = fromCacheInstance._value;
             parsedComponents  = fromCacheInstance._components;
             return(true);
         }
     }
     //
     if (IsValid(metadataPathName, out validationMessage))
     {
         var components = metadataPathName.Split(ComponentDelimiter);
         if (components.Length > MaxComponentCount)
         {
             parsedValue       = null;
             parsedComponents  = null;
             validationMessage = FormatXResource(typeof(InvalidMetadataNameException), "PathNameContainsTooManyComponents", metadataPathName, components.Length, MaxComponentCount);
             return(false);
         }
         parsedValue      = metadataPathName;
         parsedComponents = new MetadataName[components.Length];
         for (var i = 0; i < components.Length; ++i)
         {
             parsedComponents[i] = MetadataName.CreateUnsafe(components[i]);
         }
         return(true);
     }
     else
     {
         parsedValue      = null;
         parsedComponents = null;
         return(false);
     }
 }
Ejemplo n.º 2
0
 protected MetadataBase(MetadataName name)
 {
     _name = name is null ? null : new P_Name(name: name, isAutoName: false);
     //
     P_Initialize(resetGuid: true);
 }
Ejemplo n.º 3
0
        public bool Resolve(IMetadata @base, IMetadataReference reference, out IMetadata metadata)
        {
            @base.EnsureNotNull(nameof(@base));
            var pathNameReference =
                reference
                .EnsureNotNull(nameof(reference))
                .EnsureOfType <IMetadataReference, IMetadataPathNameReference>()
                .Value;
            //
            var requiredMetadataType = pathNameReference.TargetMetadataType;
            var name = pathNameReference.Name;
            var firstNameComponent = true;
            var currentSearchPlace = @base;
            var locMetadata        = default(IMetadata);

            foreach (var currentComponentName in name.Components)
            {
                if (firstNameComponent)
                {
                    locMetadata =
                        currentSearchPlace
                        .Sequence()
                        .Concat(currentSearchPlace.Parent.Sequence())
                        .Concat(currentSearchPlace.Siblings)
                        .Concat(currentSearchPlace.Children)
                        .Concat(currentSearchPlace.Ancestors.Skip(1))
                        .Where(i => MetadataName.Equals(i?.Name, currentComponentName))
                        .FirstOrDefault();
                    firstNameComponent = false;
                }
                else
                {
                    locMetadata =
                        currentSearchPlace
                        .Children
                        .Where(i => MetadataName.Equals(i.Name, currentComponentName))
                        .FirstOrDefault();
                }
                if (locMetadata == null)
                {
                    break;
                }
                else
                {
                    currentSearchPlace = locMetadata;
                }
            }
            if (locMetadata == null)
            {
                metadata = null;
                return(false);
            }
            else if (requiredMetadataType.IsAssignableFrom(locMetadata.GetType()))
            {
                metadata = locMetadata;
                return(true);
            }
            else
            {
                throw new MetadataNotCompliantReferenceException(reference, locMetadata);
            }
        }
Ejemplo n.º 4
0
 public Namespace(MetadataName name)
     : base(name)
 {
 }