/*
         * Create a generic-purpose reference.
         */
        private ITES5Referencer CreateReference(string referenceName, TES5BasicType?typeForNewProperty, string?tes4ReferenceNameForType, TES5GlobalScope globalScope, TES5MultipleScriptsScope multipleScriptsScope, TES5LocalScope localScope)
        {
            if (TES5PlayerReference.EqualsPlayer(referenceName))
            {
                return(CreateReferenceToPlayer(globalScope));
            }

            Match match = ReferenceAndPropertyNameRegex.Match(referenceName);

            if (match.Success)
            {
                TES5ObjectProperty propertyReference = this.objectPropertyFactory.CreateObjectProperty(match.Groups[1].Value, match.Groups[2].Value, this, localScope, globalScope, multipleScriptsScope);
                return(propertyReference);
            }

            ITES5VariableOrProperty?property = localScope.TryGetVariable(referenceName);

            if (property == null)
            {
                property = globalScope.TryGetPropertyByOriginalName(referenceName); //todo rethink how to unify the prefix searching
                if (property == null)
                {
                    Nullable <int> tes4FormID   = null;
                    ITES5Type      propertyType =
                        typeForNewProperty != null ? typeForNewProperty :
                        GetPropertyTypeAndFormID(referenceName, tes4ReferenceNameForType, globalScope, multipleScriptsScope, out tes4FormID);
                    TES5Property propertyToAddToGlobalScope = TES5PropertyFactory.ConstructWithTES4FormID(referenceName, propertyType, referenceName, tes4FormID);
                    globalScope.AddProperty(propertyToAddToGlobalScope);
                    property = propertyToAddToGlobalScope;
                }
            }

            return(CreateReferenceToVariableOrProperty(property));
        }