Here are the examples of the csharp api string.CompareTo(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
778 Examples
19
Source : SQLite.cs
with GNU General Public License v3.0
from 0xfd3
with GNU General Public License v3.0
from 0xfd3
public string GetValue(int row_num, string field)
{
int num = -1;
int length = this.field_names.Length - 1;
for (int i = 0; i <= length; i++)
{
if (this.field_names[i].ToLower().CompareTo(field.ToLower()) == 0)
{
num = i;
break;
}
}
if (num == -1)
{
return null;
}
return this.GetValue(row_num, num);
}
19
Source : SQLite.cs
with GNU General Public License v3.0
from 0xfd3
with GNU General Public License v3.0
from 0xfd3
public bool ReadTable(string TableName)
{
int index = -1;
int length = this.master_table_entries.Length - 1;
for (int i = 0; i <= length; i++)
{
if (this.master_table_entries[i].item_name.ToLower().CompareTo(TableName.ToLower()) == 0)
{
index = i;
break;
}
}
if (index == -1)
{
return false;
}
string[] strArray = this.master_table_entries[index].sql_statement.Substring(this.master_table_entries[index].sql_statement.IndexOf("(") + 1).Split(new char[] { ',' });
int num6 = strArray.Length - 1;
for (int j = 0; j <= num6; j++)
{
strArray[j] = (strArray[j]).TrimStart();
int num4 = strArray[j].IndexOf(" ");
if (num4 > 0)
{
strArray[j] = strArray[j].Substring(0, num4);
}
if (strArray[j].IndexOf("UNIQUE") == 0)
{
break;
}
this.field_names = (string[])Utils.CopyArray((Array)this.field_names, new string[j + 1]);
this.field_names[j] = strArray[j];
}
return this.ReadTableFromOffset((ulong)((this.master_table_entries[index].root_num - 1L) * this.page_size));
}
19
Source : LunarTime.cs
with MIT License
from 6tail
with MIT License
from 6tail
public NineStar getNineStar()
{
//顺逆
string solarYmd = lunar.getSolar().toYmd();
Dictionary<string,Solar> jieQi = lunar.getJieQiTable();
bool asc = false;
if (solarYmd.CompareTo(jieQi["冬至"].toYmd()) >= 0 && solarYmd.CompareTo(jieQi["夏至"].toYmd()) < 0)
{
asc = true;
}
int start = asc ? 7 : 3;
string dayZhi = lunar.getDayZhi();
if ("子午卯酉".Contains(dayZhi))
{
start = asc ? 1 : 9;
}
else if ("辰戌丑未".Contains(dayZhi))
{
start = asc ? 4 : 6;
}
int index = asc ? start + zhiIndex - 1 : start - zhiIndex - 1;
if (index > 8)
{
index -= 9;
}
if (index < 0)
{
index += 9;
}
return new NineStar(index);
}
19
Source : FileCache.cs
with Apache License 2.0
from acarteas
with Apache License 2.0
from acarteas
public int CompareTo(CacheItemReference other)
{
int i = LastAccessTime.CompareTo(other.LastAccessTime);
// It's possible, although rare, that two different items will have
// the same LastAccessTime. So in that case, we need to check to see
// if they're actually the same.
if (i == 0)
{
// second order should be length (but from smallest to largest,
// that way we delete smaller files first)
i = -1 * Length.CompareTo(other.Length);
if (i == 0)
{
i = string.Compare(Region, other.Region);
if (i == 0)
{
i = Key.CompareTo(other.Key);
}
}
}
return i;
}
19
Source : HashedFileCacheManager.cs
with Apache License 2.0
from acarteas
with Apache License 2.0
from acarteas
private string GetFileName(string key, string regionName = null)
{
if (regionName == null)
{
regionName = "";
}
//CacheItemPolicies have references to the original key, which is why we look there. This implies that
//manually deleting a policy in the file system has dire implications for any keys that probe after
//the policy. It also means that deleting a policy file makes the related .dat "invisible" to FC.
string directory = Path.Combine(CacheDir, PolicySubFolder, regionName);
string hash = ComputeHash(key);
int hashCounter = 0;
string fileName = Path.Combine(directory, string.Format("{0}_{1}.policy", hash, hashCounter));
bool found = false;
while (found == false)
{
fileName = Path.Combine(directory, string.Format("{0}_{1}.policy", hash, hashCounter));
if (File.Exists(fileName) == true)
{
//check for correct key
try
{
SerializableCacheItemPolicy policy = DeserializePolicyData(fileName);
if (key.CompareTo(policy.Key) == 0)
{
//correct key found!
found = true;
}
else
{
//wrong key, try again
hashCounter++;
}
}
catch
{
//Corrupt file? replacedume usable for current key.
found = true;
}
}
else
{
//key not found, must not exist. Return last generated file name.
found = true;
}
}
return Path.GetFileNameWithoutExtension(fileName);
}
19
Source : Feature.cs
with Microsoft Public License
from achimismaili
with Microsoft Public License
from achimismaili
public int CompareTo(object obj)
{
if (obj is Feature)
{
int iVal = 0;
int oVal = 0;
switch (this.Scope)
{
case SPFeatureScope.Farm:
iVal += 100; break;
case SPFeatureScope.WebApplication:
iVal += 200; break;
case SPFeatureScope.Site:
iVal += 300; break;
case SPFeatureScope.Web:
iVal += 400; break;
default:
iVal += 500; break;
}
switch (((Feature)obj).Scope)
{
case SPFeatureScope.Farm:
oVal += 100; break;
case SPFeatureScope.WebApplication:
oVal += 200; break;
case SPFeatureScope.Site:
oVal += 300; break;
case SPFeatureScope.Web:
oVal += 400; break;
default:
oVal += 500; break;
}
if (this.Name != null)
{
iVal += this.Name.CompareTo(((Feature)obj).Name);
}
// if iVal is higher than oVal in value, it will be far down in the list ...
return (iVal - oVal);
}
else
throw (new System.ArgumentException("Object is not a Feature like the instance"));
}
19
Source : CrmMetadataDataSourceView.cs
with MIT License
from Adoxio
with MIT License
from Adoxio
public IEnumerable ExecuteSelect(
string enreplacedyName,
string attributeName,
string sortExpression,
EnreplacedyFilters enreplacedyFlags,
EnreplacedyFilters metadataFlags,
out int rowsAffected)
{
rowsAffected = 0;
IEnumerable result = null;
var client = OrganizationServiceContextFactory.Create(Owner.CrmDataContextName);
if (!string.IsNullOrEmpty(enreplacedyName) && !string.IsNullOrEmpty(attributeName))
{
Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "RetrieveAttributeMetadata: enreplacedyName={0}, attributeName={1}, sortExpression={2}", enreplacedyName, attributeName, sortExpression);
var metadata = client.RetrieveAttribute(enreplacedyName, attributeName);
if (metadata is PicklistAttributeMetadata)
{
var picklist = metadata as PicklistAttributeMetadata;
var options = picklist.OptionSet.Options.ToArray();
if (!string.IsNullOrEmpty(sortExpression))
{
Array.Sort(
options,
delegate(OptionMetadata x, OptionMetadata y)
{
int comparison = 0;
if (sortExpression.StartsWith("Value") || sortExpression.StartsWith("OptionValue"))
comparison = x.Value.Value.CompareTo(y.Value.Value);
else if (sortExpression.StartsWith("Label") || sortExpression.StartsWith("OptionLabel"))
comparison = x.Label.UserLocalizedLabel.Label.CompareTo(y.Label.UserLocalizedLabel.Label);
return (!sortExpression.EndsWith("DESC") ? comparison : -comparison);
});
}
result = options.Select(option => new { OptionLabel = option.Label.UserLocalizedLabel.Label, OptionValue = option.Value });
rowsAffected = options.Length;
}
else if (metadata is StatusAttributeMetadata)
{
var status = metadata as StatusAttributeMetadata;
var options = (StatusOptionMetadata[])status.OptionSet.Options.ToArray();
if (!string.IsNullOrEmpty(sortExpression))
{
Array.Sort(
options,
delegate(StatusOptionMetadata x, StatusOptionMetadata y)
{
int comparison = 0;
if (sortExpression.StartsWith("Value") || sortExpression.StartsWith("OptionValue"))
comparison = x.Value.Value.CompareTo(y.Value.Value);
else if (sortExpression.StartsWith("Label") || sortExpression.StartsWith("OptionLabel"))
comparison = x.Label.UserLocalizedLabel.Label.CompareTo(y.Label.UserLocalizedLabel.Label);
else if (sortExpression.StartsWith("State"))
comparison = x.State.Value.CompareTo(y.State.Value);
return (!sortExpression.EndsWith("DESC") ? comparison : -comparison);
});
}
result = options.Select(option => new { OptionLabel = option.Label.UserLocalizedLabel.Label, OptionValue = option.Value });
rowsAffected = options.Length;
}
else if (metadata is StateAttributeMetadata)
{
var state = metadata as StateAttributeMetadata;
var options = (StateOptionMetadata[])state.OptionSet.Options.ToArray();
if (!string.IsNullOrEmpty(sortExpression))
{
Array.Sort(
options,
delegate(StateOptionMetadata x, StateOptionMetadata y)
{
int comparison = 0;
if (sortExpression.StartsWith("Value") || sortExpression.StartsWith("OptionValue"))
comparison = x.Value.Value.CompareTo(y.Value.Value);
else if (sortExpression.StartsWith("Label") || sortExpression.StartsWith("OptionLabel"))
comparison = x.Label.UserLocalizedLabel.Label.CompareTo(y.Label.UserLocalizedLabel.Label);
else if (sortExpression.StartsWith("DefaultStatus"))
comparison = x.DefaultStatus.Value.CompareTo(y.DefaultStatus.Value);
return (!sortExpression.EndsWith("DESC") ? comparison : -comparison);
});
}
result = options.Select(option => new { OptionLabel = option.Label.UserLocalizedLabel.Label, OptionValue = option.Value });
rowsAffected = options.Length;
}
}
else if (!string.IsNullOrEmpty(enreplacedyName))
{
Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "RetrieveEnreplacedyMetadata: enreplacedyName={0}, enreplacedyFlags={1}", enreplacedyName, enreplacedyFlags);
var metadata = client.RetrieveEnreplacedy(enreplacedyName, enreplacedyFlags);
result = metadata.Attributes;
rowsAffected = metadata.Attributes.Length;
}
else
{
Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "RetrieveMetadata: metadataFlags={0}", metadataFlags);
var metadata = client.RetrieveAllEnreplacedies(metadataFlags);
result = metadata;
rowsAffected = metadata.Length;
}
return result;
}
19
Source : UIAtlas.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
private static int CompareString(string a, string b)
{
return a.CompareTo(b);
}
19
Source : InventoryPanel.cs
with GNU General Public License v3.0
from aenemenate
with GNU General Public License v3.0
from aenemenate
public static bool RenderInventory() // display handling
{
int heightOfItems = inventoryItems.Count;
int itemPortHeight = Program.Console.Height - 8 - ( displayingEquipment ? equipmentStartY : 3 );
itemsPerPage = itemPortHeight / padding;
Point mousePos = new Point( SadConsole.Global.MouseState.ScreenPosition.X / SadConsole.Global.FontDefault.Size.X,
SadConsole.Global.MouseState.ScreenPosition.Y / SadConsole.Global.FontDefault.Size.Y );
float bgAlpha = 0.99F, fgAlpha = 0.99F;
Color textColor = new Color( Color.White, fgAlpha );
Color highlightedColor = new Color( Color.Green, bgAlpha );
Color bgColor = new Color( darkerColor, bgAlpha );
// FUNCTIONS
void AddEquipment()
{
if (Program.Player.Body.MainHand != null)
equipment.Add( Program.Player.Body.MainHand );
if (Program.Player.Body.OffHand != null)
equipment.Add( Program.Player.Body.OffHand );
if (Program.Player.Body.Helmet != null)
equipment.Add( Program.Player.Body.Helmet );
if (Program.Player.Body.ChestPiece != null)
equipment.Add( Program.Player.Body.ChestPiece );
if (Program.Player.Body.Shirt != null)
equipment.Add( Program.Player.Body.Shirt );
if (Program.Player.Body.Gauntlets != null)
equipment.Add( Program.Player.Body.Gauntlets );
if (Program.Player.Body.Leggings != null)
equipment.Add( Program.Player.Body.Leggings );
if (Program.Player.Body.Boots != null)
equipment.Add( Program.Player.Body.Boots );
}
string AddEquipSlotToName( string name, int index )
{
if (Program.Player.Body.MainHand != null
&& name.CompareTo( Program.Player.Body.MainHand.Name ) == 0)
name = $"main hand: {name}";
else if (Program.Player.Body.OffHand != null
&& name.CompareTo( Program.Player.Body.OffHand.Name ) == 0)
name = $"off hand: {name}";
else if (Program.Player.Body.Helmet != null
&& name.CompareTo( Program.Player.Body.Helmet.Name ) == 0)
name = $"head: {name}";
else if (Program.Player.Body.ChestPiece != null
&& name.CompareTo( Program.Player.Body.ChestPiece.Name ) == 0)
name = $"chest: {name}";
else if (Program.Player.Body.Shirt != null
&& name.CompareTo( Program.Player.Body.Shirt.Name ) == 0)
name = $"shirt: {name}";
else if (Program.Player.Body.Gauntlets != null
&& name.CompareTo( Program.Player.Body.Gauntlets.Name ) == 0)
name = $"hands: {name}";
else if (Program.Player.Body.Leggings != null
&& name.CompareTo( Program.Player.Body.Leggings.Name ) == 0)
name = $"legs: {name}";
else if (Program.Player.Body.Boots != null
&& name.CompareTo( Program.Player.Body.Boots.Name ) == 0)
name = $"feet: {name}";
return name;
}
void ConvertInventoryForDisplay()
{
// items are stored in the inventory on an individual basis.
// they are displayed in chunks that have a counter
inventoryCount = new Dictionary<string, int>();
inventoryItems = new List<Item>();
bool InventoryItemsContains( Item item )
{
foreach (Item i in inventoryItems)
if (item.Name == i.Name)
return true;
return false;
}
Program.Player.Inventory.Sort();
foreach (Item item in Program.Player.Inventory)
{
if (!InventoryItemsContains( item ))
{
inventoryCount[item.Name] = 1;
inventoryItems.Add( item );
} else
inventoryCount[item.Name] += 1;
}
}
void DetermineInventoryPages()
{
if (itemPortHeight % padding != 0)
itemsPerPage += 1;
inventoryPages = heightOfItems / itemsPerPage;
if (heightOfItems % itemsPerPage != 0)
inventoryPages += 1;
if (invCurrentPage > inventoryPages - 1 & heightOfItems > 2)
invCurrentPage = inventoryPages - 1;
}
void DetermineEquipmentPages()
{
equipmentPages = 1;
equipmentPages = equipment.Count / equipmentPerPage;
if (equipment.Count % equipmentPerPage != 0)
equipmentPages += 1;
if (equipCurrentPage > equipmentPages - 1 & equipment.Count > 2)
equipCurrentPage = equipmentPages - 1;
}
void PrintHeader()
{
// fill the background
for (int i = 0; i < width; i++)
for (int j = 0; j < Program.Console.Height; j++)
GUI.Console.SetGlyph( i, j, ' ', bgColor, bgColor );
// print the header
GUI.Console.Print( width / 2 - "INVENTORY".Length / 2, 1, "INVENTORY", textColor );
// print the right page turning button
GUI.Console.Print( width - 2, 1, " ", textColor, bgColor );
if (mousePos.Equals( new Point( ( width - 2 ), 1 ) ))
bgColor = highlightedColor * 0.95F;
if (inventoryPages > 1 && invCurrentPage < inventoryPages - 1)
GUI.Console.Print( width - 2, 1, ">", textColor, bgColor );
bgColor = new Color( darkerColor, bgAlpha );
// print the left page turning button
GUI.Console.Print( 1, 1, " ", textColor, bgColor );
if (mousePos.Equals( new Point( 1, 1 ) ))
bgColor = highlightedColor * 0.95F;
if (inventoryPages > 1 && invCurrentPage > 0)
GUI.Console.Print( 1, 1, "<", textColor, bgColor );
bgColor = new Color( color, bgAlpha );
}
bool PrintInventory()
{
ConvertInventoryForDisplay();
DetermineInventoryPages();
bool highlighting = false;
bool highlighted = false;
for (int i = 0, index = 0 + invCurrentPage * itemsPerPage; i < itemPortHeight; i += padding, index++)
{
string name = "";
bool indexGreaterThanInventory = index >= inventoryItems.Count;
textColor = new Color( Color.AntiqueWhite, fgAlpha );
// this is to clear the line
GUI.Console.Print( 1, 4 + i, " ", new Color( darkerColor, bgAlpha ), new Color( darkerColor, bgAlpha ) );
GUI.Console.Print( 1, 4 + i + 1, " ", new Color( darkerColor, bgAlpha ), new Color( darkerColor, bgAlpha ) );
if (inventoryCount.Any() && !indexGreaterThanInventory)
{
Item item = inventoryItems[index];
name = item.Name;
string invCounter = "x" + inventoryCount[item.Name];
string pt2 = "";
Tuple<string, string> nameParts = Window.SplitNameIfGreaterThanLength( name, pt2, width - 3 - invCounter.Length );
name = nameParts.Item1;
if (nameParts.Item2 != "")
pt2 = nameParts.Item2;
// check if the mouse is on the item that is currently being drawn
if (mousePos.Y >= 3 && mousePos.X >= 1 && mousePos.X <= ( width - 2 ))
if (mousePos.Y - 4 == i || mousePos.Y - 1 - 4 == i)
highlighted = true;
if (item.Identified)
textColor = item.ReturnRarityColor();
if (index % 2 == 0)
bgColor = new Color( color, bgAlpha );
else
bgColor = new Color( lighterColor, bgAlpha );
if (item == currentlyViewedItem)
bgColor = highlightedColor * bgAlpha;
string spaces = "";
for (int c = 0; c <= ( width - 2 ) - ( 1 + name.Length ) - invCounter.Length; c++)
spaces += ' ';
if (highlighted)
{
// print the name's first line
GUI.Console.Print( 1, 4 + i, name + spaces, highlightedColor, bgColor );
// print the count
GUI.Console.Print( width - 1 - invCounter.Length, 4 + i, invCounter, textColor, bgColor );
// print / clear the name's second line
GUI.Console.Print( 1, 4 + i + 1, " ", textColor, bgColor );
if (pt2 != "")
GUI.Console.Print( 1, 4 + i + 1, pt2, highlightedColor, bgColor );
highlighting = true;
} else
{
// print the name's first line
GUI.Console.Print( 1, 4 + i, name + spaces, textColor, bgColor );
// print the count
GUI.Console.Print( width - 1 - invCounter.Length, 4 + i, invCounter, textColor, bgColor );
// print / clear the name's second line
GUI.Console.Print( 1, 4 + i + 1, " ", textColor, bgColor );
if (pt2 != "")
GUI.Console.Print( 1, 4 + i + 1, pt2, textColor, bgColor );
}
}
highlighted = false;
}
return highlighting;
}
bool PrintEquipment()
{
string equipmentreplacedle = " EQUIPMENT ";
if (displayingEquipment)
equipmentreplacedle = (char)31 + equipmentreplacedle + (char)31;
else
equipmentreplacedle = (char)30 + equipmentreplacedle + (char)30;
GUI.Console.Print( width / 2 - " EQUIPMENT ".Length / 2, equipmentStartY - 2, equipmentreplacedle, textColor );
if (!displayingEquipment)
return false;
DetermineEquipmentPages();
bgColor = new Color( darkerColor, bgAlpha );
// print the right page turning button
GUI.Console.Print( width - 2, equipmentStartY - 2, " ", textColor, bgColor );
if (mousePos.Equals( new Point( width - 2, equipmentStartY - 2 ) ))
bgColor = highlightedColor * 0.95F;
if (equipmentPages > 1 && equipCurrentPage < equipmentPages - 1)
GUI.Console.Print( width - 2, equipmentStartY - 2, ">", textColor, bgColor );
bgColor = new Color( darkerColor, bgAlpha );
// print the left page turning button
GUI.Console.Print( 1, equipmentStartY - 2, " ", textColor, bgColor );
if (mousePos.Equals( new Point( 1, equipmentStartY - 2 ) ))
bgColor = highlightedColor * 0.95F;
if (equipmentPages > 1 && equipCurrentPage > 0)
GUI.Console.Print( 1, equipmentStartY - 2, "<", textColor, bgColor );
bgColor = new Color( color, bgAlpha );
bool highlighting = false;
bool highlighted = false;
for (int i = 0, index = 0 + equipCurrentPage * equipmentPerPage; i < equipmentLen; i += padding, index++)
{
string name = "";
bool indexGreaterThanPlayersItems = index >= equipment.Count;
textColor = new Color( Color.AntiqueWhite, bgAlpha );
// this is to clear the line
GUI.Console.Print( 1, equipmentStartY + i, " ", new Color( darkerColor, bgAlpha ), new Color( darkerColor, bgAlpha ) );
GUI.Console.Print( 1, equipmentStartY + i + 1, " ", new Color( darkerColor, bgAlpha ), new Color( darkerColor, bgAlpha ) );
if (equipment.Any() && !indexGreaterThanPlayersItems)
{
Item item = equipment[index];
name = AddEquipSlotToName( item.Name, index );
string pt2 = "";
Tuple<string, string> nameParts = Window.SplitNameIfGreaterThanLength( name, pt2, StatusPanel.Width - 2 );
name = nameParts.Item1;
if (name[name.Length - 1] == ' ')
name = name.Substring( 0, name.Length - 1 );
if (nameParts.Item2 != "")
pt2 = nameParts.Item2;
// check if the mouse is on the item that is currently being drawn
if (mousePos.X >= 1 && mousePos.X <= ( width - 1 ))
if (mousePos.Y - equipmentStartY == i || mousePos.Y - 1 - equipmentStartY == i)
highlighted = true;
if (item.Identified)
textColor = new Color( item.ReturnRarityColor(), bgAlpha );
bgColor = index % 2 == 0 ? new Color( color, bgAlpha ) : new Color( lighterColor, bgAlpha );
if (item == currentlyViewedItem)
bgColor = new Color( highlightedColor * 0.95F, bgAlpha );
string spaces = "";
for (int c = 0; c < ( StatusPanel.Width - 2 ) - name.Length; c++)
spaces += ' ';
if (highlighted)
{
// print the name's first line
GUI.Console.Print( 1, equipmentStartY + i, name + spaces, highlightedColor, bgColor );
// print / clear the name's second line
GUI.Console.Print( 1, equipmentStartY + i + 1, " ", bgColor, bgColor );
if (pt2 != "")
GUI.Console.Print( 1, equipmentStartY + i + 1, pt2, highlightedColor, bgColor );
highlighting = true;
} else
{
// print the name's first line
GUI.Console.Print( 1, equipmentStartY + i, name + spaces, textColor, bgColor );
// print / clear the name's second line
GUI.Console.Print( 1, equipmentStartY + i + 1, " ", textColor, bgColor );
if (pt2 != "")
GUI.Console.Print( 1, equipmentStartY + i + 1, pt2, textColor, bgColor );
}
}
highlighted = false;
}
return highlighting;
}
// START
equipment = new List<Item>();
AddEquipment();
PrintHeader();
// print the gold
int goldX = width - 1 - $"gold: {Program.Player.Gold}".Length;
GUI.Console.Print( goldX, Program.Console.Height - 2, $"gold: {Program.Player.Gold}", textColor );
return PrintInventory() | PrintEquipment();
}
19
Source : Element.cs
with GNU General Public License v3.0
from aenemenate
with GNU General Public License v3.0
from aenemenate
public int CompareTo(Element other)
{
if (this is Item item) {
if (other is Item otherI)
return item.Name.CompareTo(otherI.Name);
else
return item.Name.CompareTo(other.Name);
}
else {
if (other is Item otherI)
return Name.CompareTo(otherI.Name);
else return Name.CompareTo(other.Name);
}
}
19
Source : Element.cs
with GNU General Public License v3.0
from aenemenate
with GNU General Public License v3.0
from aenemenate
public int CompareTo(Element other)
{
if (this is Item item) {
if (other is Item otherI)
return item.Name.CompareTo(otherI.Name);
else
return item.Name.CompareTo(other.Name);
}
else {
if (other is Item otherI)
return Name.CompareTo(otherI.Name);
else return Name.CompareTo(other.Name);
}
}
19
Source : ArrayList.cs
with Mozilla Public License 2.0
from ahyahy
with Mozilla Public License 2.0
from ahyahy
public int Compare(object x, object y)
{
x2 = OneScriptForms.DefineTypeIValue(x);
y2 = OneScriptForms.DefineTypeIValue(y);
int num = 0;
if (sortType == 3)//Boolean
{
if ((x2.GetType() != typeof(System.Boolean)) && (y2.GetType() != typeof(System.Boolean)))
{
num = 0;
}
else if ((x2.GetType() != typeof(System.Boolean)) && (y2.GetType() == typeof(System.Boolean)))
{
num = 1;
}
else if ((x2.GetType() == typeof(System.Boolean)) && (y2.GetType() != typeof(System.Boolean)))
{
num = -1;
}
else
{
num = ((System.Boolean)x2).CompareTo((System.Boolean)y2);
if (sortOrder == 0)
{
num = 0;
}
else if (sortOrder == 1)
{
}
else if (sortOrder == 2)
{
num = -num;
}
}
}
if (sortType == 2)//DateTime
{
if ((x2.GetType() != typeof(System.DateTime)) && (y2.GetType() != typeof(System.DateTime)))
{
num = 0;
}
else if ((x2.GetType() != typeof(System.DateTime)) && (y2.GetType() == typeof(System.DateTime)))
{
num = 1;
}
else if ((x2.GetType() == typeof(System.DateTime)) && (y2.GetType() != typeof(System.DateTime)))
{
num = -1;
}
else
{
num = ((System.DateTime)x2).CompareTo((System.DateTime)y2);
if (sortOrder == 0)
{
num = 0;
}
else if (sortOrder == 1)
{
}
else if (sortOrder == 2)
{
num = -num;
}
}
}
else if (sortType == 1)//Number
{
if ((x2.GetType() != typeof(System.Decimal)) && (y2.GetType() != typeof(System.Decimal)))
{
num = 0;
}
else if ((x2.GetType() != typeof(System.Decimal)) && (y2.GetType() == typeof(System.Decimal)))
{
num = 1;
}
else if ((x2.GetType() == typeof(System.Decimal)) && (y2.GetType() != typeof(System.Decimal)))
{
num = -1;
}
else
{
num = ((System.Decimal)x2).CompareTo((System.Decimal)y2);
if (sortOrder == 0)
{
num = 0;
}
else if (sortOrder == 1)
{
}
else if (sortOrder == 2)
{
num = -num;
}
}
}
else if (sortType == 0)// text
{
if ((x2.GetType() != typeof(System.String)) && (y2.GetType() != typeof(System.String)))
{
num = 0;
}
else if ((x2.GetType() != typeof(System.String)) && (y2.GetType() == typeof(System.String)))
{
num = 1;
}
else if ((x2.GetType() == typeof(System.String)) && (y2.GetType() != typeof(System.String)))
{
num = -1;
}
else
{
num = ((System.String)x2).CompareTo((System.String)y2);
if (sortOrder == 0)
{
num = 0;
}
else if (sortOrder == 1)
{
}
else if (sortOrder == 2)
{
num = -num;
}
}
}
return num;
}
19
Source : WLEDDevice.cs
with MIT License
from Aircoookie
with MIT License
from Aircoookie
public int CompareTo(object comp) //compares devices in alphabetic order based on name
{
WLEDDevice c = comp as WLEDDevice;
if (c == null || c.Name == null) return 1;
int result = (name.CompareTo(c.name));
if (result != 0) return result;
return (networkAddress.CompareTo(c.networkAddress));
}
19
Source : ImagePacker.cs
with MIT License
from Alan-FGR
with MIT License
from Alan-FGR
public int PackImage(
IEnumerable<string> imageFiles,
bool requirePowerOfTwo,
bool requireSquareImage,
int maximumWidth,
int maximumHeight,
int imagePadding,
bool generateMap,
out Bitmap outputImage,
out Dictionary<string, Rectangle> outputMap)
{
files = new List<string>(imageFiles);
requirePow2 = requirePowerOfTwo;
requireSquare = requireSquareImage;
outputWidth = maximumWidth;
outputHeight = maximumHeight;
padding = imagePadding;
outputImage = null;
outputMap = null;
// make sure our dictionaries are cleared before starting
imageSizes.Clear();
imagePlacement.Clear();
// get the sizes of all the images
foreach (var filePath in files)
{
Bitmap bitmap;
using (var b = new Bitmap(filePath))
{
bitmap = new Bitmap(b); //FIXED! DARN NOOBS LOCKING MY FILESS!!!!! :trollface: - Alan, May 21, 3199BC
b.Dispose();
}
imageSizes.Add(filePath, bitmap.Size);
}
// sort our files by file size so we place large sprites first
files.Sort(
(f1, f2) =>
{
Size b1 = imageSizes[f1];
Size b2 = imageSizes[f2];
int c = -b1.Width.CompareTo(b2.Width);
if (c != 0)
return c;
c = -b1.Height.CompareTo(b2.Height);
if (c != 0)
return c;
return f1.CompareTo(f2);
});
// try to pack the images
if (!PackImageRectangles())
return -2;
// make our output image
outputImage = CreateOutputImage();
if (outputImage == null)
return -3;
if (generateMap)
{
// go through our image placements and replace the width/height found in there with
// each image's actual width/height (since the ones in imagePlacement will have padding)
string[] keys = new string[imagePlacement.Keys.Count];
imagePlacement.Keys.CopyTo(keys, 0);
foreach (var k in keys)
{
// get the actual size
Size s = imageSizes[k];
// get the placement rectangle
Rectangle r = imagePlacement[k];
// set the proper size
r.Width = s.Width;
r.Height = s.Height;
// insert back into the dictionary
imagePlacement[k] = r;
}
// copy the placement dictionary to the output
outputMap = new Dictionary<string, Rectangle>();
foreach (var pair in imagePlacement)
{
outputMap.Add(pair.Key, pair.Value);
}
}
// clear our dictionaries just to free up some memory
imageSizes.Clear();
imagePlacement.Clear();
return 0;
}
19
Source : ExpressionComparer.cs
with MIT License
from albyho
with MIT License
from albyho
protected virtual int CompareType(Type x, Type y)
{
if (x == y) return 0;
if (CompareNull(x, y, out var result)) return result;
result = x.GetHashCode() - y.GetHashCode();
if (result != 0) return result;
result = String.Compare(x.Name, y.Name, StringComparison.Ordinal);
if (result != 0) return result;
return x.replacedemblyQualifiedName.CompareTo(y.replacedemblyQualifiedName);
}
19
Source : ExpressionComparer.cs
with MIT License
from albyho
with MIT License
from albyho
protected virtual int CompareMemberInfo(MemberInfo x, MemberInfo y)
{
if (x == y) return 0;
int result;
if (CompareNull(x, y, out result)) return result;
result = x.GetHashCode() - y.GetHashCode();
if (result != 0) return result;
result = x.MemberType - y.MemberType;
if (result != 0) return result;
result = x.Name.CompareTo(y.Name);
if (result != 0) return result;
result = CompareType(x.DeclaringType, y.DeclaringType);
if (result != 0) return result;
return x.ToString().CompareTo(y.ToString());
}
19
Source : ExpressionComparer.cs
with MIT License
from albyho
with MIT License
from albyho
protected virtual int CompareParameter(ParameterExpression x, ParameterExpression y)
{
return x.Name.CompareTo(y.Name);
}
19
Source : MonoHelper.cs
with GNU General Public License v3.0
from alexgracianoarj
with GNU General Public License v3.0
from alexgracianoarj
public static bool IsOlderVersionThan(string version)
{
version = "Mono " + version;
return (Version.CompareTo(version) < 0);
}
19
Source : ContextMenuItem.cs
with MIT License
from alexismorin
with MIT License
from alexismorin
public int CompareTo( ContextMenuItem item , bool useWeights )
{
if ( useWeights && NodeAttributes.SortOrderPriority > -1 && item.NodeAttributes.SortOrderPriority > -1 )
{
if ( NodeAttributes.SortOrderPriority > item.NodeAttributes.SortOrderPriority )
{
return 1;
}
else if ( NodeAttributes.SortOrderPriority == item.NodeAttributes.SortOrderPriority )
{
return m_name.CompareTo( item.Name );
}
else
{
return -1;
}
}
return m_name.CompareTo( item.Name );
}
19
Source : CollisionGroupsManagerTool.cs
with Apache License 2.0
from Algoryx
with Apache License 2.0
from Algoryx
public int Compare( string a, string b ) { return a.ToLower().CompareTo( b.ToLower() ); }
19
Source : SceneManagerEditor.cs
with Apache License 2.0
from allenai
with Apache License 2.0
from allenai
private static int PartCompare(string x, string y) {
int a, b;
if (int.TryParse(x, out a) && int.TryParse(y, out b))
return a.CompareTo(b);
return x.CompareTo(y);
}
19
Source : YmdString.cs
with MIT License
from ambleside138
with MIT License
from ambleside138
public int CompareTo([AllowNull] YmdString other)
{
if (other == null)
return 1;
return Value.CompareTo(other.Value);
}
19
Source : Country.cs
with GNU General Public License v3.0
from Amebis
with GNU General Public License v3.0
from Amebis
public int CompareTo(object obj)
{
return ToString().CompareTo(obj.ToString());
}
19
Source : StringId.cs
with MIT License
from andrewlock
with MIT License
from andrewlock
public int CompareTo(StringId other) => Value.CompareTo(other.Value);
19
Source : RequestBot.cs
with GNU Lesser General Public License v3.0
from angturil
with GNU Lesser General Public License v3.0
from angturil
int CompareSong(JSONObject song2, JSONObject song1, ref string [] sortorder)
{
int result=0;
foreach (string s in sortorder)
{
string sortby = s.Substring(1);
switch (sortby)
{
case "rating":
case "pp":
//QueueChatMessage($"{song2[sortby].AsFloat} < {song1[sortby].AsFloat}");
result = song2[sortby].AsFloat.CompareTo(song1[sortby].AsFloat);
break;
case "id":
case "version":
// BUG: This hack makes sorting by version and ID sort of work. In reality, we're comparing 1-2 numbers
result=GetBeatSaverId(song2[sortby].Value).PadLeft(6).CompareTo(GetBeatSaverId(song1[sortby].Value).PadLeft(6));
break;
default:
result= song2[sortby].Value.CompareTo(song1[sortby].Value);
break;
}
if (result == 0) continue;
if (s[0] == '-') return -result;
return result;
}
return result;
}
19
Source : NodebuilderInfo.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public int CompareTo(NodebuilderInfo other)
{
// Compare
return name.CompareTo(other.name);
}
19
Source : ImageBrowserItem.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public int CompareTo(ImageBrowserItem other)
{
return this.Text.CompareTo(other.Text);
}
19
Source : ConfigurationInfo.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
public int CompareTo(ConfigurationInfo other)
{
// Compare
return name.CompareTo(other.name);
}
19
Source : ResourceListView.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
protected override void OnDragEnter(DragEventArgs e)
{
// Preplaced on to base
base.OnDragEnter(e);
// Check if our data format is present
if(!e.Data.GetDataPresent(DataFormats.Text))
{
// No effect
e.Effect = DragDropEffects.None;
return;
}
// Check if the data matches our data
String text = (String)e.Data.GetData(DRAG_TYPE.GetType());
if(text.CompareTo(DRAG_TYPE + base.Name) == 0)
{
// We're moving these items
e.Effect = DragDropEffects.Move;
}
else
{
// No effect
e.Effect = DragDropEffects.None;
}
}
19
Source : ResourceListView.cs
with GNU General Public License v3.0
from anotak
with GNU General Public License v3.0
from anotak
protected override void OnDragOver(DragEventArgs e)
{
int dropindex, i;
ListViewItem insertareplacedem;
Point cp;
// Check if our data format is present
if(!e.Data.GetDataPresent(DataFormats.Text))
{
e.Effect = DragDropEffects.None;
return;
}
// Check if the data matches our data
String text = (String)e.Data.GetData(DRAG_TYPE.GetType());
if(text.CompareTo(DRAG_TYPE + this.Name) == 0)
{
// Determine where to insert
cp = base.PointToClient(new Point(e.X, e.Y));
insertareplacedem = base.GereplacedemAt(cp.X, cp.Y);
if(insertareplacedem == null)
{
// Cannot insert here
e.Effect = DragDropEffects.None;
return;
}
// Item is one of the items being dragged?
if(dragitems.Contains(insertareplacedem))
{
// Show move possibility, but dont do anything
e.Effect = DragDropEffects.Move;
insertareplacedem.EnsureVisible();
return;
}
// Check if item is grayed
if(insertareplacedem.ForeColor != SystemColors.WindowText)
{
// Cannot insert here
e.Effect = DragDropEffects.None;
insertareplacedem.EnsureVisible();
return;
}
// Preplaced on to base
base.OnDragOver(e);
// Can insert here
e.Effect = DragDropEffects.Move;
insertareplacedem.EnsureVisible();
// Determine index where to insert
dropindex = insertareplacedem.Index;
if(dropindex > dragitems[0].Index) dropindex++;
// Begin updating
base.BeginUpdate();
// Deselect items
DeselectAll();
// Insert items
for(i = dragitems.Count - 1; i >= 0; i--)
{
// Insert a copy of the item here
base.Items.Insert(dropindex, (ListViewItem)dragitems[i].Clone());
base.Items[dropindex].Selected = true;
}
// Remove old items
foreach(ListViewItem lvi in dragitems)
{
// Remove item from list
base.Items.Remove(lvi);
}
// Copy selected items to the list
dragitems.Clear();
foreach(ListViewItem lvi in base.SelectedItems) dragitems.Add(lvi);
// Done
base.EndUpdate();
}
else
{
// Cannot insert here
e.Effect = DragDropEffects.None;
}
}
19
Source : ResourceName.cs
with GNU General Public License v3.0
from anydream
with GNU General Public License v3.0
from anydream
public int CompareTo(ResourceName other) {
if (HasId != other.HasId) {
// Sort names before ids
return HasName ? -1 : 1;
}
if (HasId)
return id.CompareTo(other.id);
else
return name.ToUpperInvariant().CompareTo(other.name.ToUpperInvariant());
}
19
Source : UTF8String.cs
with GNU General Public License v3.0
from anydream
with GNU General Public License v3.0
from anydream
public int CompareTo(string strB) {
return String.CompareTo(strB);
}
19
Source : Utils.cs
with GNU General Public License v3.0
from anydream
with GNU General Public License v3.0
from anydream
internal static int LocaleCompareTo(UTF8String a, UTF8String b) {
return GetCanonicalLocale(a).CompareTo(GetCanonicalLocale(b));
}
19
Source : Utils.cs
with GNU General Public License v3.0
from anydream
with GNU General Public License v3.0
from anydream
internal static int LocaleCompareTo(UTF8String a, string b) {
return GetCanonicalLocale(a).CompareTo(GetCanonicalLocale(b));
}
19
Source : TestSetup.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public int CompareTo(object obj)
{
int result = -1;
if(obj != null && obj is TestSetupAttribute)
{
TestSetupAttribute other = obj as TestSetupAttribute;
result = this.InstanceName.CompareTo(other.InstanceName);
if (result == 0)
{
result = this.nmsInstanceIds.Length - other.nmsInstanceIds.Length;
}
if(result == 0 && this.nmsInstanceIds.Length != 0)
{
for(int i=0; (i < this.nmsInstanceIds.Length) && result == 0; i++)
{
string id = this.nmsInstanceIds[i];
string otherId = other.nmsInstanceIds[i];
result = id.CompareTo(otherId);
}
}
}
return result;
}
19
Source : Destination.cs
with Apache License 2.0
from apache
with Apache License 2.0
from apache
public int CompareTo(Destination that)
{
int answer = 0;
if (physicalName != that.physicalName)
{
if (physicalName == null)
{
return -1;
}
else if (that.physicalName == null)
{
return 1;
}
answer = physicalName.CompareTo(that.physicalName);
}
if (answer == 0)
{
if (IsTopic)
{
if (that.IsQueue)
{
return 1;
}
}
else
{
if (that.IsTopic)
{
return -1;
}
}
}
return answer;
}
19
Source : GridPortalComponentEditor.cs
with GNU Lesser General Public License v3.0
from ApexGameTools
with GNU Lesser General Public License v3.0
from ApexGameTools
private void ShowActionSelector()
{
var portal = this.target as GridPortalComponent;
object pa = portal.As<IPortalAction>();
if (pa == null)
{
pa = portal.As<IPortalActionFactory>();
}
if (pa == null)
{
if (_actionsList == null)
{
_actionsList = new List<KeyValuePair<string, Type>>();
var asm = replacedembly.Getreplacedembly(typeof(GridPortalComponent));
foreach (var actionType in asm.GetTypes().Where(t => (typeof(IPortalActionFactory).IsreplacedignableFrom(t) || typeof(IPortalAction).IsreplacedignableFrom(t)) && t.IsSubclreplacedOf(typeof(MonoBehaviour)) && t.IsClreplaced && !t.IsAbstract))
{
var actionName = actionType.Name;
var acm = Attribute.GetCustomAttribute(actionType, typeof(AddComponentMenu)) as AddComponentMenu;
if (acm != null)
{
var startIdx = acm.componentMenu.LastIndexOf('/') + 1;
actionName = acm.componentMenu.Substring(startIdx);
}
var pair = new KeyValuePair<string, Type>(actionName, actionType);
_actionsList.Add(pair);
}
_actionsList.Sort((a, b) => a.Key.CompareTo(b.Key));
_actionsNames = _actionsList.Select(p => p.Key).ToArray();
}
EditorGUILayout.Separator();
var style = new GUIStyle(GUI.skin.label);
style.normal.textColor = Color.yellow;
EditorGUILayout.LabelField("Select a Portal Action", style);
var selectedActionIdx = EditorGUILayout.Popup(-1, _actionsNames);
if (selectedActionIdx >= 0)
{
portal.gameObject.AddComponent(_actionsList[selectedActionIdx].Value);
}
}
}
19
Source : AIInvestigator.cs
with GNU Lesser General Public License v3.0
from ApexGameTools
with GNU Lesser General Public License v3.0
from ApexGameTools
private void PrepareAIResult()
{
_referencers.Sort((a, b) => a.name.CompareTo(b.name));
_aisList = _aiReferences.Values.OrderBy(ai => ai.name).ToArray();
foreach (var aiRef in _aisList)
{
aiRef.recordScenesOrPrefabs(_referencers);
aiRef.recordReferencingAIs(_aisList);
}
Array.Sort(
_aisList,
(a, b) =>
{
var res = a.referencedByAny.CompareTo(b.referencedByAny);
if (res == 0)
{
return a.name.CompareTo(b.name);
}
return res;
});
}
19
Source : AIInvestigator.cs
with GNU Lesser General Public License v3.0
from ApexGameTools
with GNU Lesser General Public License v3.0
from ApexGameTools
private void CreateSceneOrPrefab(string name, IEnumerable<string> refedIds, bool isPrefab)
{
var s = new SceneOrPrefab(name, isPrefab);
AIReference aiRef;
foreach (var aiId in refedIds)
{
if (_aiReferences.TryGetValue(aiId, out aiRef))
{
s.directReferences.Add(aiRef);
}
else
{
s.directReferences.Add(AIReference.missing);
}
}
if (s.directReferences.Count > 0)
{
s.directReferences.Sort((a, b) => a.name.CompareTo(b.name));
_referencers.Add(s);
}
}
19
Source : AlphanumComparatorFast.cs
with MIT License
from Apollo199999999
with MIT License
from Apollo199999999
public int Compare(object x, object y)
{
string s1 = x as string;
if (s1 == null)
{
return 0;
}
string s2 = y as string;
if (s2 == null)
{
return 0;
}
int len1 = s1.Length;
int len2 = s2.Length;
int marker1 = 0;
int marker2 = 0;
// Walk through two the strings with two markers.
while (marker1 < len1 && marker2 < len2)
{
char ch1 = s1[marker1];
char ch2 = s2[marker2];
// Some buffers we can build up characters in for each chunk.
char[] space1 = new char[len1];
int loc1 = 0;
char[] space2 = new char[len2];
int loc2 = 0;
// Walk through all following characters that are digits or
// characters in BOTH strings starting at the appropriate marker.
// Collect char arrays.
do
{
space1[loc1++] = ch1;
marker1++;
if (marker1 < len1)
{
ch1 = s1[marker1];
}
else
{
break;
}
} while (char.IsDigit(ch1) == char.IsDigit(space1[0]));
do
{
space2[loc2++] = ch2;
marker2++;
if (marker2 < len2)
{
ch2 = s2[marker2];
}
else
{
break;
}
} while (char.IsDigit(ch2) == char.IsDigit(space2[0]));
// If we have collected numbers, compare them numerically.
// Otherwise, if we have strings, compare them alphabetically.
string str1 = new string(space1);
string str2 = new string(space2);
int result;
if (char.IsDigit(space1[0]) && char.IsDigit(space2[0]))
{
int thisNumericChunk = int.Parse(str1);
int thatNumericChunk = int.Parse(str2);
result = thisNumericChunk.CompareTo(thatNumericChunk);
}
else
{
result = str1.CompareTo(str2);
}
if (result != 0)
{
return result;
}
}
return len1 - len2;
}
19
Source : ValueMatcher.cs
with Apache License 2.0
from Appdynamics
with Apache License 2.0
from Appdynamics
protected virtual int CompareStringToString(string s1, string s2)
{
return s1.CompareTo(s2);
}
19
Source : Program.cs
with MIT License
from ardalis
with MIT License
from ardalis
public int CompareTo(Student other)
{
if (other is null) return 1;
if (other.LastName == this.LastName)
{
return this.FirstName.CompareTo(other.FirstName);
}
return this.LastName.CompareTo(other.LastName);
}
19
Source : Program.cs
with MIT License
from ardalis
with MIT License
from ardalis
public int CompareTo(object obj)
{
if (obj is null) return 1;
if (obj is Author otherAuthor)
{
return this.ToString().CompareTo(otherAuthor.ToString());
}
throw new ArgumentException("Not an Author", nameof(obj));
}
19
Source : Program.cs
with MIT License
from ardalis
with MIT License
from ardalis
public int CompareTo(Author other)
{
if (other is null) return 1;
return this.ToString().CompareTo(other.ToString());
}
19
Source : TypeConstraintAttribute.cs
with MIT License
from arimger
with MIT License
from arimger
public List<Type> GetFilteredTypes()
{
var types = new List<Type>();
var replacedemblies = AppDomain.CurrentDomain.Getreplacedemblies();
foreach (var replacedembly in replacedemblies)
{
types.AddRange(GetFilteredTypes(replacedembly));
}
types.Sort((a, b) => a.FullName.CompareTo(b.FullName));
return types;
}
19
Source : ArkName.cs
with MIT License
from ark-mod
with MIT License
from ark-mod
public int CompareTo(ArkName other) => Token.CompareTo(other.Token);
19
Source : ArkName.cs
with MIT License
from ark-mod
with MIT License
from ark-mod
public int CompareTo([AllowNull] string other) => Token.CompareTo(other);
19
Source : FileCommand.cs
with GNU Affero General Public License v3.0
from arklumpus
with GNU Affero General Public License v3.0
from arklumpus
public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
{
if (string.IsNullOrWhiteSpace(partialCommand))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("file ", ConsoleColor.Green) }, "file ");
string[] directories = Directory.GetDirectories(Directory.GetCurrentDirectory(), "*");
List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();
foreach (string sr in directories)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
}, this.PrimaryCommand + " " + Path.GetFileName(sr) + Path.DirectorySeparatorChar));
}
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*");
foreach (string sr in files)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
}, this.PrimaryCommand + " " + Path.GetFileName(sr) + " "));
}
tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));
foreach ((ConsoleTextSpan[], string) item in tbr)
{
yield return item;
}
}
else
{
partialCommand = partialCommand.Trim();
Regex reg = new Regex("^[A-Za-z]:$");
if (reg.IsMatch(partialCommand))
{
partialCommand = partialCommand + "\\";
}
partialCommand = partialCommand.Trim();
string directory = null;
directory = Path.GetDirectoryName(partialCommand);
if (directory == null)
{
reg = new Regex("^[A-Za-z]:\\\\$");
if (reg.IsMatch(partialCommand))
{
directory = partialCommand;
}
}
string actualDirectory = directory;
if (string.IsNullOrEmpty(actualDirectory))
{
actualDirectory = Directory.GetCurrentDirectory();
}
string fileName = Path.GetFileName(partialCommand);
string[] directories = Directory.GetDirectories(actualDirectory, fileName + "*");
List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();
foreach (string sr in directories)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
}, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + Path.DirectorySeparatorChar));
}
string[] files = Directory.GetFiles(actualDirectory, fileName + "*");
foreach (string sr in files)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
}, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + " "));
}
tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));
foreach ((ConsoleTextSpan[], string) item in tbr)
{
yield return item;
}
}
}
19
Source : OpenCommand.cs
with GNU Affero General Public License v3.0
from arklumpus
with GNU Affero General Public License v3.0
from arklumpus
public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
{
if (string.IsNullOrWhiteSpace(partialCommand))
{
if (!string.IsNullOrEmpty(Program.InputFileName))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open", ConsoleColor.Green) }, "open ");
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "open info ");
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with", ConsoleColor.Yellow) }, "open with ");
}
string[] directories = Directory.GetDirectories(Directory.GetCurrentDirectory(), "*");
List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();
foreach (string sr in directories)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
}, this.PrimaryCommand + " " + Path.GetFileName(sr) + Path.DirectorySeparatorChar));
}
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*");
foreach (string sr in files)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
}, this.PrimaryCommand + " " + Path.GetFileName(sr) + " "));
}
tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));
foreach ((ConsoleTextSpan[], string) item in tbr)
{
yield return item;
}
}
else
{
partialCommand = partialCommand.TrimStart();
StringBuilder firstWordBuilder = new StringBuilder();
foreach (char c in partialCommand)
{
if (!char.IsWhiteSpace(c))
{
firstWordBuilder.Append(c);
}
else
{
break;
}
}
string firstWord = firstWordBuilder.ToString();
if (firstWord.Equals("with", StringComparison.OrdinalIgnoreCase))
{
partialCommand = partialCommand.Substring(4).TrimStart();
foreach (FileTypeModule mod in Modules.FileTypeModules)
{
if (mod.Name.StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with ", ConsoleColor.Yellow), new ConsoleTextSpan(mod.Name + " ", ConsoleColor.Blue) }, "open with " + mod.Name + " ");
}
}
foreach (FileTypeModule mod in Modules.FileTypeModules)
{
if (mod.Id.StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with ", ConsoleColor.Yellow), new ConsoleTextSpan(mod.Id + " ", ConsoleColor.Blue) }, "open with " + mod.Id + " ");
}
}
}
else if (firstWord.Equals("info", StringComparison.OrdinalIgnoreCase))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "open info ");
}
else
{
if ("with".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("with", ConsoleColor.Yellow) }, "open with ");
}
if ("info".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("open ", ConsoleColor.Green), new ConsoleTextSpan("info", ConsoleColor.Yellow) }, "open info ");
}
Regex reg = new Regex("^[A-Za-z]:$");
if (reg.IsMatch(partialCommand))
{
partialCommand = partialCommand + "\\";
}
partialCommand = partialCommand.Trim();
string directory = null;
directory = Path.GetDirectoryName(partialCommand);
if (directory == null)
{
reg = new Regex("^[A-Za-z]:\\\\$");
if (reg.IsMatch(partialCommand))
{
directory = partialCommand;
}
}
string actualDirectory = directory;
if (string.IsNullOrEmpty(actualDirectory))
{
actualDirectory = Directory.GetCurrentDirectory();
}
string fileName = Path.GetFileName(partialCommand);
string[] directories = Directory.GetDirectories(actualDirectory, fileName + "*");
List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();
foreach (string sr in directories)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
}, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + Path.DirectorySeparatorChar));
}
string[] files = Directory.GetFiles(actualDirectory, fileName + "*");
foreach (string sr in files)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
}, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + " "));
}
tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));
foreach ((ConsoleTextSpan[], string) item in tbr)
{
yield return item;
}
}
}
}
19
Source : PDFCommand.cs
with GNU Affero General Public License v3.0
from arklumpus
with GNU Affero General Public License v3.0
from arklumpus
public override IEnumerable<(ConsoleTextSpan[], string)> GetCompletions(string partialCommand)
{
if (string.IsNullOrWhiteSpace(partialCommand))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf", ConsoleColor.Green) }, "pdf ");
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "pdf stdout ");
string[] directories = Directory.GetDirectories(Directory.GetCurrentDirectory(), "*");
List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();
foreach (string sr in directories)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
}, this.PrimaryCommand + " " + Path.GetFileName(sr) + Path.DirectorySeparatorChar));
}
string[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "*");
foreach (string sr in files)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
}, this.PrimaryCommand + " " + Path.GetFileName(sr) + " "));
}
tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));
foreach ((ConsoleTextSpan[], string) item in tbr)
{
yield return item;
}
}
else
{
partialCommand = partialCommand.TrimStart();
StringBuilder firstWordBuilder = new StringBuilder();
foreach (char c in partialCommand)
{
if (!char.IsWhiteSpace(c))
{
firstWordBuilder.Append(c);
}
else
{
break;
}
}
string firstWord = firstWordBuilder.ToString();
if (firstWord.Equals("stdout", StringComparison.OrdinalIgnoreCase))
{
partialCommand = partialCommand.Substring(4).TrimStart();
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "pdf stdout ");
}
else
{
if ("stdout".StartsWith(partialCommand, StringComparison.OrdinalIgnoreCase))
{
yield return (new ConsoleTextSpan[] { new ConsoleTextSpan("pdf ", ConsoleColor.Green), new ConsoleTextSpan("stdout", ConsoleColor.Yellow) }, "pdf stdout ");
}
Regex reg = new Regex("^[A-Za-z]:$");
if (reg.IsMatch(partialCommand))
{
partialCommand = partialCommand + "\\";
}
partialCommand = partialCommand.Trim();
string directory = null;
directory = Path.GetDirectoryName(partialCommand);
if (directory == null)
{
reg = new Regex("^[A-Za-z]:\\\\$");
if (reg.IsMatch(partialCommand))
{
directory = partialCommand;
}
}
string actualDirectory = directory;
if (string.IsNullOrEmpty(actualDirectory))
{
actualDirectory = Directory.GetCurrentDirectory();
}
string fileName = Path.GetFileName(partialCommand);
string[] directories = Directory.GetDirectories(actualDirectory, fileName + "*");
List<(ConsoleTextSpan[], string)> tbr = new List<(ConsoleTextSpan[], string)>();
foreach (string sr in directories)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Blue)
}, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + Path.DirectorySeparatorChar));
}
string[] files = Directory.GetFiles(actualDirectory, fileName + "*");
foreach (string sr in files)
{
tbr.Add((new ConsoleTextSpan[]
{
new ConsoleTextSpan(Path.GetFileName(sr) + " ", ConsoleColor.Red)
}, this.PrimaryCommand + " " + Path.Combine(directory, Path.GetFileName(sr)) + " "));
}
tbr.Sort((a, b) => a.Item2.CompareTo(b.Item2));
foreach ((ConsoleTextSpan[], string) item in tbr)
{
yield return item;
}
}
}
}
See More Examples