You've already forked linux-packaging-mono
Imported Upstream version 4.0.0~alpha1
Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
@ -0,0 +1,128 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="BidirectionalDictionary.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.Data.Entity.Design.PluralizationServices
|
||||
{
|
||||
/// <summary>
|
||||
/// This class provide service for both the singularization and pluralization, it takes the word pairs
|
||||
/// in the ctor following the rules that the first one is singular and the second one is plural.
|
||||
/// </summary>
|
||||
internal class BidirectionalDictionary<TFirst, TSecond>
|
||||
{
|
||||
internal Dictionary<TFirst, TSecond> FirstToSecondDictionary { get; set; }
|
||||
internal Dictionary<TSecond, TFirst> SecondToFirstDictionary { get; set; }
|
||||
|
||||
internal BidirectionalDictionary()
|
||||
{
|
||||
this.FirstToSecondDictionary = new Dictionary<TFirst, TSecond>();
|
||||
this.SecondToFirstDictionary = new Dictionary<TSecond, TFirst>();
|
||||
}
|
||||
|
||||
internal BidirectionalDictionary(Dictionary<TFirst,TSecond> firstToSecondDictionary) : this()
|
||||
{
|
||||
foreach (var key in firstToSecondDictionary.Keys)
|
||||
{
|
||||
this.AddValue(key, firstToSecondDictionary[key]);
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual bool ExistsInFirst(TFirst value)
|
||||
{
|
||||
if (this.FirstToSecondDictionary.ContainsKey(value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal virtual bool ExistsInSecond(TSecond value)
|
||||
{
|
||||
if (this.SecondToFirstDictionary.ContainsKey(value))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal virtual TSecond GetSecondValue(TFirst value)
|
||||
{
|
||||
if (this.ExistsInFirst(value))
|
||||
{
|
||||
return this.FirstToSecondDictionary[value];
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(TSecond);
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual TFirst GetFirstValue(TSecond value)
|
||||
{
|
||||
if (this.ExistsInSecond(value))
|
||||
{
|
||||
return this.SecondToFirstDictionary[value];
|
||||
}
|
||||
else
|
||||
{
|
||||
return default(TFirst);
|
||||
}
|
||||
}
|
||||
|
||||
internal void AddValue(TFirst firstValue, TSecond secondValue)
|
||||
{
|
||||
this.FirstToSecondDictionary.Add(firstValue, secondValue);
|
||||
|
||||
if (!this.SecondToFirstDictionary.ContainsKey(secondValue))
|
||||
{
|
||||
this.SecondToFirstDictionary.Add(secondValue, firstValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class StringBidirectionalDictionary : BidirectionalDictionary<string, string>
|
||||
{
|
||||
|
||||
internal StringBidirectionalDictionary()
|
||||
: base()
|
||||
{ }
|
||||
internal StringBidirectionalDictionary(Dictionary<string, string> firstToSecondDictionary)
|
||||
: base(firstToSecondDictionary)
|
||||
{ }
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
|
||||
internal override bool ExistsInFirst(string value)
|
||||
{
|
||||
return base.ExistsInFirst(value.ToLowerInvariant());
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
|
||||
internal override bool ExistsInSecond(string value)
|
||||
{
|
||||
return base.ExistsInSecond(value.ToLowerInvariant());
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
|
||||
internal override string GetFirstValue(string value)
|
||||
{
|
||||
return base.GetFirstValue(value.ToLowerInvariant());
|
||||
}
|
||||
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
|
||||
internal override string GetSecondValue(string value)
|
||||
{
|
||||
return base.GetSecondValue(value.ToLowerInvariant());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,67 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="EntityDesignPluralizationHandler.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Data.Entity.Design.PluralizationServices;
|
||||
using System.Data.Metadata.Edm;
|
||||
using System.IO;
|
||||
using System.Data.Entity.Design.SsdlGenerator;
|
||||
using System.Data.Entity.Design.Common;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace System.Data.Entity.Design
|
||||
{
|
||||
internal class EntityDesignPluralizationHandler
|
||||
{
|
||||
/// <summary>
|
||||
/// user might set the service to null, so we have to check the null when using this property
|
||||
/// </summary>
|
||||
internal PluralizationService Service
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handler for pluralization service in Entity Design
|
||||
/// </summary>
|
||||
/// <param name="doPluralization">overall switch for the service, the service only start working when the value is true</param>
|
||||
/// <param name="userDictionaryPath"></param>
|
||||
/// <param name="errors"></param>
|
||||
internal EntityDesignPluralizationHandler(PluralizationService service)
|
||||
{
|
||||
this.Service = service;
|
||||
}
|
||||
|
||||
internal string GetEntityTypeName(string storeTableName)
|
||||
{
|
||||
return this.Service != null ? this.Service.Singularize(storeTableName) : storeTableName;
|
||||
}
|
||||
|
||||
internal string GetEntitySetName(string storeTableName)
|
||||
{
|
||||
return this.Service != null ? this.Service.Pluralize(storeTableName) : storeTableName;
|
||||
}
|
||||
|
||||
internal string GetNavigationPropertyName(AssociationEndMember toEnd, string storeTableName)
|
||||
{
|
||||
if (this.Service != null)
|
||||
{
|
||||
return toEnd.RelationshipMultiplicity == RelationshipMultiplicity.Many ?
|
||||
this.Service.Pluralize(storeTableName) : this.Service.Singularize(storeTableName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return storeTableName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="ICustomPluralizationMapping.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Data.Entity.Design.Common;
|
||||
|
||||
namespace System.Data.Entity.Design.PluralizationServices
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pluralization")]
|
||||
public interface ICustomPluralizationMapping
|
||||
{
|
||||
void AddWord(string singular, string plural);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="PluralizationService.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner venkatja
|
||||
// @backupOwner willa
|
||||
//---------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Globalization;
|
||||
using System.Data.Entity.Design.Common;
|
||||
using System.Data.Entity.Design;
|
||||
|
||||
namespace System.Data.Entity.Design.PluralizationServices
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Pluralization")]
|
||||
public abstract class PluralizationService
|
||||
{
|
||||
public CultureInfo Culture { get; protected set; }
|
||||
|
||||
public abstract bool IsPlural(string word);
|
||||
public abstract bool IsSingular(string word);
|
||||
public abstract string Pluralize(string word);
|
||||
public abstract string Singularize(string word);
|
||||
|
||||
/// <summary>
|
||||
/// Factory method for PluralizationService. Only support english pluralization.
|
||||
/// Please set the PluralizationService on the System.Data.Entity.Design.EntityModelSchemaGenerator
|
||||
/// to extend the service to other locales.
|
||||
/// </summary>
|
||||
/// <param name="culture">CultureInfo</param>
|
||||
/// <returns>PluralizationService</returns>
|
||||
public static PluralizationService CreateService(CultureInfo culture)
|
||||
{
|
||||
EDesignUtil.CheckArgumentNull<CultureInfo>(culture, "culture");
|
||||
|
||||
if (culture.TwoLetterISOLanguageName == "en")
|
||||
{
|
||||
return new EnglishPluralizationService();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException(Strings.UnsupportedLocaleForPluralizationServices(culture.DisplayName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
//---------------------------------------------------------------------
|
||||
// <copyright file="PluralizationServiceUtil.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//
|
||||
// @owner [....]
|
||||
// @backupOwner [....]
|
||||
//---------------------------------------------------------------------
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.Data.Entity.Design.PluralizationServices
|
||||
{
|
||||
internal static class PluralizationServiceUtil
|
||||
{
|
||||
internal static bool DoesWordContainSuffix(string word, IEnumerable<string> suffixes, CultureInfo culture)
|
||||
{
|
||||
return suffixes.Any(s => word.EndsWith(s, true, culture));
|
||||
}
|
||||
|
||||
internal static bool TryInflectOnSuffixInWord(string word, IEnumerable<string> suffixes, Func<string, string> operationOnWord, CultureInfo culture, out string newWord)
|
||||
{
|
||||
newWord = null;
|
||||
|
||||
if (PluralizationServiceUtil.DoesWordContainSuffix(word, suffixes, culture))
|
||||
{
|
||||
newWord = operationOnWord(word);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user