本文整理汇总了C#中System.Collections.Stack.Reverse方法的典型用法代码示例。如果您正苦于以下问题:C# Stack.Reverse方法的具体用法?C# Stack.Reverse怎么用?C# Stack.Reverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Stack
的用法示例。
在下文中一共展示了Stack.Reverse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MatchViewRootProperties
private static string MatchViewRootProperties(object view, string output)
{
var sb = new StringBuilder(output);
// Normal access properties
var matcher = new Regex(@"<%([\.a-zA-Z]+)>");
var match = matcher.Match(sb.ToString());
while (match.Success)
{
var listProperties = match.Groups[1].Value;
var propCallStack = new Stack<string>(listProperties.Split('.'));
var value = view;
foreach (var prop in propCallStack.Reverse())
{
var pinfo = value.GetType().GetProperty(prop);
//Try to Map invalid Data
if (pinfo == null)
throw new InvalidDataBindViewException(listProperties, prop, value.GetType().Name, "Master");
value = pinfo.GetValue(value, new object[] { });
}
//MustEscapeData
sb.Replace(match.Value, SecurityElement.Escape(value.ToString()));
match = match.NextMatch();
}
return sb.ToString();
}
示例2: BuildPath
private IPath BuildPath(Stack<Tuple<JProperty, bool>> propertyStack, JProperty jProperty, JToken root)
{
var path = new JsonPath();
path.ActualPath = string.Join(JsonPath.SeperatorSymbol,
propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));
List<Tuple<IPathSegment, bool>> displayPathSegments =
propertyStack.Reverse()
.Select(p => new Tuple<IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2))
.ToList();
bool recordsetEncountered = false;
for (int i = displayPathSegments.Count - 1; i >= 0; i--)
{
Tuple<IPathSegment, bool> pathSegment = displayPathSegments[i];
if (recordsetEncountered)
{
pathSegment.Item1.IsEnumarable = false;
}
if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) recordsetEncountered = true;
}
path.DisplayPath = string.Join(JsonPath.SeperatorSymbol,
displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));
if (path.ActualPath != string.Empty)
{
path.ActualPath += JsonPath.SeperatorSymbol;
}
if (path.DisplayPath != string.Empty)
{
path.DisplayPath += JsonPath.SeperatorSymbol;
}
path.ActualPath += path.CreatePathSegment(jProperty).ToString();
path.DisplayPath += path.CreatePathSegment(jProperty).ToString();
path.SampleData += GetSampleData(root, path);
return path;
}
示例3: GetOrCreateInstances
/// <summary>
/// Trys to get an instance from the instance store, creating it if it doesnt exist
/// </summary>
/// <param name="requestType">The requested type</param>
/// <param name="instanceStore"></param>
/// <param name="tempInstanceStore"></param>
/// <param name="buildStack"></param>
/// <returns></returns>
IEnumerable GetOrCreateInstances(Type requestType, IInstanceStore instanceStore, IInstanceStore tempInstanceStore, Stack<Type> buildStack)
{
var typesToCreate = GetTypesToCreate(requestType, buildStack);
var instances = new List<Tuple<Registration, object>>();
if (tempInstanceStore != null && tempInstanceStore.ContainsInstancesFor(requestType))
instances.AddRange(tempInstanceStore.GetInstances(requestType).Cast<Tuple<Registration, object>>());
else if (instanceStore.ContainsInstancesFor(requestType))
instances.AddRange(instanceStore.GetInstances(requestType).Cast<Tuple<Registration, object>>());
foreach (var registration in typesToCreate)
{
if(!instances.Any(i => i != null && i.Item1 == registration))
{
var newinstance = this.GetInstance(registration, tempInstanceStore, new Stack<Type>(buildStack.Reverse()));
instanceStore.Insert(registration, requestType, newinstance);
instances.Add(new Tuple<Registration, object>(registration, newinstance));
}
}
return instances.Select(i => i.Item2).ToArray();
}
示例4: GetInstance
object GetInstance(Registration registration, IInstanceStore tempInstanceStore, Stack<Type> buildStack)
{
if (buildStack.Contains(registration.ConcreteType))
throw new ContainerException("Cyclic dependency detected when trying to construct `" + registration.ConcreteType.AssemblyQualifiedName + "`", buildStack);
buildStack.Push(registration.ConcreteType);
var constructor = registration.Ctor ??
(container =>
{
var constructors = registration.ConcreteType.GetConstructors();
var ctorsWithParams = constructors.Select(c => new {ctor = c, parameters = c.GetParameters()});
var orderedEnumerable = ctorsWithParams.OrderBy(x => x.parameters.Length);
foreach (var ctor in orderedEnumerable)
{
var parameterInfos = ctor.parameters.Select(p => p.ParameterType);
this.CheckDependencies(registration.ConcreteType, parameterInfos, registration.Lifecycle, tempInstanceStore, buildStack);
var parameters = new object[ctor.parameters.Length];
for (var i = 0; i < ctor.parameters.Length; i++)
{
var newBuildStack = new Stack<Type>(buildStack.Reverse());
if (ctor.parameters[i].ParameterType.IsGenericType && ctor.parameters[i].ParameterType.GetGenericTypeDefinition() == typeof (IEnumerable<>))
{
var genericArgument = ctor.parameters[i].ParameterType.GetGenericArguments()[0];
parameters[i] = this.ResolveAll(genericArgument, newBuildStack);
}
else
{
parameters[i] = this.Resolve(ctor.parameters[i].ParameterType, tempInstanceStore, newBuildStack);
}
}
try
{
return ctor.ctor.Invoke(parameters);
}
catch(Exception e)
{
throw new ContainerException("Cannot create type `" + ctor.ctor.DeclaringType.FullName + "`", buildStack, e);
}
}
throw new ContainerException("Unable to construct `" + registration.ConcreteType.AssemblyQualifiedName + "`", buildStack);
});
return constructor(this);
}
示例5: createListBoxItems
private bool createListBoxItems ( string path, Stack<string> subDirectories )
{
if(!isMatch(path))
{
return false;
}
subDirectories.Push( Path.GetFileName( path ));
var subPaths = Directory.GetDirectories( path );
foreach ( var subPath in subPaths )
{
if ( !createListBoxItems( subPath, subDirectories ) )
{
var internalData = new InternalDataItem( path, subDirectories.Reverse().ToArray() );
var lvItem = new ListViewItem();
lvItem.Text = internalData.ToString();
lvItem.Tag = internalData;
lv_Directories.Items.Add( lvItem );
subDirectories.Pop();
break;
}
}
return true;
}
示例6: MatchViewProperties
private static string MatchViewProperties(object view, string filePath)
{
if (!File.Exists(RootFolder + filePath + ".txt"))
throw new TemplateViewNotFoundViewException(
view.GetType().Name, RootFolder + filePath + ".txt");
var sb = new StringBuilder();
using (TextReader reader = File.OpenText(RootFolder + filePath + ".txt"))
{
sb.Append(reader.ReadToEnd());
}
// Normal access properties
var matcher = new Regex(@"<\$([\.a-zA-Z]+)>");
var match = matcher.Match(sb.ToString());
while (match.Success)
{
var listProperties = match.Groups[1].Value;
var propCallStack = new Stack<string>(listProperties.Split('.'));
var value = view;
foreach (var prop in propCallStack.Reverse())
{
var pinfo = value.GetType().GetProperty(prop);
//Try to Map invalid Data
if (pinfo == null)
throw new InvalidDataBindViewException(listProperties, prop, value.GetType().Name, filePath);
value = pinfo.GetValue(value, new object[] { });
}
//MustEscapeData
sb.Replace(match.Value, SecurityElement.Escape(value.ToString()));
match = match.NextMatch();
}
matcher = new Regex(@"<@([\.a-zA-Z]+)>");
var matchList = matcher.Match(sb.ToString());
while (matchList.Success)
{
var listProperties = matchList.Groups[1].Value;
var propCallStack = new Stack<string>(listProperties.Split('.'));
var value = view;
var propIndex = propCallStack.Count;
foreach (var prop in propCallStack.Reverse())
{
--propIndex;
var pinfo = value.GetType().GetProperty(prop);
//Try to Map invalid Data
if (pinfo == null)
throw new InvalidDataBindViewException(listProperties, prop, value.GetType().Name, filePath);
value = pinfo.GetValue(value, new object[] { });
//Is enumerable and it's the last callstack it can be usefull to use fom .Count on collections
if (value is IEnumerable && propIndex == 0)
{
// the enumerable
var listsb = new StringBuilder();
foreach (var item in (IEnumerable)value)
{
listsb.Append(MatchViewProperties(item, filePath + "." + pinfo.Name));
}
value = listsb.ToString();
}
}
//MustEscapeData
sb.Replace(matchList.Value, value.ToString());
matchList = matchList.NextMatch();
}
return sb.ToString();
}
示例7: InitializeThePeer
public SwarmMemory InitializeThePeer(string data, string myIPPort)
{
XDocument doc = XDocument.Parse(data);
var q = from x in doc.Elements().Descendants("Pid") select x;
string Pid = q.ElementAt(0).Value.ToString();
SwarmMemory sm = new SwarmMemory(Pid,myIPPort);
q = from x in doc.Elements().Descendants("stack").Descendants("value") select x;
Stack<string> newProgramStack = new Stack<string>();
foreach (var item in q)
{
newProgramStack.Push(item.Value.ToString());
}
newProgramStack.Reverse();
sm.setProgramStack(newProgramStack);
////////////////////////////////////////////////////////
q = from x in doc.Elements().Descendants("partialResults").Descendants("Result").Descendants("IPPort") select x;
List<string> ResultIPorts = new List<string>();
foreach (var item in q)
{
ResultIPorts.Add(item.Value.ToString());
}
q = from x in doc.Elements().Descendants("partialResults").Descendants("Result").Descendants("ResultValue") select x;
List<string> ResultVal = new List<string>();
foreach (var item in q)
{
ResultVal.Add(item.Value.ToString());
}
q = from x in doc.Elements().Descendants("partialResults").Descendants("Result").Descendants("done") select x;
List<string> _done = new List<string>();
foreach (var item in q)
{
_done.Add(item.Value.ToString());
}
Hashtable newPartialResults = new Hashtable();
for (int i = 0; i < ResultIPorts.Count; i++)
{
string[] temp = { ResultVal[i].ToString(), _done[i].ToString() };
newPartialResults.Add(ResultIPorts[i].ToString(), temp);
}
sm.setpartialResults(newPartialResults);
/////////////////////////////
q = from x in doc.Elements().Descendants("permissions").Descendants("permit").Descendants("IPPort") select x;
List<string> IPorts = new List<string>();
foreach (var item in q)
{
IPorts.Add(item.Value.ToString());
}
q = from x in doc.Elements().Descendants("permissions").Descendants("permit").Descendants("read") select x;
List<string> reads = new List<string>();
foreach (var item in q)
{
reads.Add(item.Value.ToString());
}
q = from x in doc.Elements().Descendants("permissions").Descendants("permit").Descendants("write") select x;
List<string> writes = new List<string>();
foreach (var item in q)
{
writes.Add(item.Value.ToString());
}
Hashtable newPermissions = new Hashtable();
for (int i = 0; i < IPorts.Count; i++)
{
string[] temp = { reads[i].ToString(), writes[i].ToString() };
newPermissions.Add(IPorts[i].ToString(), temp);
}
sm.setPermissions(newPermissions);
//////////////////////////////
q = from x in doc.Elements().Descendants("programVariables").Descendants("variable").Descendants("name") select x;
List<string> varnames = new List<string>();
foreach (var item in q)
{
varnames.Add(item.Value.ToString());
}
q = from x in doc.Elements().Descendants("programVariables").Descendants("variable").Descendants("value") select x;
List<string> varvalues = new List<string>();
foreach (var item in q)
{
varvalues.Add(item.Value.ToString());
}
Hashtable newProgramVariables = new Hashtable();
for (int i = 0; i < varnames.Count; i++)
{
newProgramVariables.Add(varnames[i].ToString(), varvalues[i].ToString());
}
sm.setProgramVariables(newProgramVariables);
///////////////////////////////////////////
q = from x in doc.Elements().Descendants("Replies").Descendants("Reply").Descendants("IPPort") select x;
List<string> ports = new List<string>();
foreach (var item in q)
{
ports.Add(item.Value.ToString());
}
q = from x in doc.Elements().Descendants("Replies").Descendants("Reply").Descendants("ReplyValue") select x;
List<string> repVal = new List<string>();
foreach (var item in q)
{
//.........这里部分代码省略.........
示例8: ContextAwareObjectVisitor
public ContextAwareObjectVisitor(Stack<string> previousContext = null)
{
this.context = previousContext == null
? new Stack<string>()
: new Stack<string>(previousContext.Reverse());
}
示例9: GetName
private static String GetName(Stack<Field> fields)
{
return String.Join(".", fields.Reverse().Select(f => f.Name));
}